Ticket #1514: systemtray.py.patch
File systemtray.py.patch, 9.1 KB (added by , 14 years ago) |
---|
-
/home/grundoko/Desktop/deluge-1.3.1/deluge/ui/gtkui/systemtray.py
old new 33 33 # 34 34 # 35 35 36 try: 37 import appindicator 38 except: 39 appindicator = None 36 40 37 41 import gtk 38 42 import pkg_resources … … 54 58 "menuitem_add_torrent", 55 59 "menuitem_pause_all", 56 60 "menuitem_resume_all", 57 "menuitem_download_limit",58 "menuitem_upload_limit",61 # "menuitem_download_limit", 62 # "menuitem_upload_limit", 59 63 "menuitem_quitdaemon", 60 64 "separatormenuitem1", 61 65 "separatormenuitem2", 62 "separatormenuitem3",66 # "separatormenuitem3", 63 67 "separatormenuitem4" 64 68 ] 65 69 self.config.register_set_function("enable_system_tray", … … 77 81 78 82 def enable(self): 79 83 """Enables the system tray icon.""" 80 log.debug("Enabling the system tray icon..") 84 if appindicator: 85 log.debug("Enabling the Application Indicator..") 86 else: 87 log.debug("Enabling the system tray icon..") 81 88 self.tray_glade = gtk.glade.XML( 82 89 pkg_resources.resource_filename("deluge.ui.gtkui", 83 90 "glade/tray_menu.glade")) 84 91 85 if deluge.common.windows_check() or deluge.common.osx_check(): 86 self.tray = gtk.status_icon_new_from_pixbuf( 87 common.get_logo(32)) 92 if appindicator: 93 self.indicator = appindicator.Indicator ("deluge", 94 "deluge", 95 appindicator.CATEGORY_APPLICATION_STATUS) 88 96 else: 89 try: 90 self.tray = gtk.status_icon_new_from_icon_name("deluge") 91 except: 92 log.warning("Update PyGTK to 2.10 or greater for SystemTray..") 93 return 97 if deluge.common.windows_check() or deluge.common.osx_check(): 98 self.tray = gtk.status_icon_new_from_pixbuf( 99 common.get_logo(32)) 100 else: 101 try: 102 self.tray = gtk.status_icon_new_from_icon_name("deluge") 103 except: 104 log.warning("Update PyGTK to 2.10 or greater for SystemTray..") 105 return 94 106 95 self.tray.connect("activate", self.on_tray_clicked)96 self.tray.connect("popup-menu", self.on_tray_popup)107 self.tray.connect("activate", self.on_tray_clicked) 108 self.tray.connect("popup-menu", self.on_tray_popup) 97 109 98 110 99 111 self.tray_glade.signal_autoconnect({ … … 112 124 113 125 self.tray_menu = self.tray_glade.get_widget("tray_menu") 114 126 115 self.tray_glade.get_widget("download-limit-image").set_from_file(116 deluge.common.get_pixmap("downloading16.png"))117 self.tray_glade.get_widget("upload-limit-image").set_from_file(118 deluge.common.get_pixmap("seeding16.png"))127 # self.tray_glade.get_widget("download-limit-image").set_from_file( 128 # deluge.common.get_pixmap("downloading16.png")) 129 # self.tray_glade.get_widget("upload-limit-image").set_from_file( 130 # deluge.common.get_pixmap("seeding16.png")) 119 131 120 132 client.register_event_handler("ConfigValueChangedEvent", self.config_value_changed) 121 133 if not client.connected(): … … 123 135 for widget in self.hide_widget_list: 124 136 self.tray_glade.get_widget(widget).hide() 125 137 138 if appindicator: 139 # Pass the menu to the Application Indicator 140 self.indicator.set_menu(self.tray_menu) 141 142 # Make sure the status of the Show Window MenuItem is correct 143 self._sig_win_hide = self.window.window.connect("hide", self._on_window_hide) 144 self._sig_win_show = self.window.window.connect("show", self._on_window_show) 145 if self.window.visible(): 146 self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) 147 else: 148 self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) 149 150 # Show the Application Indicator 151 self.indicator.set_status(appindicator.STATUS_ACTIVE) 152 153 #dl = gtk.MenuItem(_("Download Speed Limit")) 154 #up = gtk.MenuItem(_("Upload Speed Limit")) 155 #self.tray_menu.insert(dl,len(self.tray_menu.get_children())-1) 156 #self.tray_menu.insert(up,len(self.tray_menu.get_children())-1) 157 126 158 if client.connected(): 127 159 # We're connected so we need to get some values from the core 128 160 self.__start() … … 166 198 167 199 def shutdown(self): 168 200 if self.config["enable_system_tray"]: 169 self.tray.set_visible(False) 201 if appindicator: 202 self.indicator.set_status(appindicator.STATUS_PASSIVE) 203 else: 204 self.tray.set_visible(False) 170 205 171 206 def send_status_request(self): 172 207 client.core.get_session_status([ … … 198 233 if not self.config["enable_system_tray"]: 199 234 return 200 235 201 # Set the tool tip text 202 max_download_speed = self.max_download_speed 203 max_upload_speed = self.max_upload_speed 236 if not appindicator: 237 # Set the tool tip text 238 max_download_speed = self.max_download_speed 239 max_upload_speed = self.max_upload_speed 204 240 205 if max_download_speed == -1:206 max_download_speed = _("Unlimited")207 else:208 max_download_speed = "%s %s" % (max_download_speed, _("KiB/s"))209 if max_upload_speed == -1:210 max_upload_speed = _("Unlimited")211 else:212 max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s"))241 if max_download_speed == -1: 242 max_download_speed = _("Unlimited") 243 else: 244 max_download_speed = "%s %s" % (max_download_speed, _("KiB/s")) 245 if max_upload_speed == -1: 246 max_upload_speed = _("Unlimited") 247 else: 248 max_upload_speed = "%s %s" % (max_upload_speed, _("KiB/s")) 213 249 214 msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (\215 _("Deluge"), _("Down"), self.download_rate, \216 max_download_speed, _("Up"), self.upload_rate, max_upload_speed)250 msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (\ 251 _("Deluge"), _("Down"), self.download_rate, \ 252 max_download_speed, _("Up"), self.upload_rate, max_upload_speed) 217 253 218 # Set the tooltip219 self.tray.set_tooltip(msg)254 # Set the tooltip 255 self.tray.set_tooltip(msg) 220 256 221 257 self.send_status_request() 222 258 … … 243 279 submenu_bwdownset.show_all() 244 280 submenu_bwupset.show_all() 245 281 282 # Re-set the menu to partly work around bug #608219 283 if appindicator: 284 self.indicator.set_menu(self.tray_menu) 285 246 286 def disable(self): 247 """Disables the system tray icon.""" 248 log.debug("Disabling the system tray icon..") 287 """Disables the system tray icon or appindicator.""" 288 if appindicator: 289 if hasattr(self, "_sig_win_hide"): 290 self.window.window.disconnect(self._sig_win_hide) 291 self.window.window.disconnect(self._sig_win_show) 292 log.debug("Disabling the application indicator..") 293 else: 294 log.debug("Disabling the system tray icon..") 249 295 try: 250 self.tray.set_visible(False) 251 del self.tray 296 if appindicator: 297 self.indicator.set_status(appindicator.STATUS_PASSIVE) 298 del self.indicator 299 else: 300 self.tray.set_visible(False) 301 del self.tray 252 302 del self.tray_glade 253 303 del self.tray_menu 254 304 except Exception, e: … … 336 386 self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed", 337 387 "tray_download_speed_list", self.max_download_speed, "downloading.svg") 338 388 389 def _on_window_hide(self, widget, data=None): 390 """_on_window_hide - update the menuitem's status""" 391 log.debug("_on_window_hide") 392 self.tray_glade.get_widget("menuitem_show_deluge").set_active(False) 393 394 def _on_window_show(self, widget, data=None): 395 """_on_window_show - update the menuitem's status""" 396 log.debug("_on_window_show") 397 self.tray_glade.get_widget("menuitem_show_deluge").set_active(True) 398 339 399 def tray_setbwup(self, widget, data=None): 340 400 self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed", 341 401 "tray_upload_speed_list", self.max_upload_speed, "seeding.svg") … … 343 403 def setbwlimit(self, widget, string, core_key, ui_key, default, image): 344 404 """Sets the bandwidth limit based on the user selection.""" 345 405 value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s")) 406 407 346 408 if value == _("Unlimited"): 347 409 value = -1 348 410