From 98ccde92a9bec6ee41945d0aea4aebe8d8a70577 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 7 Sep 2022 15:41:17 +0100 Subject: [PATCH] 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. --- theme.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/theme.py b/theme.py index 38be6638c..6cc9bee69 100644 --- a/theme.py +++ b/theme.py @@ -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( @@ -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: + # Ref: + ###################################################################### + self.ttk_style.configure('TSizegrip', background=self.current['background']) + self.ttk_style.configure('TSizegrip', foreground=self.current['foreground']) + ####################################################################### + # singleton theme = _Theme()