From b4fc36701ae97be643c27e36308bd1f29869cf0d Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Mon, 3 Jun 2013 21:39:29 +0200 Subject: [PATCH] added attention() to tray icon --- lib/solaar/ui/__init__.py | 2 +- lib/solaar/ui/icons.py | 13 ++-- lib/solaar/ui/status_icon.py | 62 ++++++++++++++----- share/solaar/icons/solaar-tray-attention.png | Bin 0 -> 748 bytes share/solaar/icons/solaar-tray-init.png | Bin 0 -> 744 bytes share/solaar/icons/solaar-tray.png | Bin 0 -> 877 bytes 6 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 share/solaar/icons/solaar-tray-attention.png create mode 100644 share/solaar/icons/solaar-tray-init.png create mode 100644 share/solaar/icons/solaar-tray.png diff --git a/lib/solaar/ui/__init__.py b/lib/solaar/ui/__init__.py index d182bc0d..f19e8a5f 100644 --- a/lib/solaar/ui/__init__.py +++ b/lib/solaar/ui/__init__.py @@ -25,4 +25,4 @@ from . import notify, main_window from . import icons # for some reason, set_icon_name does not always work on windows Gtk.Window.set_default_icon_name(main_window.NAME.lower()) -Gtk.Window.set_default_icon_from_file(icons.icon_file(main_window.NAME.lower())) +Gtk.Window.set_default_icon_from_file(icons.icon_file(main_window.NAME.lower(), 32)) diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py index fd47cecc..76ea7d30 100644 --- a/lib/solaar/ui/icons.py +++ b/lib/solaar/ui/icons.py @@ -24,7 +24,9 @@ Gtk.IconSize.LARGE = Gtk.icon_size_register('large', _LARGE_SIZE, _LARGE_SIZE) # print ("dnd", int(Gtk.IconSize.DND), Gtk.icon_size_lookup(Gtk.IconSize.DND)) # print ("dialog", int(Gtk.IconSize.DIALOG), Gtk.icon_size_lookup(Gtk.IconSize.DIALOG)) -APP_ICON = ('solaar-init', 'solaar', 'solaar-fail') +TRAY_INIT = 'solaar-tray-init' +TRAY_OKAY = 'solaar-tray' +TRAY_ATTENTION = 'solaar-tray-attention' def _look_for_application_icons(): @@ -44,8 +46,8 @@ def _look_for_application_icons(): location = _path.join(location, 'icons') if _log.isEnabledFor(_DEBUG): _log.debug("looking for icons in %s", location) - solaar_png = _path.join(location, APP_ICON[0] + '.png') - if _path.exists(solaar_png): + + if _path.exists(_path.join(location, TRAY_ATTENTION + '.png')): yield location del _environ @@ -181,9 +183,10 @@ def device_icon_name(name, kind=None): def icon_file(name, size=_LARGE_SIZE): - # _log.debug("looking for file of icon %s at size %s", name, size) if _default_theme.has_icon(name): theme_icon = _default_theme.lookup_icon(name, size, 0) file_name = theme_icon.get_filename() - # _log.debug("icon %s => %s : %s", name, theme_icon, file_name) + _log.debug("icon %s(%d) => %s", name, size, file_name) return file_name + + _log.warn("icon %s(%d) not found in current theme", name, size) diff --git a/lib/solaar/ui/status_icon.py b/lib/solaar/ui/status_icon.py index 6e777e5c..2033c562 100644 --- a/lib/solaar/ui/status_icon.py +++ b/lib/solaar/ui/status_icon.py @@ -8,7 +8,7 @@ from logging import getLogger, DEBUG as _DEBUG _log = getLogger('solaar.ui.tray') del getLogger -from gi.repository import Gtk +from gi.repository import Gtk, GLib from solaar import NAME from . import action as _action, icons as _icons @@ -40,22 +40,30 @@ def _create_common(icon, menu_activate_callback): try: - from gi.repository import AppIndicator3 as AppIndicator + from gi.repository import AppIndicator3 _log.debug("using AppIndicator3") # def _scroll(ind, delta, direction): - # print ("scroll", ind, delta, direction) + # if _log.isEnabledFor(_DEBUG): + # _log.debug("scroll delta %s direction %s", delta, direction) def create(activate_callback, menu_activate_callback): assert activate_callback assert menu_activate_callback - ind = AppIndicator.Indicator.new('indicator-solaar', _icons.APP_ICON[0], AppIndicator.IndicatorCategory.HARDWARE) - ind.set_status(AppIndicator.IndicatorStatus.ACTIVE) + ind = AppIndicator3.Indicator.new( + 'indicator-solaar', + _icons.TRAY_INIT, + AppIndicator3.IndicatorCategory.HARDWARE) + ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) + ind.set_label(NAME, NAME) - theme_paths = Gtk.IconTheme.get_default().get_search_path() - ind.set_icon_theme_path(':'.join(theme_paths)) + # theme_paths = Gtk.IconTheme.get_default().get_search_path() + # ind.set_icon_theme_path(':'.join(theme_paths)) + + # ind.set_icon(_icons.TRAY_INIT) + ind.set_attention_icon(_icons.TRAY_ATTENTION) _create_common(ind, menu_activate_callback) ind.set_menu(ind._menu) @@ -66,15 +74,20 @@ try: # def destroy(ind): - # ind.set_status(AppIndicator.IndicatorStatus.PASSIVE) + # ind.set_status(AppIndicator3.IndicatorStatus.PASSIVE) def _update_icon(ind, icon_name, tooltip): - #ind.set_icon(icon_name) - ind.set_icon_full(icon_name, tooltip) - # _log.debug("set icon %s => %s %s %s", icon_name, ind.get_icon(), ind.get_title(), ind.get_status()) + icon_file = _icons.icon_file(icon_name, 32) + ind.set_icon(icon_file) + # ind.set_icon_full(icon_name, tooltip) + def attention(ind): + if ind.get_status != AppIndicator3.IndicatorStatus.ATTENTION: + ind.set_status(AppIndicator3.IndicatorStatus.ATTENTION) + GLib.timeout_add(10 * 1000, ind.set_status, AppIndicator3.IndicatorStatus.ACTIVE) + except ImportError: _log.debug("using StatusIcon") @@ -83,7 +96,7 @@ except ImportError: assert activate_callback assert menu_activate_callback - icon = Gtk.StatusIcon.new_from_icon_name(_icons.APP_ICON[0]) + icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT) icon.set_name(NAME) icon.set_tooltip_text(NAME) icon.connect('activate', activate_callback) @@ -105,6 +118,25 @@ except ImportError: icon.set_from_icon_name(icon_name) icon.set_tooltip_markup(tooltip) + + _icon_after_attention = None + + def _blink(icon, count): + global _icon_after_attention + if count % 2: + icon.set_from_icon_name(_icons.TRAY_ATTENTION) + else: + icon.set_from_icon_name(_icon_after_attention) + + if count > 0: + GLib.timeout_add(1000, _blink, icon, count - 1) + + def attention(icon): + global _icon_after_attention + if _icon_after_attention is None: + _icon_after_attention = icon.get_icon_name() + GLib.idle_add(_blink, icon, 9) + # # # @@ -135,7 +167,7 @@ def _generate_tooltip_lines(devices_info): def _generate_icon_name(icon): if not icon._devices_info: - return _icons.APP_ICON[-1] + return _icons.TRAY_INIT battery_status = None battery_level = 1000 @@ -149,14 +181,14 @@ def _generate_icon_name(icon): battery_level = level if battery_status is None: - return _icons.APP_ICON[1] + return _icons.TRAY_OKAY assert battery_level < 1000 charging = battery_status.get(_status.BATTERY_CHARGING) icon_name = _icons.battery(battery_level, charging) if icon_name and 'missing' in icon_name: icon_name = None - return icon_name or _icons.APP_ICON[1] + return icon_name or _icons.TRAY_OKAY # # diff --git a/share/solaar/icons/solaar-tray-attention.png b/share/solaar/icons/solaar-tray-attention.png new file mode 100644 index 0000000000000000000000000000000000000000..bb04eaca6c0b127cb8bbf75c3bbde80cb592aaae GIT binary patch literal 748 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyacIC_6YK2V5m}KU}$JzVE6?TYIwoGP-?)y@G60U!DvL>4nJa0`PlBg3pY z5hBzZ7dy5NN&Vduuh?(M?qxAon(&ccMO%b>q~r%+xRDCHf(MAI_YxV#|m}(msSs57Y!lvI6;x#X;^) z4C~IxyacIC_6YK2V5m}KU}$JzVE6?TYIwoGP-?)y@G60U!D*-}or-Z~$1;{-8d;fexYullXPp;dV$9sAPIbCZxCgvRc z#J%ZxsdI`Cx1i1Xn=S&|9=}pPXzSInxcF^T?!P4rW(u}(XB1nEBopK^>~G{T*R!9R z#e8?CLDypqmdmNd3ZCC1Z+DvAo_tuwV%hS~59ay53}n;$`Bm*#!R}|`oEoRNzHiXt z=KSzFb9#0>gIwzl`(+0n-`g3-f1yt4tVl-HoJyd{cbT`)$qT*@6$A+I_3w+V||k+{66MJDp<}luik^xBdF~ zuXMbTPvMNm2U`+=K_FS;8d2h$pPQSSSHj?2l$uzQnxasiS(2gP?&%v4-pD5oRHO=0 zlme8pN(QT7FfuSS)-^EGH82h_w6HQZv@$T&HZZa>Fxba2H4Q~WZhlH;S|wD2p{{{t fh@mM+gRz;m0Z^O4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