ui: better handling and installation of icons

This commit is contained in:
Peter F. Patel-Schneider 2023-11-17 13:43:51 -05:00
parent b2eb039e2d
commit 5ca1790cb8
5 changed files with 17 additions and 48 deletions

View File

@ -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 `tools/po-compile.sh` to create the translation files before running or installing Solaar
and set the LANGUAGE environment variable appropriately when running 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 # Running Solaar at Startup
Distributions can cause Solaar can be run automatically at user login by installing a desktop file at Distributions can cause Solaar can be run automatically at user login by installing a desktop file at

View File

@ -33,48 +33,11 @@ del getLogger
_LARGE_SIZE = 64 _LARGE_SIZE = 64
Gtk.IconSize.LARGE = Gtk.icon_size_register('large', _LARGE_SIZE, _LARGE_SIZE) 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) # 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_INIT = 'solaar-init'
TRAY_OKAY = 'solaar' TRAY_OKAY = 'solaar'
TRAY_ATTENTION = 'solaar-attention' 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 _default_theme = None
@ -84,9 +47,6 @@ def _init_icon_paths():
return return
_default_theme = Gtk.IconTheme.get_default() _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): 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())

View File

@ -177,10 +177,8 @@ try:
def _create(menu): def _create(menu):
_icons._init_icon_paths() _icons._init_icon_paths()
theme_paths = Gtk.IconTheme.get_default().get_search_path() ind = AppIndicator3.Indicator.new(
'indicator-solaar', _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE
ind = AppIndicator3.Indicator.new_with_path(
'indicator-solaar', _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE, theme_paths[0]
) )
ind.set_title(NAME) ind.set_title(NAME)
ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE)

View File

@ -818,7 +818,6 @@ _window = None
def init(show_window, hide_on_close): def init(show_window, hide_on_close):
Gtk.Window.set_default_icon_name(NAME.lower()) 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 global _model, _tree, _details, _info, _empty, _window
_model = Gtk.TreeStore(*_COLUMN_TYPES) _model = Gtk.TreeStore(*_COLUMN_TYPES)

View File

@ -31,9 +31,8 @@ except Exception: # get commit from Ubuntu dpkg-parsechangelog
def _data_files(): def _data_files():
from os.path import dirname as _dirname from os.path import dirname as _dirname
yield 'share/solaar/icons', _glob('share/solaar/icons/solaar*.svg') yield 'share/icons/hicolor/scalable/apps', _glob('share/solaar/icons/solaar*.svg')
yield 'share/solaar/icons', _glob('share/solaar/icons/light_*.png') yield 'share/icons/hicolor/scalable/apps', _glob('share/solaar/icons/light_*.png')
yield 'share/icons/hicolor/scalable/apps', ['share/solaar/icons/solaar.svg']
for mo in _glob('share/locale/*/LC_MESSAGES/solaar.mo'): for mo in _glob('share/locale/*/LC_MESSAGES/solaar.mo'):
yield _dirname(mo), [mo] yield _dirname(mo), [mo]