Skip to content

Commit

Permalink
theme.py: Implement a ttk.Style, re-using self.current settings
Browse files Browse the repository at this point in the history
Currently this only sets foreground and background colors, as that's all
we need for `ttk.Sizegrip` to look correct in all themes.
  • Loading branch information
Athanasius committed Dec 26, 2023
1 parent d4d53e0 commit 98ccde9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ def register(self, widget: tk.Widget | tk.BitmapImage) -> None: # noqa: CCR001,
self.register(child)

def register_alternate(self, pair: tuple, gridopts: dict) -> None:
# 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()
self.widgets_pair.append((pair, gridopts))

def button_bind(
Expand Down Expand Up @@ -512,6 +515,16 @@ def apply(self, root: tk.Tk) -> None: # noqa: CCR001, C901
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()

0 comments on commit 98ccde9

Please sign in to comment.