From c1a8c5e5c791cb5b3035528a83f86ea0c3d2a614 Mon Sep 17 00:00:00 2001 From: Swapnil Devesh Date: Mon, 4 Mar 2024 22:28:42 +0530 Subject: [PATCH 1/4] Fix app name casing in UI --- lib/solaar/__init__.py | 1 + lib/solaar/ui/about.py | 6 +++--- lib/solaar/ui/tray.py | 14 +++++++------- lib/solaar/ui/window.py | 10 +++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/solaar/__init__.py b/lib/solaar/__init__.py index 11d0e3c9e0..632b52dcad 100644 --- a/lib/solaar/__init__.py +++ b/lib/solaar/__init__.py @@ -19,6 +19,7 @@ import sys as _sys NAME = "solaar" +DISPLAY_NAME = "Solaar" try: __version__ = ( diff --git a/lib/solaar/ui/about.py b/lib/solaar/ui/about.py index 781e5702e4..6fac2484dd 100644 --- a/lib/solaar/ui/about.py +++ b/lib/solaar/ui/about.py @@ -19,7 +19,7 @@ from gi.repository import Gtk -from solaar import NAME, __version__ +from solaar import NAME, DISPLAY_NAME, __version__ from solaar.i18n import _ # @@ -32,7 +32,7 @@ def _create(): about = Gtk.AboutDialog() - about.set_program_name(NAME) + about.set_program_name(DISPLAY_NAME) about.set_version(__version__) about.set_comments(_("Manages Logitech receivers,\nkeyboards, mice, and tablets.")) about.set_icon_name(NAME.lower()) @@ -83,7 +83,7 @@ def _create(): ) about.set_website("https://pwr-solaar.github.io/Solaar") - about.set_website_label(NAME) + about.set_website_label(DISPLAY_NAME) about.connect("response", lambda x, y: x.hide()) diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index 7c682c60d6..e8bcdaa59f 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -27,7 +27,7 @@ import solaar.gtk as gtk -from solaar import NAME +from solaar import NAME, DISPLAY_NAME from solaar.i18n import _ from . import icons as _icons @@ -60,8 +60,8 @@ def _create_menu(quit_handler): menu.append(no_receiver) menu.append(Gtk.SeparatorMenuItem.new()) - menu.append(_make("help-about", _("About %s") % NAME, _show_about_window, stock_id="help-about").create_menu_item()) - menu.append(_make("application-exit", _("Quit %s") % NAME, quit_handler, stock_id="application-exit").create_menu_item()) + menu.append(_make("help-about", _("About %s") % DISPLAY_NAME, _show_about_window, stock_id="help-about").create_menu_item()) + menu.append(_make("application-exit", _("Quit %s") % DISPLAY_NAME, quit_handler, stock_id="application-exit").create_menu_item()) menu.show_all() @@ -179,7 +179,7 @@ def _create(menu): ind = AppIndicator3.Indicator.new( "indicator-solaar", _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE ) - ind.set_title(NAME) + ind.set_title(DISPLAY_NAME) ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) # ind.set_attention_icon_full(_icon_file(_icons.TRAY_ATTENTION), '') # works poorly for XFCE 16 # ind.set_label(NAME, NAME) @@ -232,8 +232,8 @@ def attention(reason=None): def _create(menu): icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT) icon.set_name(NAME) - icon.set_title(NAME) - icon.set_tooltip_text(NAME) + icon.set_title(DISPLAY_NAME) + icon.set_tooltip_text(DISPLAY_NAME) icon.connect("activate", _window_toggle) icon.connect("scroll-event", _scroll) icon.connect("popup-menu", lambda icon, button, time: menu.popup(None, None, icon.position_menu, icon, button, time)) @@ -292,7 +292,7 @@ def attention(reason=None): def _generate_tooltip_lines(): if not _devices_info: - yield "%s: " % NAME + _("no receiver") + yield "%s: " % DISPLAY_NAME + _("no receiver") return yield from _generate_description_lines() diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 56fd19291b..4d8a72c333 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -24,7 +24,7 @@ from logitech_receiver.common import NamedInts as _NamedInts from logitech_receiver.status import KEYS as _K -from solaar import NAME +from solaar import NAME, DISPLAY_NAME from solaar.i18n import _, ngettext from . import action as _action @@ -315,9 +315,9 @@ def _create_window_layout(): bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL) bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START) bottom_buttons_box.set_spacing(20) - quit_button = _new_button(_("Quit %s") % NAME, "application-exit", _SMALL_BUTTON_ICON_SIZE, clicked=destroy) + quit_button = _new_button(_("Quit %s") % DISPLAY_NAME, "application-exit", _SMALL_BUTTON_ICON_SIZE, clicked=destroy) bottom_buttons_box.add(quit_button) - about_button = _new_button(_("About %s") % NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) + about_button = _new_button(_("About %s") % DISPLAY_NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) bottom_buttons_box.add(about_button) diversion_button = _new_button( _("Rule Editor"), "", _SMALL_BUTTON_ICON_SIZE, clicked=lambda *_trigger: _show_diversion_window(_model) @@ -326,7 +326,7 @@ def _create_window_layout(): bottom_buttons_box.set_child_secondary(diversion_button, True) # solaar_version = Gtk.Label() - # solaar_version.set_markup('' + NAME + ' v' + VERSION + '') + # solaar_version.set_markup('' + DISPLAY_NAME + ' v' + VERSION + '') # bottom_buttons_box.add(solaar_version) # bottom_buttons_box.set_child_secondary(solaar_version, True) @@ -343,7 +343,7 @@ def _create_window_layout(): def _create(delete_action): window = Gtk.Window() - window.set_title(NAME) + window.set_title(DISPLAY_NAME) window.set_role("status-window") # window.set_type_hint(Gdk.WindowTypeHint.UTILITY) From 4eb08330ea2da59c3b73ec65f5e71cd98a7cbe24 Mon Sep 17 00:00:00 2001 From: Swapnil Devesh Date: Mon, 4 Mar 2024 22:59:03 +0530 Subject: [PATCH 2/4] Linter fixes --- lib/solaar/ui/about.py | 2 +- lib/solaar/ui/tray.py | 10 +++++++--- lib/solaar/ui/window.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/solaar/ui/about.py b/lib/solaar/ui/about.py index 6fac2484dd..fade1a1342 100644 --- a/lib/solaar/ui/about.py +++ b/lib/solaar/ui/about.py @@ -19,7 +19,7 @@ from gi.repository import Gtk -from solaar import NAME, DISPLAY_NAME, __version__ +from solaar import DISPLAY_NAME, NAME, __version__ from solaar.i18n import _ # diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index e8bcdaa59f..3dc3825432 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -27,7 +27,7 @@ import solaar.gtk as gtk -from solaar import NAME, DISPLAY_NAME +from solaar import DISPLAY_NAME, NAME from solaar.i18n import _ from . import icons as _icons @@ -60,8 +60,12 @@ def _create_menu(quit_handler): menu.append(no_receiver) menu.append(Gtk.SeparatorMenuItem.new()) - menu.append(_make("help-about", _("About %s") % DISPLAY_NAME, _show_about_window, stock_id="help-about").create_menu_item()) - menu.append(_make("application-exit", _("Quit %s") % DISPLAY_NAME, quit_handler, stock_id="application-exit").create_menu_item()) + menu.append( + _make("help-about", _("About %s") % DISPLAY_NAME, _show_about_window, stock_id="help-about").create_menu_item() + ) + menu.append( + _make("application-exit", _("Quit %s") % DISPLAY_NAME, quit_handler, stock_id="application-exit").create_menu_item() + ) menu.show_all() diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 4d8a72c333..66403ae7ac 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -24,7 +24,7 @@ from logitech_receiver.common import NamedInts as _NamedInts from logitech_receiver.status import KEYS as _K -from solaar import NAME, DISPLAY_NAME +from solaar import DISPLAY_NAME, NAME from solaar.i18n import _, ngettext from . import action as _action From 9ac6e44e49913039fed6a83b11ab0cdfeffd7876 Mon Sep 17 00:00:00 2001 From: Swapnil Devesh Date: Tue, 5 Mar 2024 04:11:28 +0530 Subject: [PATCH 3/4] Only use NAME variable --- lib/solaar/__init__.py | 3 +-- lib/solaar/cli/__init__.py | 4 ++-- lib/solaar/cli/show.py | 2 +- lib/solaar/gtk.py | 2 +- lib/solaar/ui/about.py | 6 +++--- lib/solaar/ui/notify.py | 8 ++++---- lib/solaar/ui/tray.py | 18 +++++++++--------- lib/solaar/ui/window.py | 10 +++++----- 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/lib/solaar/__init__.py b/lib/solaar/__init__.py index 632b52dcad..5b26a1529d 100644 --- a/lib/solaar/__init__.py +++ b/lib/solaar/__init__.py @@ -18,8 +18,7 @@ import subprocess as _subprocess import sys as _sys -NAME = "solaar" -DISPLAY_NAME = "Solaar" +NAME = "Solaar" try: __version__ = ( diff --git a/lib/solaar/cli/__init__.py b/lib/solaar/cli/__init__.py index 01f2b13b3b..5bb93fe353 100644 --- a/lib/solaar/cli/__init__.py +++ b/lib/solaar/cli/__init__.py @@ -117,7 +117,7 @@ def _receivers(dev_path=None): yield r except Exception as e: logger.exception("opening " + str(dev_info)) - _sys.exit("%s: error: %s" % (NAME, str(e))) + _sys.exit("%s: error: %s" % (NAME.lower(), str(e))) def _receivers_and_devices(dev_path=None): @@ -136,7 +136,7 @@ def _receivers_and_devices(dev_path=None): yield d except Exception as e: logger.exception("opening " + str(dev_info)) - _sys.exit("%s: error: %s" % (NAME, str(e))) + _sys.exit("%s: error: %s" % (NAME.lower(), str(e))) def _find_receiver(receivers, name): diff --git a/lib/solaar/cli/show.py b/lib/solaar/cli/show.py index 1ea33b2e12..2837aa5376 100644 --- a/lib/solaar/cli/show.py +++ b/lib/solaar/cli/show.py @@ -295,7 +295,7 @@ def run(devices, args, find_receiver, find_device): assert devices assert args.device - print("%s version %s" % (NAME, __version__)) + print("%s version %s" % (NAME.lower(), __version__)) print("") device_name = args.device.lower() diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index 8d0c0c214a..b4cb72023f 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -51,7 +51,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None): gi.require_version(gi_package, gi_version) return importlib.import_module(module) except (ImportError, ValueError): - sys.exit("%s: missing required system package %s" % (NAME, os_package)) + sys.exit("%s: missing required system package %s" % (NAME.lower(), os_package)) battery_icons_style = "regular" diff --git a/lib/solaar/ui/about.py b/lib/solaar/ui/about.py index fade1a1342..781e5702e4 100644 --- a/lib/solaar/ui/about.py +++ b/lib/solaar/ui/about.py @@ -19,7 +19,7 @@ from gi.repository import Gtk -from solaar import DISPLAY_NAME, NAME, __version__ +from solaar import NAME, __version__ from solaar.i18n import _ # @@ -32,7 +32,7 @@ def _create(): about = Gtk.AboutDialog() - about.set_program_name(DISPLAY_NAME) + about.set_program_name(NAME) about.set_version(__version__) about.set_comments(_("Manages Logitech receivers,\nkeyboards, mice, and tablets.")) about.set_icon_name(NAME.lower()) @@ -83,7 +83,7 @@ def _create(): ) about.set_website("https://pwr-solaar.github.io/Solaar") - about.set_website_label(DISPLAY_NAME) + about.set_website_label(NAME) about.connect("response", lambda x, y: x.hide()) diff --git a/lib/solaar/ui/notify.py b/lib/solaar/ui/notify.py index e05af8560b..fd41842ecf 100644 --- a/lib/solaar/ui/notify.py +++ b/lib/solaar/ui/notify.py @@ -55,7 +55,7 @@ def init(): if logger.isEnabledFor(logging.INFO): logger.info("starting desktop notifications") try: - return Notify.init(NAME) + return Notify.init(NAME.lower()) except Exception: logger.exception("initializing desktop notifications") available = False @@ -80,15 +80,15 @@ def alert(reason, icon=None): assert reason if available and Notify.is_initted(): - n = _notifications.get(NAME) + n = _notifications.get(NAME.lower()) if n is None: - n = _notifications[NAME] = Notify.Notification() + n = _notifications[NAME.lower()] = Notify.Notification() # we need to use the filename here because the notifications daemon # is an external application that does not know about our icon sets icon_file = _icons.icon_file(NAME.lower()) if icon is None else _icons.icon_file(icon) - n.update(NAME, reason, icon_file) + n.update(NAME.lower(), reason, icon_file) n.set_urgency(Notify.Urgency.NORMAL) n.set_hint("desktop-entry", GLib.Variant("s", NAME.lower())) diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index 3dc3825432..aba5956bef 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -27,7 +27,7 @@ import solaar.gtk as gtk -from solaar import DISPLAY_NAME, NAME +from solaar import NAME from solaar.i18n import _ from . import icons as _icons @@ -61,10 +61,10 @@ def _create_menu(quit_handler): menu.append(Gtk.SeparatorMenuItem.new()) menu.append( - _make("help-about", _("About %s") % DISPLAY_NAME, _show_about_window, stock_id="help-about").create_menu_item() + _make("help-about", _("About %s") % NAME, _show_about_window, stock_id="help-about").create_menu_item() ) menu.append( - _make("application-exit", _("Quit %s") % DISPLAY_NAME, quit_handler, stock_id="application-exit").create_menu_item() + _make("application-exit", _("Quit %s") % NAME, quit_handler, stock_id="application-exit").create_menu_item() ) menu.show_all() @@ -183,10 +183,10 @@ def _create(menu): ind = AppIndicator3.Indicator.new( "indicator-solaar", _icon_file(_icons.TRAY_INIT), AppIndicator3.IndicatorCategory.HARDWARE ) - ind.set_title(DISPLAY_NAME) + ind.set_title(NAME) ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE) # ind.set_attention_icon_full(_icon_file(_icons.TRAY_ATTENTION), '') # works poorly for XFCE 16 - # ind.set_label(NAME, NAME) + # ind.set_label(NAME.lower(), NAME.lower()) ind.set_menu(menu) ind.connect("scroll-event", _scroll) @@ -235,9 +235,9 @@ def attention(reason=None): def _create(menu): icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT) - icon.set_name(NAME) - icon.set_title(DISPLAY_NAME) - icon.set_tooltip_text(DISPLAY_NAME) + icon.set_name(NAME.lower()) + icon.set_title(NAME) + icon.set_tooltip_text(NAME) icon.connect("activate", _window_toggle) icon.connect("scroll-event", _scroll) icon.connect("popup-menu", lambda icon, button, time: menu.popup(None, None, icon.position_menu, icon, button, time)) @@ -296,7 +296,7 @@ def attention(reason=None): def _generate_tooltip_lines(): if not _devices_info: - yield "%s: " % DISPLAY_NAME + _("no receiver") + yield "%s: " % NAME + _("no receiver") return yield from _generate_description_lines() diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 66403ae7ac..56fd19291b 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -24,7 +24,7 @@ from logitech_receiver.common import NamedInts as _NamedInts from logitech_receiver.status import KEYS as _K -from solaar import DISPLAY_NAME, NAME +from solaar import NAME from solaar.i18n import _, ngettext from . import action as _action @@ -315,9 +315,9 @@ def _create_window_layout(): bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL) bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START) bottom_buttons_box.set_spacing(20) - quit_button = _new_button(_("Quit %s") % DISPLAY_NAME, "application-exit", _SMALL_BUTTON_ICON_SIZE, clicked=destroy) + quit_button = _new_button(_("Quit %s") % NAME, "application-exit", _SMALL_BUTTON_ICON_SIZE, clicked=destroy) bottom_buttons_box.add(quit_button) - about_button = _new_button(_("About %s") % DISPLAY_NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) + about_button = _new_button(_("About %s") % NAME, "help-about", _SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) bottom_buttons_box.add(about_button) diversion_button = _new_button( _("Rule Editor"), "", _SMALL_BUTTON_ICON_SIZE, clicked=lambda *_trigger: _show_diversion_window(_model) @@ -326,7 +326,7 @@ def _create_window_layout(): bottom_buttons_box.set_child_secondary(diversion_button, True) # solaar_version = Gtk.Label() - # solaar_version.set_markup('' + DISPLAY_NAME + ' v' + VERSION + '') + # solaar_version.set_markup('' + NAME + ' v' + VERSION + '') # bottom_buttons_box.add(solaar_version) # bottom_buttons_box.set_child_secondary(solaar_version, True) @@ -343,7 +343,7 @@ def _create_window_layout(): def _create(delete_action): window = Gtk.Window() - window.set_title(DISPLAY_NAME) + window.set_title(NAME) window.set_role("status-window") # window.set_type_hint(Gdk.WindowTypeHint.UTILITY) From 5b3914b1ea698e04d8e782f85d5106efa8bfb48a Mon Sep 17 00:00:00 2001 From: Swapnil Devesh Date: Tue, 5 Mar 2024 04:18:48 +0530 Subject: [PATCH 4/4] FIx linter errors --- lib/solaar/ui/tray.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index aba5956bef..81d3a02c4b 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -60,12 +60,8 @@ def _create_menu(quit_handler): menu.append(no_receiver) menu.append(Gtk.SeparatorMenuItem.new()) - menu.append( - _make("help-about", _("About %s") % NAME, _show_about_window, stock_id="help-about").create_menu_item() - ) - menu.append( - _make("application-exit", _("Quit %s") % NAME, quit_handler, stock_id="application-exit").create_menu_item() - ) + menu.append(_make("help-about", _("About %s") % NAME, _show_about_window, stock_id="help-about").create_menu_item()) + menu.append(_make("application-exit", _("Quit %s") % NAME, quit_handler, stock_id="application-exit").create_menu_item()) menu.show_all()