Initial import of DesiredRatio plugin.
Removed desired ratio options from tray menu, but code from old method still exists in interface.py.
This commit is contained in:
parent
b0e1210c1b
commit
d64a5c0d03
|
@ -161,55 +161,5 @@
|
|||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem3">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">_Desired Ratio</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child>
|
||||
<widget class="GtkMenu" id="menu2">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem4">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">_Not set</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="set_ratio0"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem9">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">_1</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="set_ratio1"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem10">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">_2</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="set_ratio2"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkMenuItem" id="menuitem11">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label" translatable="yes">_3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="set_ratio3"/>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</glade-interface>
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
# Copyright (C) 2007 - Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
### Initialization ###
|
||||
|
||||
plugin_name = _("Desired Ratio")
|
||||
plugin_author = "Andrew Resch"
|
||||
plugin_version = "0.1"
|
||||
plugin_description = _("Set the desired ratio for a torrent.")
|
||||
|
||||
def deluge_init(deluge_path):
|
||||
global path
|
||||
path = deluge_path
|
||||
|
||||
def enable(core, interface):
|
||||
global path
|
||||
return DesiredRatio(path, core, interface)
|
||||
|
||||
### The Plugin ###
|
||||
|
||||
DEFAULT_PREFS = {
|
||||
"ratios": [1.0, 1.5, 2.0, 3.0]
|
||||
}
|
||||
|
||||
import deluge
|
||||
import gtk, gtk.glade
|
||||
|
||||
class DesiredRatio:
|
||||
|
||||
def __init__(self, path, core, interface):
|
||||
self.path = path
|
||||
self.core = core
|
||||
self.interface = interface
|
||||
self.set_ratios = {}
|
||||
self.callback_ids = []
|
||||
|
||||
# Setup preferences
|
||||
self.config = deluge.pref.Preferences(filename=deluge.common.CONFIG_DIR + "/desired_ratio.conf", global_defaults=False, defaults=DEFAULT_PREFS)
|
||||
|
||||
# Connect to events for the torrent menu so we know when to build and remove our sub-menu
|
||||
self.callback_ids.append(self.interface.torrent_menu.connect_after("realize", self.torrent_menu_show))
|
||||
self.callback_ids.append(self.interface.torrent_menu.connect("show", self.torrent_menu_show))
|
||||
self.callback_ids.append(self.interface.torrent_menu.connect("hide", self.torrent_menu_hide))
|
||||
|
||||
def torrent_menu_show(self, widget, data=None):
|
||||
# Get the selected torrent
|
||||
self.unique_ID = self.interface.get_selected_torrent()
|
||||
|
||||
# Make the sub-menu for the torrent menu
|
||||
self.ratio_menuitem = gtk.MenuItem(_("_Desired Ratio"))
|
||||
|
||||
|
||||
|
||||
self.ratio_menu = self.interface.build_menu_radio_list(self.config.get("ratios"), self.ratio_clicked, self.get_torrent_desired_ratio(), None, True, _("Not Set"), 1)
|
||||
|
||||
self.ratio_menuitem.set_submenu(self.ratio_menu)
|
||||
self.interface.torrent_menu.append(self.ratio_menuitem)
|
||||
|
||||
self.ratio_menuitem.show_all()
|
||||
|
||||
def torrent_menu_hide(self, widget):
|
||||
try:
|
||||
self.interface.torrent_menu.remove(self.ratio_menuitem)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def unload(self):
|
||||
# Disconnect all callbacks
|
||||
for callback_id in self.callback_ids:
|
||||
self.interface.torrent_menu.disconnect(callback_id)
|
||||
|
||||
def ratio_clicked(self, widget):
|
||||
value = widget.get_children()[0].get_text()
|
||||
if value == _("Not Set"):
|
||||
value = -1
|
||||
|
||||
if value == _("Other..."):
|
||||
dialog_glade = gtk.glade.XML(deluge.common.get_glade_file("dgtkpopups.glade"))
|
||||
rate_dialog = dialog_glade.get_widget("rate_dialog")
|
||||
spin_rate = dialog_glade.get_widget("spin_rate")
|
||||
spin_rate.set_value(self.get_torrent_desired_ratio())
|
||||
spin_rate.set_increments(0.1, 1.0)
|
||||
spin_rate.set_digits(1)
|
||||
spin_rate.set_range(1.0, 1000.0)
|
||||
spin_rate.select_region(0, -1)
|
||||
response = rate_dialog.run()
|
||||
if response == 1: # OK Response
|
||||
value = spin_rate.get_value()
|
||||
else:
|
||||
rate_dialog.destroy()
|
||||
return
|
||||
rate_dialog.destroy()
|
||||
|
||||
# Set the ratio in the core and remember the setting
|
||||
self.core.set_ratio(self.unique_ID, value)
|
||||
self.set_ratios[self.unique_ID] = float(value)
|
||||
|
||||
# Update the ratios list if necessary
|
||||
if value not in self.config.get("ratios") and value >= 1:
|
||||
self.config.get("ratios").insert(0, value)
|
||||
self.config.get("ratios").pop()
|
||||
|
||||
def get_torrent_desired_ratio(self):
|
||||
if self.set_ratios.has_key(self.unique_ID):
|
||||
return self.set_ratios[self.unique_ID]
|
||||
else:
|
||||
return -1
|
|
@ -585,7 +585,7 @@ class Manager:
|
|||
self.apply_queue()
|
||||
|
||||
def set_ratio(self, unique_ID, num):
|
||||
deluge_core.set_ratio(unique_ID, num)
|
||||
deluge_core.set_ratio(unique_ID, float(num))
|
||||
|
||||
def is_user_paused(self, unique_ID):
|
||||
return self.unique_IDs[unique_ID].user_paused
|
||||
|
|
|
@ -1290,8 +1290,9 @@ static PyObject *torrent_pe_settings(PyObject *self, PyObject *args)
|
|||
|
||||
static PyObject *torrent_set_ratio(PyObject *self, PyObject *args)
|
||||
{
|
||||
python_long unique_ID, num;
|
||||
if (!PyArg_ParseTuple(args, "ii", &unique_ID, &num))
|
||||
python_long unique_ID;
|
||||
float num;
|
||||
if (!PyArg_ParseTuple(args, "if", &unique_ID, &num))
|
||||
return NULL;
|
||||
|
||||
long index = get_index_from_unique_ID(unique_ID);
|
||||
|
|
|
@ -200,7 +200,7 @@ class DelugeGTK:
|
|||
self.submenu_bwdownset.show_all()
|
||||
self.submenu_bwupset.show_all()
|
||||
|
||||
def build_menu_radio_list(self, value_list, callback, pref_value=None, suffix=None, show_notset=False, notset_label="Unlimited"):
|
||||
def build_menu_radio_list(self, value_list, callback, pref_value=None, suffix=None, show_notset=False, notset_label="Unlimited", notset_lessthan=0):
|
||||
# Build a menu with radio menu items from a list and connect them to the callback
|
||||
# The pref_value is what you would like to test for the default active radio item
|
||||
# Setting show_unlimited will include an Unlimited radio item
|
||||
|
@ -226,7 +226,7 @@ class DelugeGTK:
|
|||
|
||||
if show_notset:
|
||||
menuitem = gtk.RadioMenuItem(group, _(notset_label))
|
||||
if pref_value < 0 and pref_value != None:
|
||||
if pref_value < notset_lessthan and pref_value != None:
|
||||
menuitem.set_active(True)
|
||||
menuitem.connect("toggled", callback)
|
||||
menu.append(menuitem)
|
||||
|
|
Loading…
Reference in New Issue