1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-18 18:07:37 +03:00

prefs.py & related files: Fix up mypy type checking

* Some trivial.
* As myNotebook.py's class is based on `ttk.Notebook`, typing changed to
  that.
This commit is contained in:
Athanasius 2022-12-22 14:50:05 +00:00
parent 3b0c7370cc
commit f4b150960c
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
4 changed files with 17 additions and 16 deletions

View File

@ -216,7 +216,7 @@ class Logger:
""" """
return self.logger_channel return self.logger_channel
def set_channels_loglevel(self, level: int) -> None: def set_channels_loglevel(self, level: int | str) -> None:
""" """
Set the specified log level on the channels. Set the specified log level on the channels.
@ -226,7 +226,7 @@ class Logger:
self.logger_channel.setLevel(level) self.logger_channel.setLevel(level)
self.logger_channel_rotating.setLevel(level) self.logger_channel_rotating.setLevel(level)
def set_console_loglevel(self, level: int) -> None: def set_console_loglevel(self, level: int | str) -> None:
""" """
Set the specified log level on the console channel. Set the specified log level on the console channel.

View File

@ -58,7 +58,7 @@ class Notebook(ttk.Notebook):
class Frame(sys.platform == 'darwin' and tk.Frame or ttk.Frame): # type: ignore class Frame(sys.platform == 'darwin' and tk.Frame or ttk.Frame): # type: ignore
"""Custom t(t)k.Frame class to fix some display issues.""" """Custom t(t)k.Frame class to fix some display issues."""
def __init__(self, master: Optional[ttk.Frame] = None, **kw): def __init__(self, master: ttk.Notebook | None = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
kw['background'] = kw.pop('background', PAGEBG) kw['background'] = kw.pop('background', PAGEBG)
tk.Frame.__init__(self, master, **kw) tk.Frame.__init__(self, master, **kw)

View File

@ -9,6 +9,8 @@ import tkinter as tk
from builtins import object, str from builtins import object, str
from typing import Any, Callable, List, Mapping, MutableMapping, Optional, Tuple from typing import Any, Callable, List, Mapping, MutableMapping, Optional, Tuple
import ttk
import companion import companion
import myNotebook as nb # noqa: N813 import myNotebook as nb # noqa: N813
from config import config from config import config
@ -118,7 +120,7 @@ class Plugin(object):
return None return None
def get_prefs(self, parent: tk.Frame, cmdr: str, is_beta: bool) -> Optional[tk.Frame]: def get_prefs(self, parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> Optional[tk.Frame]:
""" """
If the plugin provides a prefs frame, create and return it. If the plugin provides a prefs frame, create and return it.
@ -248,7 +250,7 @@ def notify_stop() -> Optional[str]:
return error return error
def notify_prefs_cmdr_changed(cmdr: str, is_beta: bool) -> None: def notify_prefs_cmdr_changed(cmdr: str | None, is_beta: bool) -> None:
""" """
Notify plugins that the Cmdr was changed while the settings dialog is open. Notify plugins that the Cmdr was changed while the settings dialog is open.
@ -265,7 +267,7 @@ def notify_prefs_cmdr_changed(cmdr: str, is_beta: bool) -> None:
logger.exception(f'Plugin "{plugin.name}" failed') logger.exception(f'Plugin "{plugin.name}" failed')
def notify_prefs_changed(cmdr: str, is_beta: bool) -> None: def notify_prefs_changed(cmdr: str | None, is_beta: bool) -> None:
""" """
Notify plugins that the settings dialog has been closed. Notify plugins that the settings dialog has been closed.

View File

@ -19,7 +19,6 @@ from EDMCLogging import edmclogger, get_main_logger
from hotkey import hotkeymgr from hotkey import hotkeymgr
from l10n import Translations from l10n import Translations
from monitor import monitor from monitor import monitor
from myNotebook import Notebook
from theme import theme from theme import theme
from ttkHyperlinkLabel import HyperlinkLabel from ttkHyperlinkLabel import HyperlinkLabel
@ -279,7 +278,7 @@ class PreferencesDialog(tk.Toplevel):
frame = ttk.Frame(self) frame = ttk.Frame(self)
frame.grid(sticky=tk.NSEW) frame.grid(sticky=tk.NSEW)
notebook = nb.Notebook(frame) notebook: ttk.Notebook = nb.Notebook(frame)
notebook.bind('<<NotebookTabChanged>>', self.tabchanged) # Recompute on tab change notebook.bind('<<NotebookTabChanged>>', self.tabchanged) # Recompute on tab change
self.PADX = 10 self.PADX = 10
@ -333,7 +332,7 @@ class PreferencesDialog(tk.Toplevel):
): ):
self.geometry(f"+{position.left}+{position.top}") self.geometry(f"+{position.left}+{position.top}")
def __setup_output_tab(self, root_notebook: nb.Notebook) -> None: def __setup_output_tab(self, root_notebook: ttk.Notebook) -> None:
output_frame = nb.Frame(root_notebook) output_frame = nb.Frame(root_notebook)
output_frame.columnconfigure(0, weight=1) output_frame.columnconfigure(0, weight=1)
@ -418,13 +417,13 @@ class PreferencesDialog(tk.Toplevel):
# LANG: Label for 'Output' Settings/Preferences tab # LANG: Label for 'Output' Settings/Preferences tab
root_notebook.add(output_frame, text=_('Output')) # Tab heading in settings root_notebook.add(output_frame, text=_('Output')) # Tab heading in settings
def __setup_plugin_tabs(self, notebook: Notebook) -> None: def __setup_plugin_tabs(self, notebook: ttk.Notebook) -> None:
for plugin in plug.PLUGINS: for plugin in plug.PLUGINS:
plugin_frame = plugin.get_prefs(notebook, monitor.cmdr, monitor.is_beta) plugin_frame = plugin.get_prefs(notebook, monitor.cmdr, monitor.is_beta)
if plugin_frame: if plugin_frame:
notebook.add(plugin_frame, text=plugin.name) notebook.add(plugin_frame, text=plugin.name)
def __setup_config_tab(self, notebook: Notebook) -> None: # noqa: CCR001 def __setup_config_tab(self, notebook: ttk.Notebook) -> None: # noqa: CCR001
config_frame = nb.Frame(notebook) config_frame = nb.Frame(notebook)
config_frame.columnconfigure(1, weight=1) config_frame.columnconfigure(1, weight=1)
row = AutoInc(start=1) row = AutoInc(start=1)
@ -675,7 +674,7 @@ class PreferencesDialog(tk.Toplevel):
# LANG: Label for 'Configuration' tab in Settings # LANG: Label for 'Configuration' tab in Settings
notebook.add(config_frame, text=_('Configuration')) notebook.add(config_frame, text=_('Configuration'))
def __setup_privacy_tab(self, notebook: Notebook) -> None: def __setup_privacy_tab(self, notebook: ttk.Notebook) -> None:
frame = nb.Frame(notebook) frame = nb.Frame(notebook)
self.hide_multicrew_captain = tk.BooleanVar(value=config.get_bool('hide_multicrew_captain', default=False)) self.hide_multicrew_captain = tk.BooleanVar(value=config.get_bool('hide_multicrew_captain', default=False))
self.hide_private_group = tk.BooleanVar(value=config.get_bool('hide_private_group', default=False)) self.hide_private_group = tk.BooleanVar(value=config.get_bool('hide_private_group', default=False))
@ -697,7 +696,7 @@ class PreferencesDialog(tk.Toplevel):
notebook.add(frame, text=_('Privacy')) # LANG: Preferences privacy tab title notebook.add(frame, text=_('Privacy')) # LANG: Preferences privacy tab title
def __setup_appearance_tab(self, notebook: Notebook) -> None: def __setup_appearance_tab(self, notebook: ttk.Notebook) -> None:
self.languages = Translations.available_names() self.languages = Translations.available_names()
# Appearance theme and language setting # Appearance theme and language setting
# LANG: The system default language choice in Settings > Appearance # LANG: The system default language choice in Settings > Appearance
@ -887,7 +886,7 @@ class PreferencesDialog(tk.Toplevel):
# LANG: Label for Settings > Appearance tab # LANG: Label for Settings > Appearance tab
notebook.add(appearance_frame, text=_('Appearance')) # Tab heading in settings notebook.add(appearance_frame, text=_('Appearance')) # Tab heading in settings
def __setup_plugin_tab(self, notebook: Notebook) -> None: # noqa: CCR001 def __setup_plugin_tab(self, notebook: ttk.Notebook) -> None: # noqa: CCR001
# Plugin settings and info # Plugin settings and info
plugins_frame = nb.Frame(notebook) plugins_frame = nb.Frame(notebook)
plugins_frame.columnconfigure(0, weight=1) plugins_frame.columnconfigure(0, weight=1)
@ -1188,8 +1187,8 @@ class PreferencesDialog(tk.Toplevel):
:return: "break" as a literal, to halt processing :return: "break" as a literal, to halt processing
""" """
good = hotkeymgr.fromevent(event) good = hotkeymgr.fromevent(event)
if good: if good and isinstance(good, tuple):
(hotkey_code, hotkey_mods) = good hotkey_code, hotkey_mods = good
event.widget.delete(0, tk.END) event.widget.delete(0, tk.END)
event.widget.insert(0, hotkeymgr.display(hotkey_code, hotkey_mods)) event.widget.insert(0, hotkeymgr.display(hotkey_code, hotkey_mods))
if hotkey_code: if hotkey_code: