ui: add option to not use battery icons for tray icon
This commit is contained in:
parent
ca0e2a0a3f
commit
1c6f289d91
|
@ -49,7 +49,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None):
|
||||||
sys.exit('%s: missing required system package %s' % (NAME, os_package))
|
sys.exit('%s: missing required system package %s' % (NAME, os_package))
|
||||||
|
|
||||||
|
|
||||||
prefer_symbolic_battery_icons = False
|
battery_icons_style = 'regular'
|
||||||
|
|
||||||
|
|
||||||
def _parse_arguments():
|
def _parse_arguments():
|
||||||
|
@ -74,7 +74,12 @@ def _parse_arguments():
|
||||||
arg_parser.add_argument(
|
arg_parser.add_argument(
|
||||||
'-w', '--window', choices=('show', 'hide', 'only'), help='start with window showing / hidden / only (no tray icon)'
|
'-w', '--window', choices=('show', 'hide', 'only'), help='start with window showing / hidden / only (no tray icon)'
|
||||||
)
|
)
|
||||||
arg_parser.add_argument('-b', '--battery-icons', choices=('regular', 'symbolic'), help='prefer regular / symbolic icons')
|
arg_parser.add_argument(
|
||||||
|
'-b',
|
||||||
|
'--battery-icons',
|
||||||
|
choices=('regular', 'symbolic', 'solaar'),
|
||||||
|
help='prefer regular battery / symbolic battery / solaar icons'
|
||||||
|
)
|
||||||
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
||||||
arg_parser.add_argument('--help-actions', action='store_true', help='print help for the optional actions')
|
arg_parser.add_argument('--help-actions', action='store_true', help='print help for the optional actions')
|
||||||
arg_parser.add_argument('action', nargs=argparse.REMAINDER, choices=_cli.actions, help='optional actions to perform')
|
arg_parser.add_argument('action', nargs=argparse.REMAINDER, choices=_cli.actions, help='optional actions to perform')
|
||||||
|
@ -88,8 +93,8 @@ def _parse_arguments():
|
||||||
if args.window is None:
|
if args.window is None:
|
||||||
args.window = 'show' # default behaviour is to show main window
|
args.window = 'show' # default behaviour is to show main window
|
||||||
|
|
||||||
global prefer_symbolic_battery_icons
|
global battery_icons_style
|
||||||
prefer_symbolic_battery_icons = True if args.battery_icons == 'symbolic' else False
|
battery_icons_style = args.battery_icons if args.battery_icons is not None else 'regular'
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
if args.debug > 0:
|
if args.debug > 0:
|
||||||
|
|
|
@ -79,7 +79,6 @@ def _look_for_application_icons():
|
||||||
|
|
||||||
|
|
||||||
_default_theme = None
|
_default_theme = None
|
||||||
_use_symbolic_icons = False
|
|
||||||
|
|
||||||
|
|
||||||
def _init_icon_paths():
|
def _init_icon_paths():
|
||||||
|
@ -93,15 +92,14 @@ def _init_icon_paths():
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
_log.debug('icon theme paths: %s', _default_theme.get_search_path())
|
_log.debug('icon theme paths: %s', _default_theme.get_search_path())
|
||||||
|
|
||||||
if gtk.prefer_symbolic_battery_icons:
|
if gtk.battery_icons_style == 'symbolic':
|
||||||
if _default_theme.has_icon('battery-good-symbolic'):
|
if not _default_theme.has_icon('battery-good-symbolic'):
|
||||||
global _use_symbolic_icons
|
|
||||||
_use_symbolic_icons = True
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
_log.warning('failed to detect symbolic icons')
|
_log.warning('failed to detect symbolic icons')
|
||||||
if not _default_theme.has_icon('battery-good'):
|
gtk.battery_icons_style = 'regular'
|
||||||
_log.warning('failed to detect icons')
|
if gtk.battery_icons_style == 'regular':
|
||||||
|
if not _default_theme.has_icon('battery-good'):
|
||||||
|
_log.warning('failed to detect icons')
|
||||||
|
gtk.battery_icons_style = 'none'
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -129,10 +127,12 @@ def _battery_icon_name(level, charging):
|
||||||
_init_icon_paths()
|
_init_icon_paths()
|
||||||
|
|
||||||
if level is None or level < 0:
|
if level is None or level < 0:
|
||||||
return 'battery-missing' + ('-symbolic' if _use_symbolic_icons else '')
|
return 'battery-missing' + ('-symbolic' if gtk.battery_icons_style == 'symbolic' else '')
|
||||||
|
|
||||||
level_name = _first_res(level, ((90, 'full'), (50, 'good'), (20, 'low'), (5, 'caution'), (0, 'empty')))
|
level_name = _first_res(level, ((90, 'full'), (50, 'good'), (20, 'low'), (5, 'caution'), (0, 'empty')))
|
||||||
return 'battery-%s%s%s' % (level_name, '-charging' if charging else '', '-symbolic' if _use_symbolic_icons else '')
|
return 'battery-%s%s%s' % (
|
||||||
|
level_name, '-charging' if charging else '', '-symbolic' if gtk.battery_icons_style == 'symbolic' else ''
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -25,6 +25,8 @@ from logging import DEBUG as _DEBUG
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from time import time as _timestamp
|
from time import time as _timestamp
|
||||||
|
|
||||||
|
import solaar.gtk as gtk
|
||||||
|
|
||||||
from gi.repository import GLib, Gtk
|
from gi.repository import GLib, Gtk
|
||||||
from gi.repository.Gdk import ScrollDirection
|
from gi.repository.Gdk import ScrollDirection
|
||||||
from logitech_receiver.status import KEYS as _K
|
from logitech_receiver.status import KEYS as _K
|
||||||
|
@ -198,7 +200,7 @@ try:
|
||||||
indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
|
indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
|
||||||
|
|
||||||
def _update_tray_icon():
|
def _update_tray_icon():
|
||||||
if _picked_device:
|
if _picked_device and gtk.battery_icons_style != 'solaar':
|
||||||
_ignore, _ignore, name, device_status = _picked_device
|
_ignore, _ignore, name, device_status = _picked_device
|
||||||
battery_level = device_status.get(_K.BATTERY_LEVEL)
|
battery_level = device_status.get(_K.BATTERY_LEVEL)
|
||||||
battery_charging = device_status.get(_K.BATTERY_CHARGING)
|
battery_charging = device_status.get(_K.BATTERY_CHARGING)
|
||||||
|
@ -251,7 +253,7 @@ except ImportError:
|
||||||
tooltip = '\n'.join(tooltip_lines).rstrip('\n')
|
tooltip = '\n'.join(tooltip_lines).rstrip('\n')
|
||||||
_icon.set_tooltip_markup(tooltip)
|
_icon.set_tooltip_markup(tooltip)
|
||||||
|
|
||||||
if _picked_device:
|
if _picked_device and gtk.battery_icons_style != 'solaar':
|
||||||
_ignore, _ignore, name, device_status = _picked_device
|
_ignore, _ignore, name, device_status = _picked_device
|
||||||
battery_level = device_status.get(_K.BATTERY_LEVEL)
|
battery_level = device_status.get(_K.BATTERY_LEVEL)
|
||||||
battery_charging = device_status.get(_K.BATTERY_CHARGING)
|
battery_charging = device_status.get(_K.BATTERY_CHARGING)
|
||||||
|
|
Loading…
Reference in New Issue