From 3e6c9dc78a731dc4ab56b8f00b873299063c1d75 Mon Sep 17 00:00:00 2001 From: Eric Jeschke Date: Wed, 22 May 2024 18:13:26 -1000 Subject: [PATCH] Add ability to easily customize the app icon --- ginga/gtk3w/GtkHelp.py | 4 ++-- ginga/gtk3w/Widgets.py | 12 ++++-------- ginga/qtw/Widgets.py | 6 +++--- ginga/util/paths.py | 8 +++++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ginga/gtk3w/GtkHelp.py b/ginga/gtk3w/GtkHelp.py index 4479350de..f6fd1fc43 100644 --- a/ginga/gtk3w/GtkHelp.py +++ b/ginga/gtk3w/GtkHelp.py @@ -14,7 +14,7 @@ from ginga.misc import Bunch, Callback from ginga.fonts import font_asst -from ginga.util.paths import icondir +from ginga.util.paths import icondir, app_icon_path import ginga.toolkit import gi @@ -287,7 +287,7 @@ def __init__(self, widget, label, iconpath=None): # set window icon if iconpath is None: - iconpath = os.path.join(icondir, "ginga.svg") + iconpath = app_icon_path pixbuf = pixbuf_new_from_file_at_size(iconpath, 32, 32) self.image = Gtk.Image.new_from_pixbuf(pixbuf) hbox.pack_start(self.image, False, False, 2) diff --git a/ginga/gtk3w/Widgets.py b/ginga/gtk3w/Widgets.py index 64f23abd2..dbd8d1e4c 100644 --- a/ginga/gtk3w/Widgets.py +++ b/ginga/gtk3w/Widgets.py @@ -6,12 +6,11 @@ # import os.path +from functools import reduce from ginga.gtk3w import GtkHelp -import ginga.icons - from ginga.misc import Callback, Bunch, Settings, LineHistory -from functools import reduce +from ginga.util.paths import icondir, app_icon_path from gi.repository import Gtk from gi.repository import Gdk @@ -29,9 +28,6 @@ 'Dialog', 'SaveDialog', 'DragPackage', 'WidgetMoveEvent', 'name_mangle', 'make_widget', 'hadjust', 'build_info', 'wrap'] -# path to our icons -icondir = os.path.split(ginga.icons.__file__)[0] - class WidgetError(Exception): """For errors thrown in this module.""" @@ -1583,7 +1579,7 @@ def __init__(self, parent, child, title='', iconpath=None): child_w = child.get_widget() label = Gtk.Label(title) if iconpath is None: - iconpath = os.path.join(icondir, "ginga.svg") + iconpath = app_icon_path subwin = GtkHelp.MDISubWindow(child_w, label, iconpath=iconpath) self.widget = subwin @@ -2274,7 +2270,7 @@ def __init__(self, title=None, iconpath=None): widget = GtkHelp.TopLevel() if iconpath is None: - iconpath = os.path.join(icondir, "ginga.svg") + iconpath = app_icon_path widget.set_icon(GtkHelp.get_icon(iconpath)) self.widget = widget widget.set_border_width(0) diff --git a/ginga/qtw/Widgets.py b/ginga/qtw/Widgets.py index 2aad28ffe..5c6aa6260 100644 --- a/ginga/qtw/Widgets.py +++ b/ginga/qtw/Widgets.py @@ -13,7 +13,7 @@ from ginga.qtw import QtHelp from ginga.misc import Callback, Bunch, Settings, LineHistory -from ginga.util.paths import icondir +from ginga.util.paths import icondir, app_icon_path __all__ = ['WidgetError', 'WidgetBase', 'TextEntry', 'TextEntrySet', 'GrowingTextEdit', 'TextArea', 'Label', 'Button', 'ComboBox', @@ -1958,7 +1958,7 @@ def __init__(self, parent, child, title='', iconpath=None): w = QtGui.QMdiSubWindow(parent.get_widget()) # replace Qt logo from subwindow if iconpath is None: - iconpath = os.path.join(icondir, "ginga.svg") + iconpath = app_icon_path w.setWindowIcon(QIcon(iconpath)) self.widget = w @@ -2042,7 +2042,7 @@ def __init__(self, title=None, iconpath=None): widget = QtHelp.TopLevel() if iconpath is None: - iconpath = os.path.join(icondir, "ginga.svg") + iconpath = app_icon_path widget.setWindowIcon(QIcon(iconpath)) self.widget = widget box = QtGui.QVBoxLayout() diff --git a/ginga/util/paths.py b/ginga/util/paths.py index d7b53037b..e74e9f968 100644 --- a/ginga/util/paths.py +++ b/ginga/util/paths.py @@ -18,7 +18,8 @@ # path to our icons icondir = os.path.split(ginga.icons.__file__)[0] - +# define app icon +app_icon_path = os.path.join(icondir, 'ginga.svg') if 'GINGA_HOME' in os.environ: # User override @@ -31,3 +32,8 @@ def set_home(dirpath): global ginga_home ginga_home = dirpath + + +def set_icon(svg_path): + global app_icon_path + app_icon_path = svg_path