theme img + font handling
@@ -268,6 +268,14 @@ class Workbench(tk.Tk):
def _init_fonts(self):
+ # Remember original standard fonts so that it's possible to reset themes
+ std_fonts = {"TkDefaultFont", "TkTextFont", "TkFixedFont", "TkMenuFont", "TkHeadingFont",
+ "TkCaptionFont", "TkSmallCaptionFont", "TkIconFont", "TkTooltipFont"}
+ self._original_font_specs = {
+ name : tk_font.nametofont(name).configure() for name in std_fonts
+ }
+
+ # set up editor and shell fonts
self.set_default("view.io_font_family",
"Courier" if running_on_mac_os() else "Courier New")
@@ -476,6 +484,7 @@ class Workbench(tk.Tk):
def _init_theming(self):
+ self._style = ttk.Style()
self._ui_themes = {}
self._syntax_themes = {}
# following will be overwritten by plugins.base_themes
@@ -675,7 +684,7 @@ class Workbench(tk.Tk):
def get_syntax_theme_names(self):
return sorted(self._syntax_themes.keys())
- def _register_ui_theme_as_tk_theme(self, name, style):
+ def _register_ui_theme_as_tk_theme(self, name):
# collect settings from all ancestors
total_settings = []
temp_name = name
@@ -688,11 +697,11 @@ class Workbench(tk.Tk):
# reached start of the chain
break
- assert temp_name in style.theme_names()
+ assert temp_name in self._style.theme_names()
# only root-parent is relevant for theme_create,
# because the method actually doesn't take parent settings into account
# (https://mail.python.org/pipermail/tkinter-discuss/2015-August/003752.html)
- style.theme_create(name, temp_name)
+ self._style.theme_create(name, temp_name)
# apply settings starting from root ancestor
for settings in total_settings:
@@ -700,18 +709,16 @@ class Workbench(tk.Tk):
settings = settings()
if isinstance(settings, dict):
- style.theme_settings(name, settings)
+ self._style.theme_settings(name, settings)
else:
for subsettings in settings:
- style.theme_settings(name, subsettings)
+ self._style.theme_settings(name, subsettings)
def _apply_ui_theme(self, name):
- style = ttk.Style()
-
- if name not in style.theme_names():
- self._register_ui_theme_as_tk_theme(name, style)
+ if name not in self._style.theme_names():
+ self._register_ui_theme_as_tk_theme(name)
- style.theme_use(name)
+ self._style.theme_use(name)
def _apply_syntax_theme(self, name):
def get_settings(name):
@@ -852,8 +859,9 @@ class Workbench(tk.Tk):
def get_image(self, filename, tk_name=None):
- if filename in self._image_mapping:
- filename = self._image_mapping[filename]
+ themed_version = self._style.lookup("IMAGES", filename)
+ if themed_version:
+ filename = themed_version
# if path is relative then interpret it as living in res folder
if not os.path.isabs(filename):
