From a384cd70b377cf46c7b4299ce165f67c7a85ff55 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 6 Jul 2011 22:20:15 +0100 Subject: [PATCH] Moved system tray to GtkBuilder. --- deluge/ui/gtkui/glade/tray_menu.glade | 154 ---------------------- deluge/ui/gtkui/glade/tray_menu.ui | 183 ++++++++++++++++++++++++++ deluge/ui/gtkui/systemtray.py | 47 +++---- 3 files changed, 207 insertions(+), 177 deletions(-) delete mode 100644 deluge/ui/gtkui/glade/tray_menu.glade create mode 100644 deluge/ui/gtkui/glade/tray_menu.ui diff --git a/deluge/ui/gtkui/glade/tray_menu.glade b/deluge/ui/gtkui/glade/tray_menu.glade deleted file mode 100644 index 504e2e7d2..000000000 --- a/deluge/ui/gtkui/glade/tray_menu.glade +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Show Deluge - True - - - - - - True - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Add Torrent - True - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-add - 1 - - - - - - - True - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Pause All - True - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-media-pause - 1 - - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Resume All - True - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-media-play - 1 - - - - - - - True - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Download Speed Limit - True - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-go-down - 1 - - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - _Upload Speed Limit - True - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-go-up - 1 - - - - - - - True - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Quit & Shutdown Daemon - True - False - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-quit - 1 - - - - - - - True - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-quit - True - True - - - - - diff --git a/deluge/ui/gtkui/glade/tray_menu.ui b/deluge/ui/gtkui/glade/tray_menu.ui new file mode 100644 index 000000000..f7a410066 --- /dev/null +++ b/deluge/ui/gtkui/glade/tray_menu.ui @@ -0,0 +1,183 @@ + + + + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-go-down + 1 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-add + 1 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-media-pause + 1 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-media-play + 1 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-quit + 1 + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + _Show Deluge + True + + + + + + True + False + + + + + _Add Torrent + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + menu-item-image1 + False + + + + + + True + False + + + + + _Pause All + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + menu-item-image6 + False + + + + + + _Resume All + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + menu-item-image7 + False + + + + + + True + False + + + + + _Download Speed Limit + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + download-limit-image + False + + + + + _Upload Speed Limit + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + upload-limit-image + False + + + + + True + False + + + + + Quit & Shutdown Daemon + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + menu-item-image8 + False + + + + + + True + False + + + + + gtk-quit + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + True + True + accelgroup1 + + + + + + True + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-go-up + 1 + + diff --git a/deluge/ui/gtkui/systemtray.py b/deluge/ui/gtkui/systemtray.py index b12feb2c5..6d79171f7 100644 --- a/deluge/ui/gtkui/systemtray.py +++ b/deluge/ui/gtkui/systemtray.py @@ -87,11 +87,12 @@ class SystemTray(component.Component): def enable(self): """Enables the system tray icon.""" - self.tray_glade = gtk.glade.XML(deluge.common.resource_filename( - "deluge.ui.gtkui", os.path.join("glade", "tray_menu.glade")) + self.builder = gtk.Builder() + self.builder.add_from_file(deluge.common.resource_filename( + "deluge.ui.gtkui", os.path.join("glade", "tray_menu.ui")) ) - self.tray_glade.signal_autoconnect({ + self.builder.connect_signals({ "on_menuitem_show_deluge_activate": \ self.on_menuitem_show_deluge_activate, "on_menuitem_add_torrent_activate": \ @@ -105,7 +106,7 @@ class SystemTray(component.Component): self.on_menuitem_quitdaemon_activate }) - self.tray_menu = self.tray_glade.get_widget("tray_menu") + self.tray_menu = self.builder.get_object("tray_menu") if appindicator and self.config["enable_appindicator"]: log.debug("Enabling the Application Indicator..") @@ -118,9 +119,9 @@ class SystemTray(component.Component): self._sig_win_hide = self.window.window.connect("hide", self._on_window_hide) self._sig_win_show = self.window.window.connect("show", self._on_window_show) if self.window.visible(): - self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) + self.builder.get_object("menuitem_show_deluge").set_active(True) else: - self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) + self.builder.get_object("menuitem_show_deluge").set_active(False) # Show the Application Indicator self.indicator.set_status(appindicator.STATUS_ACTIVE) @@ -141,9 +142,9 @@ class SystemTray(component.Component): 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.builder.get_object("download-limit-image").set_from_file( deluge.common.get_pixmap("downloading16.png")) - self.tray_glade.get_widget("upload-limit-image").set_from_file( + self.builder.get_object("upload-limit-image").set_from_file( deluge.common.get_pixmap("seeding16.png")) client.register_event_handler("ConfigValueChangedEvent", self.config_value_changed) @@ -153,7 +154,7 @@ class SystemTray(component.Component): else: # Hide menu widgets because we're not connected to a host. for widget in self.hide_widget_list: - self.tray_glade.get_widget(widget).hide() + self.builder.get_object(widget).hide() def __start(self): if self.config["enable_system_tray"]: @@ -161,8 +162,8 @@ class SystemTray(component.Component): if self.config["classic_mode"]: self.hide_widget_list.remove("menuitem_quitdaemon") self.hide_widget_list.remove("separatormenuitem4") - self.tray_glade.get_widget("menuitem_quitdaemon").hide() - self.tray_glade.get_widget("separatormenuitem4").hide() + self.builder.get_object("menuitem_quitdaemon").hide() + self.builder.get_object("separatormenuitem4").hide() # These do not work with appindicator currently and can crash Deluge. # Related to Launchpad bug #608219 @@ -170,13 +171,13 @@ class SystemTray(component.Component): 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() + self.builder.get_object("menuitem_download_limit").hide() + self.builder.get_object("menuitem_upload_limit").hide() + self.builder.get_object("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() + self.builder.get_object(widget).show() # Build the bandwidth speed limit menus self.build_tray_bwsetsubmenu() @@ -196,7 +197,7 @@ class SystemTray(component.Component): try: # Hide widgets in hide list because we're not connected to a host for widget in self.hide_widget_list: - self.tray_glade.get_widget(widget).hide() + self.builder.get_object(widget).hide() except Exception, e: log.debug("Unable to hide system tray menu widgets: %s", e) @@ -279,9 +280,9 @@ class SystemTray(component.Component): _("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( + self.builder.get_object("menuitem_download_limit").set_submenu( submenu_bwdownset) - self.tray_glade.get_widget("menuitem_upload_limit").set_submenu( + self.builder.get_object("menuitem_upload_limit").set_submenu( submenu_bwupset) # Show the sub-menus for all to see @@ -311,7 +312,7 @@ class SystemTray(component.Component): log.debug("Disabling the system tray icon..") self.tray.set_visible(False) del self.tray - del self.tray_glade + del self.builder del self.tray_menu except Exception, e: log.debug("Unable to disable system tray: %s", e) @@ -355,9 +356,9 @@ class SystemTray(component.Component): self.blink(False) if self.window.visible(): - self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) + self.builder.get_object("menuitem_show_deluge").set_active(True) else: - self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) + self.builder.get_object("menuitem_show_deluge").set_active(False) popup_function = gtk.status_icon_position_menu if deluge.common.windows_check(): @@ -408,12 +409,12 @@ class SystemTray(component.Component): def _on_window_hide(self, widget, data=None): """_on_window_hide - update the menuitem's status""" log.debug("_on_window_hide") - self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) + self.builder.get_object("menuitem_show_deluge").set_active(False) def _on_window_show(self, widget, data=None): """_on_window_show - update the menuitem's status""" log.debug("_on_window_show") - self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) + self.builder.get_object("menuitem_show_deluge").set_active(True) def tray_setbwup(self, widget, data=None): self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed",