From a40a10ed652b55e814616d492960aa4f22ecacc9 Mon Sep 17 00:00:00 2001 From: Bruno Marques Date: Mon, 27 May 2024 03:00:31 +0100 Subject: [PATCH] Added JSON theme --- EDMarketConnector.py | 14 ++++++++--- themes/dark.json | 55 ++++++++++++++++++++++++++++++++++++++++++++ ttkHyperlinkLabel.py | 7 ++++-- 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 themes/dark.json diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4d5bef6b3..4b40f0ef7 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -350,7 +350,8 @@ def already_running_popup(): handle_edmc_callback_or_foregrounding() - if locked == JournalLockResult.ALREADY_LOCKED: + if False: + #if locked == JournalLockResult.ALREADY_LOCKED: # There's a copy already running. logger.info("An EDMarketConnector.exe process was already running, exiting.") @@ -399,6 +400,7 @@ def already_running_popup(): # isort: on +import json import tkinter as tk import tkinter.filedialog import tkinter.font @@ -462,6 +464,11 @@ def open_window(systray: 'SysTrayIcon') -> None: self.systray.start() plug.load_plugins(master) + self.style = ttk.Style() + with open('themes/dark.json') as f: + dark = json.load(f) + self.style.theme_create('dark', 'default', dark) + self.style.theme_use('dark') if sys.platform == 'win32': self.w.wm_iconbitmap(default='EDMarketConnector.ico') @@ -523,7 +530,7 @@ def open_window(systray: 'SysTrayIcon') -> None: plugin_no = 0 for plugin in plug.PLUGINS: # Per plugin separator - plugin_sep = ttk.Separator(frame, name=f"plugin_hr_{plugin_no + 1}") + plugin_sep = ttk.Frame(frame, name=f"plugin_hr_{plugin_no + 1}", style='Sep.TFrame') # Per plugin frame, for it to use as its parent for own widgets plugin_frame = ttk.Frame( frame, @@ -564,6 +571,7 @@ def open_window(systray: 'SysTrayIcon') -> None: frame, name='themed_update_button', width=28, + anchor=tk.CENTER, state=tk.DISABLED ) @@ -681,7 +689,7 @@ def open_window(systray: 'SysTrayIcon') -> None: lambda e: self.help_menu.tk_popup(e.widget.winfo_rootx(), e.widget.winfo_rooty() + e.widget.winfo_height())) - ttk.Separator(self.theme_menubar).grid(columnspan=5, padx=self.PADX, sticky=tk.EW) + ttk.Frame(self.theme_menubar, style='Sep.TFrame').grid(columnspan=5, padx=self.PADX, sticky=tk.EW) theme.register(self.theme_minimize) # images aren't automatically registered theme.register(self.theme_close) self.blank_menubar = ttk.Frame(frame, name="blank_menubar") diff --git a/themes/dark.json b/themes/dark.json new file mode 100644 index 000000000..fc28b1e56 --- /dev/null +++ b/themes/dark.json @@ -0,0 +1,55 @@ +{ + "TFrame": { + "configure": { + "background": "grey4", + "highlightbackground": "#aa5500" + } + }, + "Sep.TFrame": { + "configure": { + "background": "#ff8000", + "padding": 2 + } + }, + "TLabel": { + "configure": { + "background": "grey4", + "foreground": "#ff8000", + "padding": 1 + }, + "map": { + "background": [ + ["active", "#ff8000"] + ], + "foreground": [ + ["active", "grey4"], + ["disabled", "#aa5500"] + ] + } + }, + "Hyperlink.TLabel": { + "configure": { + "foreground": "white" + } + }, + "TButton": { + "configure": { + "background": "grey4", + "foreground": "#ff8000", + "relief": "raised", + "padding": 2 + }, + "map": { + "background": [ + ["pressed", "#ff8000"] + ], + "foreground": [ + ["pressed", "grey4"], + ["disabled", "#aa5500"] + ], + "relief": [ + ["pressed", "sunken"] + ] + } + } +} diff --git a/ttkHyperlinkLabel.py b/ttkHyperlinkLabel.py index 7fd2e84f2..0e59c305f 100644 --- a/ttkHyperlinkLabel.py +++ b/ttkHyperlinkLabel.py @@ -61,12 +61,15 @@ def __init__(self, master: ttk.Frame | tk.Frame | None = None, **kw: Any) -> Non """ self.font_u: tk_font.Font self.font_n = None + self.style = 'Hyperlink.TLabel' self.url = kw.pop('url', None) self.popup_copy = kw.pop('popup_copy', False) self.underline = kw.pop('underline', None) # override ttk.Label's underline - self.foreground = kw.get('foreground', 'blue') + self.foreground = kw.get('foreground', ttk.Style().lookup( + 'Hyperlink.TLabel', 'foreground')) + # ttk.Label doesn't support disabledforeground option self.disabledforeground = kw.pop('disabledforeground', ttk.Style().lookup( - 'TLabel', 'foreground', ('disabled',))) # ttk.Label doesn't support disabledforeground option + 'Hyperlink.TLabel', 'foreground', ('disabled',))) ttk.Label.__init__(self, master, **kw) self.bind('', self._click)