From 8a36712b0dbe9db0c2fc808285728de9de5e178e Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Fri, 17 Nov 2023 13:43:51 -0500 Subject: [PATCH] ui: better handling and installation of icons --- docs/installation.md | 13 +++++++++++++ lib/solaar/ui/icons.py | 40 ---------------------------------------- lib/solaar/ui/tray.py | 6 ++---- lib/solaar/ui/window.py | 1 - setup.py | 5 ++--- 5 files changed, 17 insertions(+), 48 deletions(-) diff --git a/docs/installation.md b/docs/installation.md index 07c848af75..d8c7677376 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -136,6 +136,19 @@ If you want to have Solaar's user messages in some other language you need to ru `tools/po-compile.sh` to create the translation files before running or installing Solaar and set the LANGUAGE environment variable appropriately when running Solaar. +# Setting up Solaar's icons + +Solaar uses a number of custom icons, which have to be installed in a place where GTK can access them. + +If Solaar has never been installed, and only run from the download directory then Solaar will not be able to find the icons. +If Solaar has only been installed for a user (e.g., via pip) then Solaar will be able to find the icons, +but they may not show up in the system tray. + +One solution is to install a version of Solaar on a system-wide basis. +A more-recent version of Solaar can then be installed for a user or Solaar can be run out of the download directory. +Another solution is to copy the Solaar custom icons from share/solaar/icons to a place they can be found by GTK, +likely /usr/share/icons/hicolor/scalable/apps. + # Running Solaar at Startup Distributions can cause Solaar can be run automatically at user login by installing a desktop file at diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py index 537b2fed2a..aadf76ae12 100644 --- a/lib/solaar/ui/icons.py +++ b/lib/solaar/ui/icons.py @@ -33,48 +33,11 @@ _LARGE_SIZE = 64 Gtk.IconSize.LARGE = Gtk.icon_size_register('large', _LARGE_SIZE, _LARGE_SIZE) # Gtk.IconSize.XLARGE = Gtk.icon_size_register('x-large', _LARGE_SIZE * 2, _LARGE_SIZE * 2) -# print ("menu", int(Gtk.IconSize.MENU), Gtk.icon_size_lookup(Gtk.IconSize.MENU)) -# print ("small toolbar", int(Gtk.IconSize.SMALL_TOOLBAR), Gtk.icon_size_lookup(Gtk.IconSize.SMALL_TOOLBAR)) -# print ("button", int(Gtk.IconSize.BUTTON), Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)) -# print ("large toolbar", int(Gtk.IconSize.LARGE_TOOLBAR), Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)) -# 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)) TRAY_INIT = 'solaar-init' TRAY_OKAY = 'solaar' TRAY_ATTENTION = 'solaar-attention' - -def _look_for_application_icons(): - import os.path as _path - import sys as _sys - - from os import environ as _environ - if _log.isEnabledFor(_DEBUG): - _log.debug('sys.path[0] = %s', _sys.path[0]) - prefix_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..')) - src_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..', 'share')) - local_share = _environ.get('XDG_DATA_HOME', _path.expanduser(_path.join('~', '.local', 'share'))) - data_dirs = _environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share') - repo_share = _path.normpath(_path.join(_path.dirname(__file__), '..', '..', '..', 'share')) - setuptools_share = _path.normpath(_path.join(_path.dirname(__file__), '..', '..', 'share')) - del _sys - - share_solaar = [prefix_share] + list( - _path.join(x, 'solaar') for x in [src_share, local_share, setuptools_share, repo_share] + data_dirs.split(':') - ) - for location in share_solaar: - location = _path.join(location, 'icons') - if _log.isEnabledFor(_DEBUG): - _log.debug('looking for icons in %s', location) - - if _path.exists(_path.join(location, TRAY_ATTENTION + '.svg')): - yield location - - del _environ - # del _path - - _default_theme = None @@ -84,9 +47,6 @@ def _init_icon_paths(): return _default_theme = Gtk.IconTheme.get_default() - for p in _look_for_application_icons(): - _default_theme.prepend_search_path(p) - break # only prepend one path - that's sufficient if _log.isEnabledFor(_DEBUG): _log.debug('icon theme paths: %s', _default_theme.get_search_path()) diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index 8e04dc4bb9..298ba28e52 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -177,10 +177,8 @@ def _icon_file(icon_name): def _create(menu): _icons._init_icon_paths() - theme_paths = Gtk.IconTheme.get_default().get_search_path() - - ind = AppIndicator3.Indicator.new_with_path( - 'indicator-solaar', _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE, theme_paths[0] + ind = AppIndicator3.Indicator.new( + 'indicator-solaar', _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE ) ind.set_title(NAME) ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 63682f0b24..d7541640e8 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -818,7 +818,6 @@ def _update_info_panel(device, full=False): def init(show_window, hide_on_close): Gtk.Window.set_default_icon_name(NAME.lower()) - Gtk.Window.set_default_icon_from_file(_icons.icon_file(NAME.lower())) global _model, _tree, _details, _info, _empty, _window _model = Gtk.TreeStore(*_COLUMN_TYPES) diff --git a/setup.py b/setup.py index 8aa4f58874..2973754ea4 100755 --- a/setup.py +++ b/setup.py @@ -31,9 +31,8 @@ def _data_files(): from os.path import dirname as _dirname - yield 'share/solaar/icons', _glob('share/solaar/icons/solaar*.svg') - yield 'share/solaar/icons', _glob('share/solaar/icons/light_*.png') - yield 'share/icons/hicolor/scalable/apps', ['share/solaar/icons/solaar.svg'] + yield 'share/icons/hicolor/scalable/apps', _glob('share/solaar/icons/solaar*.svg') + yield 'share/icons/hicolor/scalable/apps', _glob('share/solaar/icons/light_*.png') for mo in _glob('share/locale/*/LC_MESSAGES/solaar.mo'): yield _dirname(mo), [mo]