mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-22 04:24:51 +00:00
Re-do the 'set maximum' dialogs.. They are now decorated.
This commit is contained in:
parent
013e9d95f1
commit
0954c3f112
5 changed files with 146 additions and 81 deletions
|
@ -115,26 +115,60 @@ def build_menu_radio_list(value_list, callback, pref_value=None,
|
|||
|
||||
return menu
|
||||
|
||||
def show_other_dialog(string, default=None):
|
||||
"""Shows a dialog to get an 'other' speed and return the value"""
|
||||
dialog_glade = gtk.glade.XML(
|
||||
def show_other_dialog(header, type_str, image_stockid=None, image_filename=None, default=0):
|
||||
"""
|
||||
Shows a dialog with :param:`header` as the header text and :param:`type_str`
|
||||
as the type text. The type of spinbutton (int or float) is determined by
|
||||
:param:`default`s type.
|
||||
|
||||
:param header: str, the header label text
|
||||
:param type_str: str, the type label text, what comes after the spinbutton
|
||||
:param image_stockid: gtkStockId, the stock id of the image in the header
|
||||
:param image_filename: str, filename of icon in pixmaps folder
|
||||
:param default: the default value in the spinbutton
|
||||
|
||||
:returns: None, int or float from spinbutton depending on :param:`default`.
|
||||
None is returned if the user clicks on Cancel.
|
||||
:rtype: None, int or float
|
||||
|
||||
:raises TypeError: if :param:`default` is not of type int or float
|
||||
|
||||
"""
|
||||
if type(default) != int and type(default) != float:
|
||||
raise TypeError("default value needs to be an int or float")
|
||||
|
||||
glade = gtk.glade.XML(
|
||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||
"glade/dgtkpopups.glade"))
|
||||
speed_dialog = dialog_glade.get_widget("speed_dialog")
|
||||
spin_title = dialog_glade.get_widget("spin_title")
|
||||
spin_title.set_text(_("%s" % string))
|
||||
spin_speed = dialog_glade.get_widget("spin_speed")
|
||||
if default != None:
|
||||
spin_speed.set_value(default)
|
||||
spin_speed.select_region(0, -1)
|
||||
response = speed_dialog.run()
|
||||
if response == 1: # OK Response
|
||||
value = spin_speed.get_value()
|
||||
else:
|
||||
speed_dialog.destroy()
|
||||
return None
|
||||
dialog = glade.get_widget("other_dialog")
|
||||
dialog.set_transient_for(component.get("MainWindow").window)
|
||||
dialog.set_title("")
|
||||
glade.get_widget("label_header").set_markup("<b>" + header + "</b>")
|
||||
glade.get_widget("label_type").set_text(type_str)
|
||||
if image_stockid:
|
||||
glade.get_widget("image").set_from_stock(image_stockid, gtk.ICON_SIZE_LARGE_TOOLBAR)
|
||||
if image_filename:
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
|
||||
deluge.common.get_pixmap(image_filename), 32, 32)
|
||||
glade.get_widget("image").set_from_pixbuf(pixbuf)
|
||||
|
||||
speed_dialog.destroy()
|
||||
spinbutton = glade.get_widget("spinbutton")
|
||||
if type(default) == float:
|
||||
spinbutton.set_digits(1)
|
||||
|
||||
# Set default value and select text
|
||||
spinbutton.set_value(default)
|
||||
spinbutton.select_region(0, -1)
|
||||
|
||||
value = None
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
if type(default) == int:
|
||||
value = spinbutton.get_value_as_int()
|
||||
else:
|
||||
value = spinbutton.get_value()
|
||||
|
||||
dialog.destroy()
|
||||
return value
|
||||
|
||||
def add_peer_dialog():
|
||||
|
|
|
@ -1,51 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.4.5 on Fri Oct 17 21:21:49 2008 -->
|
||||
<!--Generated with glade3 3.4.5 on Wed Nov 26 20:02:15 2008 -->
|
||||
<glade-interface>
|
||||
<widget class="GtkDialog" id="speed_dialog">
|
||||
<widget class="GtkDialog" id="other_dialog">
|
||||
<property name="app_paintable">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="border_width">5</property>
|
||||
<property name="title" translatable="yes">Speed</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="window_position">GTK_WIN_POS_MOUSE</property>
|
||||
<property name="destroy_with_parent">True</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
<property name="skip_taskbar_hint">True</property>
|
||||
<property name="skip_pager_hint">True</property>
|
||||
<property name="decorated">False</property>
|
||||
<property name="has_separator">False</property>
|
||||
<child internal-child="vbox">
|
||||
<widget class="GtkVBox" id="dialog-vbox2">
|
||||
<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="spacing">2</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox2">
|
||||
<widget class="GtkHBox" id="hbox3">
|
||||
<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="spacing">10</property>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="spin_title">
|
||||
<widget class="GtkImage" id="image">
|
||||
<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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spin_speed">
|
||||
<widget class="GtkLabel" id="label_header">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="has_focus">True</property>
|
||||
<property name="is_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="has_default">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="activates_default">True</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="adjustment">0 -1 10000 1 10 10</property>
|
||||
<property name="numeric">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -55,10 +45,69 @@
|
|||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator2">
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox4">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment2">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment1">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">1</property>
|
||||
<child>
|
||||
<widget class="GtkSpinButton" id="spinbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="max_length">6</property>
|
||||
<property name="activates_default">True</property>
|
||||
<property name="width_chars">6</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="adjustment">-1 -1 99999 1 10 0</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label_type">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child internal-child="action_area">
|
||||
<widget class="GtkHButtonBox" id="dialog-action_area2">
|
||||
<property name="visible">True</property>
|
||||
|
@ -72,18 +121,20 @@
|
|||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="response_id">-6</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="button4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="has_default">True</property>
|
||||
<property name="receives_default">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">gtk-ok</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">1</property>
|
||||
<property name="response_id">-5</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
|
|
|
@ -402,34 +402,17 @@ class MenuBar(component.Component):
|
|||
"menuitem_max_connections": client.set_torrent_max_connections,
|
||||
"menuitem_upload_slots": client.set_torrent_max_upload_slots
|
||||
}
|
||||
dialog_glade = gtk.glade.XML(
|
||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||
"glade/dgtkpopups.glade"))
|
||||
speed_dialog = dialog_glade.get_widget("speed_dialog")
|
||||
spin_title = dialog_glade.get_widget("spin_title")
|
||||
if widget.name == "menuitem_down_speed":
|
||||
spin_title.set_text(_("Set Max Download Speed (KiB/s):"))
|
||||
elif widget.name == "menuitem_up_speed":
|
||||
spin_title.set_text(_("Set Max Upload Speed (KiB/s):"))
|
||||
elif widget.name == "menuitem_max_connections":
|
||||
spin_title.set_text(_("Set Max Connections:"))
|
||||
elif widget.name == "menuitem_upload_slots":
|
||||
spin_title.set_text(_("Set Max Upload Slots:"))
|
||||
# widget: (header, type_str, image_stockid, image_filename, default)
|
||||
other_dialog_info = {
|
||||
"menuitem_down_speed": (_("Set Maximum Download Speed"), "KiB/s", None, "downloading.svg", -1.0),
|
||||
"menuitem_up_speed": (_("Set Maximum Upload Speed"), "KiB/s", None, "seeding.svg", -1.0),
|
||||
"menuitem_max_connections": (_("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, -1),
|
||||
"menuitem_upload_slots": (_("Set Maximum Upload Slots"), "", gtk.STOCK_SORT_ASCENDING, None, -1)
|
||||
}
|
||||
|
||||
spin_speed = dialog_glade.get_widget("spin_speed")
|
||||
spin_speed.set_value(-1)
|
||||
spin_speed.select_region(0, -1)
|
||||
response = speed_dialog.run()
|
||||
if response == 1: # OK Response
|
||||
if widget.name == "menuitem_down_speed" or widget.name == "menuitem_up_speed":
|
||||
value = spin_speed.get_value()
|
||||
else:
|
||||
value = spin_speed.get_value_as_int()
|
||||
else:
|
||||
speed_dialog.destroy()
|
||||
return
|
||||
speed_dialog.destroy()
|
||||
if widget.name in funcs.keys():
|
||||
# Show the other dialog
|
||||
value = common.show_other_dialog(*other_dialog_info[widget.name])
|
||||
if value and widget.name in funcs:
|
||||
for torrent in component.get("TorrentView").get_selected_torrents():
|
||||
funcs[widget.name](torrent, value)
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ class StatusBar(component.Component):
|
|||
value = -1
|
||||
elif widget.get_name() == _("Other..."):
|
||||
value = common.show_other_dialog(
|
||||
_("Download Speed (KiB/s):"), self.max_download_speed)
|
||||
_("Set Maximum Download Speed"), "KiB/s", None, "downloading.svg", self.max_download_speed)
|
||||
if value == None:
|
||||
return
|
||||
else:
|
||||
|
@ -395,7 +395,7 @@ class StatusBar(component.Component):
|
|||
value = -1
|
||||
elif widget.get_name() == _("Other..."):
|
||||
value = common.show_other_dialog(
|
||||
_("Upload Speed (KiB/s):"), self.max_upload_speed)
|
||||
_("Set Maximum Upload Speed"), "KiB/s", None, "seeding.svg", self.max_upload_speed)
|
||||
if value == None:
|
||||
return
|
||||
else:
|
||||
|
@ -422,7 +422,7 @@ class StatusBar(component.Component):
|
|||
value = -1
|
||||
elif widget.get_name() == _("Other..."):
|
||||
value = common.show_other_dialog(
|
||||
_("Connection Limit:"), self.max_connections)
|
||||
_("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, self.max_connections)
|
||||
if value == None:
|
||||
return
|
||||
else:
|
||||
|
|
|
@ -321,29 +321,26 @@ class SystemTray(component.Component):
|
|||
self.window.quit()
|
||||
|
||||
def tray_setbwdown(self, widget, data=None):
|
||||
self.setbwlimit(widget, _("Download"), "max_download_speed",
|
||||
"tray_download_speed_list", self.max_download_speed)
|
||||
self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed",
|
||||
"tray_download_speed_list", self.max_download_speed, "downloading.svg")
|
||||
|
||||
def tray_setbwup(self, widget, data=None):
|
||||
self.setbwlimit(widget, _("Upload"), "max_upload_speed",
|
||||
"tray_upload_speed_list", self.max_upload_speed)
|
||||
self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed",
|
||||
"tray_upload_speed_list", self.max_upload_speed, "seeding.svg")
|
||||
|
||||
def setbwlimit(self, widget, string, core_key, ui_key, default):
|
||||
def setbwlimit(self, widget, string, core_key, ui_key, default, image):
|
||||
"""Sets the bandwidth limit based on the user selection."""
|
||||
value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s"))
|
||||
if value == _("Unlimited"):
|
||||
value = -1
|
||||
|
||||
if value == _("Other..."):
|
||||
value = common.show_other_dialog(
|
||||
string + " Speed (KiB/s):", default)
|
||||
value = common.show_other_dialog(string, "KiB/s", None, image, default)
|
||||
if value == None:
|
||||
return
|
||||
|
||||
# Set the config in the core
|
||||
value = float(value)
|
||||
config_to_set = {core_key: value}
|
||||
client.set_config(config_to_set)
|
||||
client.set_config({core_key: value})
|
||||
|
||||
self.build_tray_bwsetsubmenu()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue