Fix #2086 : Enable submenus for appindicator

This commit is contained in:
Calum Lind 2012-11-26 01:59:22 +00:00
parent 0f16faabcb
commit 8ffa80c2a2
2 changed files with 26 additions and 32 deletions

View File

@ -25,6 +25,7 @@
<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">_Add Torrent</property>
<property name="use_underline">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_menuitem_add_torrent_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="menu-item-image1">
@ -86,6 +87,7 @@
<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">_Download Speed Limit</property>
<property name="use_underline">True</property>
<property name="always_show_image">True</property>
<child internal-child="image">
<widget class="GtkImage" id="download-limit-image">
<property name="visible">True</property>
@ -102,6 +104,7 @@
<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">_Upload Speed Limit</property>
<property name="use_underline">True</property>
<property name="always_show_image">True</property>
<child internal-child="image">
<widget class="GtkImage" id="upload-limit-image">
<property name="visible">True</property>

View File

@ -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