mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-03 06:58:42 +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
|
return menu
|
||||||
|
|
||||||
def show_other_dialog(string, default=None):
|
def show_other_dialog(header, type_str, image_stockid=None, image_filename=None, default=0):
|
||||||
"""Shows a dialog to get an 'other' speed and return the value"""
|
"""
|
||||||
dialog_glade = gtk.glade.XML(
|
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",
|
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||||
"glade/dgtkpopups.glade"))
|
"glade/dgtkpopups.glade"))
|
||||||
speed_dialog = dialog_glade.get_widget("speed_dialog")
|
dialog = glade.get_widget("other_dialog")
|
||||||
spin_title = dialog_glade.get_widget("spin_title")
|
dialog.set_transient_for(component.get("MainWindow").window)
|
||||||
spin_title.set_text(_("%s" % string))
|
dialog.set_title("")
|
||||||
spin_speed = dialog_glade.get_widget("spin_speed")
|
glade.get_widget("label_header").set_markup("<b>" + header + "</b>")
|
||||||
if default != None:
|
glade.get_widget("label_type").set_text(type_str)
|
||||||
spin_speed.set_value(default)
|
if image_stockid:
|
||||||
spin_speed.select_region(0, -1)
|
glade.get_widget("image").set_from_stock(image_stockid, gtk.ICON_SIZE_LARGE_TOOLBAR)
|
||||||
response = speed_dialog.run()
|
if image_filename:
|
||||||
if response == 1: # OK Response
|
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
|
||||||
value = spin_speed.get_value()
|
deluge.common.get_pixmap(image_filename), 32, 32)
|
||||||
else:
|
glade.get_widget("image").set_from_pixbuf(pixbuf)
|
||||||
speed_dialog.destroy()
|
|
||||||
return None
|
|
||||||
|
|
||||||
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
|
return value
|
||||||
|
|
||||||
def add_peer_dialog():
|
def add_peer_dialog():
|
||||||
|
|
|
@ -1,51 +1,41 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
<!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>
|
<glade-interface>
|
||||||
<widget class="GtkDialog" id="speed_dialog">
|
<widget class="GtkDialog" id="other_dialog">
|
||||||
<property name="app_paintable">True</property>
|
<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="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="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="window_position">GTK_WIN_POS_MOUSE</property>
|
||||||
<property name="destroy_with_parent">True</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_taskbar_hint">True</property>
|
||||||
<property name="skip_pager_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">
|
<child internal-child="vbox">
|
||||||
<widget class="GtkVBox" id="dialog-vbox2">
|
<widget class="GtkVBox" id="dialog-vbox2">
|
||||||
<property name="visible">True</property>
|
<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="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>
|
<child>
|
||||||
<widget class="GtkHBox" id="hbox2">
|
<widget class="GtkHBox" id="hbox3">
|
||||||
<property name="visible">True</property>
|
<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>
|
<property name="spacing">10</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkLabel" id="spin_title">
|
<widget class="GtkImage" id="image">
|
||||||
<property name="visible">True</property>
|
<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>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">False</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkSpinButton" id="spin_speed">
|
<widget class="GtkLabel" id="label_header">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="xalign">0</property>
|
||||||
<property name="has_focus">True</property>
|
<property name="label" translatable="yes">label</property>
|
||||||
<property name="is_focus">True</property>
|
<property name="use_markup">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>
|
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
@ -55,10 +45,69 @@
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
<property name="fill">False</property>
|
<property name="fill">False</property>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</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">
|
<child internal-child="action_area">
|
||||||
<widget class="GtkHButtonBox" id="dialog-action_area2">
|
<widget class="GtkHButtonBox" id="dialog-action_area2">
|
||||||
<property name="visible">True</property>
|
<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="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="label">gtk-cancel</property>
|
||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
<property name="response_id">0</property>
|
<property name="response_id">-6</property>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkButton" id="button4">
|
<widget class="GtkButton" id="button4">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">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="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="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="label">gtk-ok</property>
|
||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
<property name="response_id">1</property>
|
<property name="response_id">-5</property>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
|
|
|
@ -402,34 +402,17 @@ class MenuBar(component.Component):
|
||||||
"menuitem_max_connections": client.set_torrent_max_connections,
|
"menuitem_max_connections": client.set_torrent_max_connections,
|
||||||
"menuitem_upload_slots": client.set_torrent_max_upload_slots
|
"menuitem_upload_slots": client.set_torrent_max_upload_slots
|
||||||
}
|
}
|
||||||
dialog_glade = gtk.glade.XML(
|
# widget: (header, type_str, image_stockid, image_filename, default)
|
||||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
other_dialog_info = {
|
||||||
"glade/dgtkpopups.glade"))
|
"menuitem_down_speed": (_("Set Maximum Download Speed"), "KiB/s", None, "downloading.svg", -1.0),
|
||||||
speed_dialog = dialog_glade.get_widget("speed_dialog")
|
"menuitem_up_speed": (_("Set Maximum Upload Speed"), "KiB/s", None, "seeding.svg", -1.0),
|
||||||
spin_title = dialog_glade.get_widget("spin_title")
|
"menuitem_max_connections": (_("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, -1),
|
||||||
if widget.name == "menuitem_down_speed":
|
"menuitem_upload_slots": (_("Set Maximum Upload Slots"), "", gtk.STOCK_SORT_ASCENDING, None, -1)
|
||||||
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:"))
|
|
||||||
|
|
||||||
spin_speed = dialog_glade.get_widget("spin_speed")
|
# Show the other dialog
|
||||||
spin_speed.set_value(-1)
|
value = common.show_other_dialog(*other_dialog_info[widget.name])
|
||||||
spin_speed.select_region(0, -1)
|
if value and widget.name in funcs:
|
||||||
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():
|
|
||||||
for torrent in component.get("TorrentView").get_selected_torrents():
|
for torrent in component.get("TorrentView").get_selected_torrents():
|
||||||
funcs[widget.name](torrent, value)
|
funcs[widget.name](torrent, value)
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ class StatusBar(component.Component):
|
||||||
value = -1
|
value = -1
|
||||||
elif widget.get_name() == _("Other..."):
|
elif widget.get_name() == _("Other..."):
|
||||||
value = common.show_other_dialog(
|
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:
|
if value == None:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -395,7 +395,7 @@ class StatusBar(component.Component):
|
||||||
value = -1
|
value = -1
|
||||||
elif widget.get_name() == _("Other..."):
|
elif widget.get_name() == _("Other..."):
|
||||||
value = common.show_other_dialog(
|
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:
|
if value == None:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -422,7 +422,7 @@ class StatusBar(component.Component):
|
||||||
value = -1
|
value = -1
|
||||||
elif widget.get_name() == _("Other..."):
|
elif widget.get_name() == _("Other..."):
|
||||||
value = common.show_other_dialog(
|
value = common.show_other_dialog(
|
||||||
_("Connection Limit:"), self.max_connections)
|
_("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, self.max_connections)
|
||||||
if value == None:
|
if value == None:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -321,29 +321,26 @@ class SystemTray(component.Component):
|
||||||
self.window.quit()
|
self.window.quit()
|
||||||
|
|
||||||
def tray_setbwdown(self, widget, data=None):
|
def tray_setbwdown(self, widget, data=None):
|
||||||
self.setbwlimit(widget, _("Download"), "max_download_speed",
|
self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed",
|
||||||
"tray_download_speed_list", self.max_download_speed)
|
"tray_download_speed_list", self.max_download_speed, "downloading.svg")
|
||||||
|
|
||||||
def tray_setbwup(self, widget, data=None):
|
def tray_setbwup(self, widget, data=None):
|
||||||
self.setbwlimit(widget, _("Upload"), "max_upload_speed",
|
self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed",
|
||||||
"tray_upload_speed_list", self.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."""
|
"""Sets the bandwidth limit based on the user selection."""
|
||||||
value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s"))
|
value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s"))
|
||||||
if value == _("Unlimited"):
|
if value == _("Unlimited"):
|
||||||
value = -1
|
value = -1
|
||||||
|
|
||||||
if value == _("Other..."):
|
if value == _("Other..."):
|
||||||
value = common.show_other_dialog(
|
value = common.show_other_dialog(string, "KiB/s", None, image, default)
|
||||||
string + " Speed (KiB/s):", default)
|
|
||||||
if value == None:
|
if value == None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Set the config in the core
|
# Set the config in the core
|
||||||
value = float(value)
|
client.set_config({core_key: value})
|
||||||
config_to_set = {core_key: value}
|
|
||||||
client.set_config(config_to_set)
|
|
||||||
|
|
||||||
self.build_tray_bwsetsubmenu()
|
self.build_tray_bwsetsubmenu()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue