Skip to content

Commit

Permalink
ui: better handling and installation of icons
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Nov 17, 2023
1 parent e71ed8a commit 8a36712
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 48 deletions.
13 changes: 13 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 0 additions & 40 deletions lib/solaar/ui/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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())

Expand Down
6 changes: 2 additions & 4 deletions lib/solaar/ui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/solaar/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8a36712

Please sign in to comment.