From bf5824223d94f6d3546b62827eb4df08714f7c41 Mon Sep 17 00:00:00 2001 From: Inutt <1228850-inutt@users.noreply.gitlab.com> Date: Tue, 25 Nov 2025 04:44:11 +0000 Subject: [PATCH] Fix mypy linting issues Mostly related to adjusting `if sys.platform == 'win32'` logic so things that are only defined on win32 platforms don't cause issues on other platforms. --- common_utils.py | 27 +++++++++++++-------------- config/linux.py | 2 +- myNotebook.py | 16 ++++++++++++---- prefs.py | 5 +++++ util_ships.py | 3 ++- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/common_utils.py b/common_utils.py index a6f78356..ce3c7986 100644 --- a/common_utils.py +++ b/common_utils.py @@ -29,23 +29,22 @@ def ensure_on_screen(self, parent: tk.Tk): :param self: The calling class instance of tk.TopLevel :param parent: The parent window """ - if sys.platform != 'win32': - return - try: - # Get monitor info for the monitor containing the parent window - monitor = win32api.MonitorFromWindow(parent.winfo_id(), win32con.MONITOR_DEFAULTTONEAREST) - monitor_info = win32api.GetMonitorInfo(monitor) - work_area = monitor_info['Work'] # Gets the working area (excludes taskbar) + if sys.platform == 'win32': + try: + # Get monitor info for the monitor containing the parent window + monitor = win32api.MonitorFromWindow(parent.winfo_id(), win32con.MONITOR_DEFAULTTONEAREST) + monitor_info = win32api.GetMonitorInfo(monitor) + work_area = monitor_info['Work'] # Gets the working area (excludes taskbar) - # Calculate optimal position - x = max(work_area[0], min(parent.winfo_rootx(), work_area[2] - self.winfo_width())) - y = max(work_area[1], min(parent.winfo_rooty(), work_area[3] - self.winfo_height())) + # Calculate optimal position + x = max(work_area[0], min(parent.winfo_rootx(), work_area[2] - self.winfo_width())) + y = max(work_area[1], min(parent.winfo_rooty(), work_area[3] - self.winfo_height())) - # Update window position - self.geometry(f"+{x}+{y}") + # Update window position + self.geometry(f"+{x}+{y}") - except Exception as e: - logger.debug(f"Failed to ensure window is on screen: {e}") + except Exception as e: + logger.debug(f"Failed to ensure window is on screen: {e}") def log_locale(prefix: str) -> None: diff --git a/config/linux.py b/config/linux.py index 27e4d6bf..1b5ac924 100644 --- a/config/linux.py +++ b/config/linux.py @@ -75,7 +75,7 @@ class LinuxConfigMinimal: def close(self) -> None: """Release resources (stub).""" - self.config = None + del self.config def linux_helper(config: Config) -> Config: diff --git a/myNotebook.py b/myNotebook.py index 46f79622..e4fe6f89 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -50,10 +50,18 @@ 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')) + if sys.platform == 'win32': + fg_color = PAGEFG + else: + fg_color = ttk.Style().lookup('TLabel', 'foreground') + + if sys.platform == 'win32': + bg_color = PAGEBG + else: + bg_color = ttk.Style().lookup('TLabel', 'background') + + kw['foreground'] = kw.pop('foreground', fg_color) + kw['background'] = kw.pop('background', bg_color) super().__init__(master, **kw) diff --git a/prefs.py b/prefs.py index 71e03087..ef5bd2df 100644 --- a/prefs.py +++ b/prefs.py @@ -310,6 +310,11 @@ class PreferencesDialog(tk.Toplevel): self.cmdrchanged() self.themevarchanged() + # Init hotkey attributes to avoid linter errors + self.hotkey_text: ttk.Entry + self.hotkey_only_btn: nb.Checkbutton + self.hotkey_play_btn: nb.Checkbutton + # disable hotkey for the duration hotkeymgr.unregister() diff --git a/util_ships.py b/util_ships.py index 8abbe20f..4f99e731 100644 --- a/util_ships.py +++ b/util_ships.py @@ -6,6 +6,7 @@ Licensed under the GNU General Public License. See LICENSE file. """ import os +import sys from pathlib import Path from edmc_data import ship_name_map @@ -18,7 +19,7 @@ def ship_file_name(ship_name: str, ship_type: str) -> str: name = Path(name).with_suffix("").name # Check if the name is a reserved filename - if os.path.isreserved(name): + if sys.platform == 'win32' and os.path.isreserved(name): name += "_" return name.translate(