Skip to content

Commit

Permalink
Add ability to easily customize the app icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ejeschke committed May 23, 2024
1 parent 0654dd4 commit 3e6c9dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ginga/gtk3w/GtkHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions ginga/gtk3w/Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ginga/qtw/Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion ginga/util/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 3e6c9dc

Please sign in to comment.