From 8ffa80c2a2c295682856ba6605c1712a77d98c52 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Mon, 26 Nov 2012 01:59:22 +0000 Subject: Fix #2086 : Enable submenus for appindicator --- deluge/ui/gtkui/glade/tray_menu.glade | 3 ++ deluge/ui/gtkui/systemtray.py | 55 +++++++++++++++-------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/deluge/ui/gtkui/glade/tray_menu.glade b/deluge/ui/gtkui/glade/tray_menu.glade index 504e2e7d2..b8668a759 100644 --- a/deluge/ui/gtkui/glade/tray_menu.glade +++ b/deluge/ui/gtkui/glade/tray_menu.glade @@ -25,6 +25,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Add Torrent True + True @@ -86,6 +87,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Download Speed Limit True + True True @@ -102,6 +104,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK _Upload Speed Limit True + True True diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index 43318f174..1db5ec1bc 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -143,10 +143,9 @@ class SystemTray(component.Component): self.tray.connect("activate", self.on_tray_clicked) self.tray.connect("popup-menu", self.on_tray_popup) - # For some reason these icons do not display in appindicator - self.tray_glade.get_widget("download-limit-image").set_from_file( + self.tray_glade.get_widget("download-limit-image").set_from_file( deluge.common.get_pixmap("downloading16.png")) - self.tray_glade.get_widget("upload-limit-image").set_from_file( + self.tray_glade.get_widget("upload-limit-image").set_from_file( deluge.common.get_pixmap("seeding16.png")) client.register_event_handler("ConfigValueChangedEvent", self.config_value_changed) @@ -167,16 +166,6 @@ class SystemTray(component.Component): self.tray_glade.get_widget("menuitem_quitdaemon").hide() self.tray_glade.get_widget("separatormenuitem4").hide() - # These do not work with appindicator currently and can crash Deluge. - # Related to Launchpad bug #608219 - if appindicator and self.config["enable_appindicator"]: - self.hide_widget_list.remove("menuitem_download_limit") - self.hide_widget_list.remove("menuitem_upload_limit") - self.hide_widget_list.remove("separatormenuitem3") - self.tray_glade.get_widget("menuitem_download_limit").hide() - self.tray_glade.get_widget("menuitem_upload_limit").hide() - self.tray_glade.get_widget("separatormenuitem3").hide() - # Show widgets in the hide list because we've connected to a host for widget in self.hide_widget_list: self.tray_glade.get_widget(widget).show() @@ -271,16 +260,15 @@ class SystemTray(component.Component): def build_tray_bwsetsubmenu(self): # Create the Download speed list sub-menu submenu_bwdownset = common.build_menu_radio_list( - self.config["tray_download_speed_list"], self.tray_setbwdown, + self.config["tray_download_speed_list"], self.on_tray_setbwdown, self.max_download_speed, _("KiB/s"), show_notset=True, show_other=True) # Create the Upload speed list sub-menu submenu_bwupset = common.build_menu_radio_list( - self.config["tray_upload_speed_list"], self.tray_setbwup, + self.config["tray_upload_speed_list"], self.on_tray_setbwup, self.max_upload_speed, _("KiB/s"), show_notset=True, show_other=True) - # Add the sub-menus to the tray menu self.tray_glade.get_widget("menuitem_download_limit").set_submenu( submenu_bwdownset) @@ -291,10 +279,6 @@ class SystemTray(component.Component): submenu_bwdownset.show_all() submenu_bwupset.show_all() - # Re-set the menu to partly work around Launchpad bug #608219 - if appindicator and self.config["enable_appindicator"]: - self.indicator.set_menu(self.tray_menu) - def disable(self,invert_app_ind_conf=False): """Disables the system tray icon or appindicator.""" try: @@ -404,10 +388,22 @@ class SystemTray(component.Component): self.window.quit(shutdown=True) - def tray_setbwdown(self, widget, data=None): + def on_tray_setbwdown(self, widget, data=None): + if isinstance(widget, gtk.RadioMenuItem): + #ignore previous radiomenuitem value + if not widget.get_active(): + return self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed", "tray_download_speed_list", self.max_download_speed, "downloading.svg") + def on_tray_setbwup(self, widget, data=None): + if isinstance(widget, gtk.RadioMenuItem): + #ignore previous radiomenuitem value + if not widget.get_active(): + return + self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed", + "tray_upload_speed_list", self.max_upload_speed, "seeding.svg") + def _on_window_hide(self, widget, data=None): """_on_window_hide - update the menuitem's status""" log.debug("_on_window_hide") @@ -418,26 +414,21 @@ class SystemTray(component.Component): log.debug("_on_window_show") self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) - def tray_setbwup(self, widget, data=None): - 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, image): """Sets the bandwidth limit based on the user selection.""" - value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s")) - if value == _("Unlimited"): + value = widget.get_children()[0].get_text().split(" ")[0] + log.debug('setbwlimit: %s', value) + if widget.get_name() == "unlimited": value = -1 - - if value == _("Other..."): + if widget.get_name() == "other": value = common.show_other_dialog(string, _("KiB/s"), None, image, default) if value == None: return - + elif value == 0: + value = -1 # Set the config in the core client.core.set_config({core_key: value}) - self.build_tray_bwsetsubmenu() - def unlock_tray(self, is_showing_dlg=[False]): try: from hashlib import sha1 as sha_hash -- cgit