diff --git a/myNotebook.py b/myNotebook.py index 02a7bef6..b488916a 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -41,23 +41,23 @@ class Frame(ttk.Frame): """Custom ttk.Frame class to fix some display issues.""" def __init__(self, master: ttk.Notebook | None = None, **kw): - if sys.platform == 'win32': - ttk.Frame.__init__(self, master, style='nb.TFrame', **kw) - ttk.Frame(self).grid(pady=5) # top spacer - else: - ttk.Frame.__init__(self, master, **kw) - ttk.Frame(self).grid(pady=5) # top spacer - self.configure(takefocus=1) # let the frame take focus so that no particular child is focused + style = 'nb.TFrame' if sys.platform == 'win32' else None + super().__init__(master, style=style, **kw) # type: ignore + ttk.Frame(self).grid(pady=5) # Top spacer + self.configure(takefocus=1) # let the frame take focus so that no particular child is focused -class Label(tk.Label): - """Custom tk.Label class to fix some display issues.""" +class Label(ttk.Label): + """Custom ttk.Label class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - kw['foreground'] = kw.pop('foreground', PAGEFG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'foreground')) - kw['background'] = kw.pop('background', PAGEBG if sys.platform == 'win32' - else ttk.Style().lookup('TLabel', 'background')) + style = ttk.Style() + if sys.platform == 'win32': + custom_style = 'nb.TLabel' # Create or update a style to emulate the tk.Label colors + style.configure(custom_style, foreground=PAGEFG, background=PAGEBG) + else: + custom_style = 'TLabel' # Use the platform default ttk style + kw.setdefault('style', custom_style) super().__init__(master, **kw) @@ -134,10 +134,8 @@ class Button(ttk.Button): """Custom ttk.Button class to fix some display issues.""" def __init__(self, master: ttk.Frame | None = None, **kw): - if sys.platform == 'win32': - ttk.Button.__init__(self, master, style='nb.TButton', **kw) - else: - ttk.Button.__init__(self, master, **kw) + style = 'nb.TButton' if sys.platform == 'win32' else None + super().__init__(master, style=style, **kw) # type: ignore class ColoredButton(tk.Button): diff --git a/outfitting.py b/outfitting.py index 207c4883..4b014e48 100644 --- a/outfitting.py +++ b/outfitting.py @@ -302,8 +302,8 @@ def export(data, filename) -> None: try: m = lookup(v, ship_name_map) if m: - h.write(f'{rowheader}, {m["category"]}, {m["name"]}, {m.get("mount","")},' - f'{m.get("guidance","")}, {m.get("ship","")}, {m["class"]}, {m["rating"]},' + h.write(f'{rowheader}, {m["category"]}, {m["name"]}, {m.get("mount", "")},' + f'{m.get("guidance", "")}, {m.get("ship", "")}, {m["class"]}, {m["rating"]},' f'{m["id"]}, {data["timestamp"]}\n') except ValueError as e: diff --git a/plugins/eddn.py b/plugins/eddn.py index bdf0c96e..2e37e1bf 100644 --- a/plugins/eddn.py +++ b/plugins/eddn.py @@ -29,6 +29,7 @@ import pathlib import re import sqlite3 import tkinter as tk +from tkinter import ttk import warnings from platform import system from textwrap import dedent @@ -115,15 +116,15 @@ class This: # Tracking UI self.ui: tk.Frame - self.ui_system_name: tk.Label - self.ui_system_address: tk.Label - self.ui_j_body_name: tk.Label - self.ui_j_body_id: tk.Label - self.ui_j_body_type: tk.Label - self.ui_s_body_name: tk.Label - self.ui_station_name: tk.Label - self.ui_station_type: tk.Label - self.ui_station_marketid: tk.Label + self.ui_system_name: ttk.Label + self.ui_system_address: ttk.Label + self.ui_j_body_name: ttk.Label + self.ui_j_body_id: ttk.Label + self.ui_j_body_type: ttk.Label + self.ui_s_body_name: ttk.Label + self.ui_station_name: ttk.Label + self.ui_station_type: ttk.Label + self.ui_station_marketid: ttk.Label this = This() @@ -2027,15 +2028,15 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # System ####################################################################### # SystemName - system_name_label = tk.Label(this.ui, text="J:SystemName:") + system_name_label = ttk.Label(this.ui, text="J:SystemName:") system_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_system_name = tk.Label(this.ui, name='eddn_track_system_name', anchor=tk.W) + this.ui_system_name = ttk.Label(this.ui, name='eddn_track_system_name', anchor=tk.W) this.ui_system_name.grid(row=row, column=1, sticky=tk.E) row += 1 # SystemAddress - system_address_label = tk.Label(this.ui, text="J:SystemAddress:") + system_address_label = ttk.Label(this.ui, text="J:SystemAddress:") system_address_label.grid(row=row, column=0, sticky=tk.W) - this.ui_system_address = tk.Label(this.ui, name='eddn_track_system_address', anchor=tk.W) + this.ui_system_address = ttk.Label(this.ui, name='eddn_track_system_address', anchor=tk.W) this.ui_system_address.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### @@ -2044,27 +2045,27 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # Body ####################################################################### # Body Name from Journal - journal_body_name_label = tk.Label(this.ui, text="J:BodyName:") + journal_body_name_label = ttk.Label(this.ui, text="J:BodyName:") journal_body_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_name = tk.Label(this.ui, name='eddn_track_j_body_name', anchor=tk.W) + this.ui_j_body_name = ttk.Label(this.ui, name='eddn_track_j_body_name', anchor=tk.W) this.ui_j_body_name.grid(row=row, column=1, sticky=tk.E) row += 1 # Body ID from Journal - journal_body_id_label = tk.Label(this.ui, text="J:BodyID:") + journal_body_id_label = ttk.Label(this.ui, text="J:BodyID:") journal_body_id_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_id = tk.Label(this.ui, name='eddn_track_j_body_id', anchor=tk.W) + this.ui_j_body_id = ttk.Label(this.ui, name='eddn_track_j_body_id', anchor=tk.W) this.ui_j_body_id.grid(row=row, column=1, sticky=tk.E) row += 1 # Body Type from Journal - journal_body_type_label = tk.Label(this.ui, text="J:BodyType:") + journal_body_type_label = ttk.Label(this.ui, text="J:BodyType:") journal_body_type_label.grid(row=row, column=0, sticky=tk.W) - this.ui_j_body_type = tk.Label(this.ui, name='eddn_track_j_body_type', anchor=tk.W) + this.ui_j_body_type = ttk.Label(this.ui, name='eddn_track_j_body_type', anchor=tk.W) this.ui_j_body_type.grid(row=row, column=1, sticky=tk.E) row += 1 # Body Name from Status.json - status_body_name_label = tk.Label(this.ui, text="S:BodyName:") + status_body_name_label = ttk.Label(this.ui, text="S:BodyName:") status_body_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_s_body_name = tk.Label(this.ui, name='eddn_track_s_body_name', anchor=tk.W) + this.ui_s_body_name = ttk.Label(this.ui, name='eddn_track_s_body_name', anchor=tk.W) this.ui_s_body_name.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### @@ -2073,21 +2074,21 @@ def plugin_app(parent: tk.Tk) -> tk.Frame | None: # Station ####################################################################### # Name - status_station_name_label = tk.Label(this.ui, text="J:StationName:") + status_station_name_label = ttk.Label(this.ui, text="J:StationName:") status_station_name_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_name = tk.Label(this.ui, name='eddn_track_station_name', anchor=tk.W) + this.ui_station_name = ttk.Label(this.ui, name='eddn_track_station_name', anchor=tk.W) this.ui_station_name.grid(row=row, column=1, sticky=tk.E) row += 1 # Type - status_station_type_label = tk.Label(this.ui, text="J:StationType:") + status_station_type_label = ttk.Label(this.ui, text="J:StationType:") status_station_type_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_type = tk.Label(this.ui, name='eddn_track_station_type', anchor=tk.W) + this.ui_station_type = ttk.Label(this.ui, name='eddn_track_station_type', anchor=tk.W) this.ui_station_type.grid(row=row, column=1, sticky=tk.E) row += 1 # MarketID - status_station_marketid_label = tk.Label(this.ui, text="J:StationID:") + status_station_marketid_label = ttk.Label(this.ui, text="J:StationID:") status_station_marketid_label.grid(row=row, column=0, sticky=tk.W) - this.ui_station_marketid = tk.Label(this.ui, name='eddn_track_station_id', anchor=tk.W) + this.ui_station_marketid = ttk.Label(this.ui, name='eddn_track_station_id', anchor=tk.W) this.ui_station_marketid.grid(row=row, column=1, sticky=tk.E) row += 1 ####################################################################### diff --git a/plugins/inara.py b/plugins/inara.py index 7bc31a30..e398a3f3 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -122,11 +122,11 @@ class This: self.station_marketid = None # Prefs UI - self.log: 'tk.IntVar' + self.log: tk.IntVar self.log_button: nb.Checkbutton self.label: HyperlinkLabel self.apikey: nb.EntryMenu - self.apikey_label: tk.Label + self.apikey_label: ttk.Label self.events: dict[Credentials, Deque[Event]] = defaultdict(deque) self.event_lock: Lock = threading.Lock() # protects events, for use when rewriting events @@ -1610,7 +1610,7 @@ def handle_api_error(data: Mapping[str, Any], status: int, reply: dict[str, Any] """ error_message = reply['header'].get('eventStatusText', "") logger.warning(f'Inara\t{status} {error_message}') - logger.debug(f'JSON data:\n{json.dumps(data, indent=2, separators = (",", ": "))}') + logger.debug(f'JSON data:\n{json.dumps(data, indent=2, separators=(",", ": "))}') # LANG: INARA API returned some kind of error (error message will be contained in {MSG}) plug.show_error(tr.tl('Error: Inara {MSG}').format(MSG=error_message)) diff --git a/stats.py b/stats.py index 4c4b0e3d..c16ec880 100644 --- a/stats.py +++ b/stats.py @@ -457,7 +457,7 @@ class StatsResults(tk.Toplevel): # label = HyperlinkLabel(parent, text=col_content, popup_copy=True) label = nb.Label(parent, text=col_content) if with_copy: - label.bind('', self.copy_callback(label, col_content)) + label.bind('', self.copy_callback(label, col_content)) # type: ignore if i == 0: label.grid(padx=10, sticky=tk.W) diff --git a/tests/config/test_config.py b/tests/config/test_config.py index e839afc7..642da5c2 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -117,7 +117,7 @@ class TestNewConfig: @mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list))) def test_list(self, lst: list[str]) -> None: """Save a list and then ask for it back.""" - name = f'list_test_{ hash("".join(lst)) }' + name = f'list_test_{hash("".join(lst))}' config.set(name, lst) config.save() @@ -222,7 +222,7 @@ class TestOldNewConfig: # So insert those spaces here, to ensure that it works otherwise. lst = [e if len(e) > 0 else ' ' for e in lst] - name = self.KEY_PREFIX + f'list_test_{ hash("".join(lst)) }' + name = self.KEY_PREFIX + f'list_test_{hash("".join(lst))}' old_config.set(name, lst) old_config.save()