1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-21 11:27:38 +03:00

theme.py: Implement a ttk.Style, re-using self.current settings

Currently this only sets foreground and background colors, as that's all
we need for `ttk.Sizegrip` to look correct in all themes.
This commit is contained in:
Athanasius 2022-09-07 15:41:17 +01:00
parent b2b2fcbaf6
commit f014fbd525
No known key found for this signature in database
GPG Key ID: 8C392035DD80FD62

@ -115,6 +115,7 @@ elif sys.platform == 'linux':
class _Theme(object):
def __init__(self):
self.ttk_style = None
self.active = None # Starts out with no theme
self.minwidth = None
self.widgets = {}
@ -184,6 +185,10 @@ class _Theme(object):
for child in widget.winfo_children():
self.register(child)
# This class is an import-time singleton, so can't do this in __init__
# as tkinter won't have been at all set up by then.
self.ttk_style = ttk.Style()
def register_alternate(self, pair, gridopts):
self.widgets_pair.append((pair, gridopts))
@ -431,6 +436,16 @@ class _Theme(object):
self.minwidth = root.winfo_width() # Minimum width = width on first creation
root.minsize(self.minwidth, -1)
#######################################################################
# Update our ttk.Style
#
# Ref: <https://stackoverflow.com/a/54476816>
# Ref: <https://tkdocs.com/shipman/ttk-style-layer.html>
######################################################################
self.ttk_style.configure('TSizegrip', background=self.current['background'])
self.ttk_style.configure('TSizegrip', foreground=self.current['foreground'])
#######################################################################
# singleton
theme = _Theme()