Ticket #1514: systemtray.py.patch

File systemtray.py.patch, 9.1 KB (added by Grundoko, 13 years ago)
  • /home/grundoko/Desktop/deluge-1.3.1/deluge/ui/gtkui/systemtray.py

    old new  
    3333# 
    3434# 
    3535 
     36try: 
     37    import appindicator 
     38except: 
     39    appindicator = None 
    3640 
    3741import gtk 
    3842import pkg_resources 
     
    5458            "menuitem_add_torrent", 
    5559            "menuitem_pause_all", 
    5660            "menuitem_resume_all", 
    57             "menuitem_download_limit", 
    58             "menuitem_upload_limit", 
     61#            "menuitem_download_limit", 
     62#            "menuitem_upload_limit", 
    5963            "menuitem_quitdaemon", 
    6064            "separatormenuitem1", 
    6165            "separatormenuitem2", 
    62             "separatormenuitem3", 
     66#            "separatormenuitem3", 
    6367            "separatormenuitem4" 
    6468        ] 
    6569        self.config.register_set_function("enable_system_tray", 
     
    7781 
    7882    def enable(self): 
    7983        """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..") 
    8188        self.tray_glade = gtk.glade.XML( 
    8289            pkg_resources.resource_filename("deluge.ui.gtkui", 
    8390                                            "glade/tray_menu.glade")) 
    8491 
    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) 
    8896        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 
    94106 
    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) 
    97109 
    98110 
    99111        self.tray_glade.signal_autoconnect({ 
     
    112124 
    113125        self.tray_menu = self.tray_glade.get_widget("tray_menu") 
    114126 
    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")) 
    119131 
    120132        client.register_event_handler("ConfigValueChangedEvent", self.config_value_changed) 
    121133        if not client.connected(): 
     
    123135            for widget in self.hide_widget_list: 
    124136                self.tray_glade.get_widget(widget).hide() 
    125137 
     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 
    126158        if client.connected(): 
    127159            # We're connected so we need to get some values from the core 
    128160            self.__start() 
     
    166198 
    167199    def shutdown(self): 
    168200        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) 
    170205 
    171206    def send_status_request(self): 
    172207        client.core.get_session_status([ 
     
    198233        if not self.config["enable_system_tray"]: 
    199234            return 
    200235 
    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 
    204240 
    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")) 
    213249 
    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) 
    217253 
    218         # Set the tooltip 
    219         self.tray.set_tooltip(msg) 
     254            # Set the tooltip 
     255            self.tray.set_tooltip(msg) 
    220256 
    221257        self.send_status_request() 
    222258 
     
    243279        submenu_bwdownset.show_all() 
    244280        submenu_bwupset.show_all() 
    245281 
     282        # Re-set the menu to partly work around bug #608219 
     283        if appindicator: 
     284            self.indicator.set_menu(self.tray_menu) 
     285 
    246286    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..") 
    249295        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 
    252302            del self.tray_glade 
    253303            del self.tray_menu 
    254304        except Exception, e: 
     
    336386        self.setbwlimit(widget, _("Set Maximum Download Speed"), "max_download_speed", 
    337387            "tray_download_speed_list", self.max_download_speed, "downloading.svg") 
    338388 
     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     
    339399    def tray_setbwup(self, widget, data=None): 
    340400        self.setbwlimit(widget, _("Set Maximum Upload Speed"), "max_upload_speed", 
    341401            "tray_upload_speed_list", self.max_upload_speed, "seeding.svg") 
     
    343403    def setbwlimit(self, widget, string, core_key, ui_key, default, image): 
    344404        """Sets the bandwidth limit based on the user selection.""" 
    345405        value = widget.get_children()[0].get_text().rstrip(" " + _("KiB/s")) 
     406 
     407 
    346408        if value == _("Unlimited"): 
    347409            value = -1 
    348410