[GTK3] Migrate to AppIndicator3

Replace the old appindicator imports with AppIndicator3.

- Only few changes required due to Enum renaming.
- Updated the preference import to include require_version and set a bool.
- The password preference needs to be encoded for hashlib on Python3 but
also need to keep Python 2 support so attempt decode then encode.
This commit is contained in:
Calum Lind 2018-10-11 17:23:33 +01:00
parent 7c1c3f62d1
commit 5183c92543
2 changed files with 29 additions and 22 deletions

View File

@ -14,6 +14,7 @@ import logging
import os import os
from hashlib import sha1 as sha from hashlib import sha1 as sha
from gi import require_version
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository.Gdk import Color from gi.repository.Gdk import Color
@ -36,9 +37,12 @@ except ImportError:
from urlparse import urlparse # pylint: disable=ungrouped-imports from urlparse import urlparse # pylint: disable=ungrouped-imports
try: try:
import appindicator require_version('AppIndicator3', '0.1')
except ImportError: from gi.repository import AppIndicator3 # noqa: F401
except (ImportError, ValueError):
appindicator = False appindicator = False
else:
appindicator = True
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -168,7 +172,7 @@ class Preferences(component.Component):
self.builder.connect_signals(self) self.builder.connect_signals(self)
# Radio buttons to choose between systray and appindicator # Radio buttons to choose between systray and appindicator
self.builder.get_object('alignment_tray_type').set_visible(bool(appindicator)) self.builder.get_object('alignment_tray_type').set_visible(appindicator)
from .gtkui import DEFAULT_PREFS from .gtkui import DEFAULT_PREFS
@ -750,7 +754,9 @@ class Preferences(component.Component):
'chk_lock_tray' 'chk_lock_tray'
).get_active() ).get_active()
passhex = sha( passhex = sha(
deluge.common.decode_bytes(
self.builder.get_object('txt_tray_password').get_text() self.builder.get_object('txt_tray_password').get_text()
).encode()
).hexdigest() ).hexdigest()
if passhex != 'c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7': if passhex != 'c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7':
new_gtkui_config['tray_password'] = passhex new_gtkui_config['tray_password'] = passhex

View File

@ -12,6 +12,7 @@ from __future__ import unicode_literals
import logging import logging
import os import os
from gi import require_version
from gi.repository.Gtk import Builder, RadioMenuItem, StatusIcon from gi.repository.Gtk import Builder, RadioMenuItem, StatusIcon
import deluge.component as component import deluge.component as component
@ -29,9 +30,10 @@ from .common import build_menu_radio_list, get_logo
from .dialogs import OtherDialog from .dialogs import OtherDialog
try: try:
import appindicator require_version('AppIndicator3', '0.1')
except ImportError: from gi.repository import AppIndicator3
appindicator = None except (ValueError, ImportError):
AppIndicator3 = None
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -84,16 +86,15 @@ class SystemTray(component.Component):
self.tray_menu = self.builder.get_object('tray_menu') self.tray_menu = self.builder.get_object('tray_menu')
if appindicator and self.config['enable_appindicator']: if AppIndicator3 and self.config['enable_appindicator']:
log.debug('Enabling the Application Indicator...') log.debug('Enabling the Application Indicator...')
self.indicator = appindicator.Indicator( self.indicator = AppIndicator3.Indicator.new(
'deluge', 'deluge', appindicator.CATEGORY_APPLICATION_STATUS 'deluge',
'deluge-panel',
AppIndicator3.IndicatorCategory.APPLICATION_STATUS,
) )
try:
self.indicator.set_property('title', _('Deluge')) self.indicator.set_property('title', _('Deluge'))
except TypeError:
# Catch 'title' property error for previous appindicator versions
pass
# Pass the menu to the Application Indicator # Pass the menu to the Application Indicator
self.indicator.set_menu(self.tray_menu) self.indicator.set_menu(self.tray_menu)
@ -110,7 +111,7 @@ class SystemTray(component.Component):
self.builder.get_object('menuitem_show_deluge').set_active(False) self.builder.get_object('menuitem_show_deluge').set_active(False)
# Show the Application Indicator # Show the Application Indicator
self.indicator.set_status(appindicator.STATUS_ACTIVE) self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
else: else:
log.debug('Enabling the system tray icon..') log.debug('Enabling the system tray icon..')
@ -184,8 +185,8 @@ class SystemTray(component.Component):
def shutdown(self): def shutdown(self):
if self.config['enable_system_tray']: if self.config['enable_system_tray']:
if appindicator and self.config['enable_appindicator']: if AppIndicator3 and self.config['enable_appindicator']:
self.indicator.set_status(appindicator.STATUS_PASSIVE) self.indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
else: else:
self.tray.set_visible(False) self.tray.set_visible(False)
@ -219,7 +220,7 @@ class SystemTray(component.Component):
return return
# Tool tip text not available for appindicator # Tool tip text not available for appindicator
if appindicator and self.config['enable_appindicator']: if AppIndicator3 and self.config['enable_appindicator']:
if self.mainwindow.visible(): if self.mainwindow.visible():
self.builder.get_object('menuitem_show_deluge').set_active(True) self.builder.get_object('menuitem_show_deluge').set_active(True)
else: else:
@ -285,19 +286,19 @@ class SystemTray(component.Component):
submenu_bwupset.show_all() submenu_bwupset.show_all()
def disable(self, invert_app_ind_conf=False): def disable(self, invert_app_ind_conf=False):
"""Disables the system tray icon or appindicator.""" """Disables the system tray icon or Appindicator."""
try: try:
if invert_app_ind_conf: if invert_app_ind_conf:
app_ind_conf = not self.config['enable_appindicator'] app_ind_conf = not self.config['enable_appindicator']
else: else:
app_ind_conf = self.config['enable_appindicator'] app_ind_conf = self.config['enable_appindicator']
if appindicator and app_ind_conf: if AppIndicator3 and app_ind_conf:
if hasattr(self, '_sig_win_hide'): if hasattr(self, '_sig_win_hide'):
self.mainwindow.window.disconnect(self._sig_win_hide) self.mainwindow.window.disconnect(self._sig_win_hide)
self.mainwindow.window.disconnect(self._sig_win_show) self.mainwindow.window.disconnect(self._sig_win_show)
log.debug('Disabling the application indicator..') log.debug('Disabling the application indicator..')
self.indicator.set_status(appindicator.STATUS_PASSIVE) self.indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
del self.indicator del self.indicator
else: else:
log.debug('Disabling the system tray icon..') log.debug('Disabling the system tray icon..')