[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
from hashlib import sha1 as sha
from gi import require_version
from gi.repository import Gtk
from gi.repository.Gdk import Color
@ -36,9 +37,12 @@ except ImportError:
from urlparse import urlparse # pylint: disable=ungrouped-imports
try:
import appindicator
except ImportError:
require_version('AppIndicator3', '0.1')
from gi.repository import AppIndicator3 # noqa: F401
except (ImportError, ValueError):
appindicator = False
else:
appindicator = True
log = logging.getLogger(__name__)
@ -168,7 +172,7 @@ class Preferences(component.Component):
self.builder.connect_signals(self)
# 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
@ -750,7 +754,9 @@ class Preferences(component.Component):
'chk_lock_tray'
).get_active()
passhex = sha(
self.builder.get_object('txt_tray_password').get_text()
deluge.common.decode_bytes(
self.builder.get_object('txt_tray_password').get_text()
).encode()
).hexdigest()
if passhex != 'c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7':
new_gtkui_config['tray_password'] = passhex

View File

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