1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 16:27:13 +03:00

myNotebook.py: Now passes flake8 & mypy

* Typed `master` to each `__init__()`.
* Having to `# type: ignore` the base class for the classes which are
  "tk on darwin, else ttk" as this 'dynamic' type confuses mypy.

  See the comment on `class Frame` for a suggested proper fix, which will
  be more work.
This commit is contained in:
Athanasius 2022-12-03 12:16:44 +00:00
parent 84860607d7
commit 514f3fac8a
No known key found for this signature in database
GPG Key ID: 772697E181BB2767

View File

@ -13,6 +13,7 @@ Entire file may be imported by plugins.
import sys import sys
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import Optional
# Can't do this with styles on OSX - http://www.tkdocs.com/tutorial/styles.html#whydifficult # Can't do this with styles on OSX - http://www.tkdocs.com/tutorial/styles.html#whydifficult
if sys.platform == 'darwin': if sys.platform == 'darwin':
@ -28,7 +29,7 @@ elif sys.platform == 'win32':
class Notebook(ttk.Notebook): class Notebook(ttk.Notebook):
"""Custom ttk.Notebook class to fix some display issues.""" """Custom ttk.Notebook class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
ttk.Notebook.__init__(self, master, **kw) ttk.Notebook.__init__(self, master, **kw)
style = ttk.Style() style = ttk.Style()
@ -51,10 +52,13 @@ class Notebook(ttk.Notebook):
self.grid(padx=10, pady=10, sticky=tk.NSEW) self.grid(padx=10, pady=10, sticky=tk.NSEW)
class Frame(sys.platform == 'darwin' and tk.Frame or ttk.Frame): # FIXME: The real fix for this 'dynamic type' would be to split this whole
# thing into being a module with per-platform files, as we've done with config
# That would also make the code cleaner.
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=None, **kw): def __init__(self, master: Optional[ttk.Frame] = 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)
@ -71,7 +75,7 @@ class Frame(sys.platform == 'darwin' and tk.Frame or ttk.Frame):
class Label(tk.Label): class Label(tk.Label):
"""Custom tk.Label class to fix some display issues.""" """Custom tk.Label class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform in ['darwin', 'win32']: if sys.platform in ['darwin', 'win32']:
kw['foreground'] = kw.pop('foreground', PAGEFG) kw['foreground'] = kw.pop('foreground', PAGEFG)
kw['background'] = kw.pop('background', PAGEBG) kw['background'] = kw.pop('background', PAGEBG)
@ -81,10 +85,10 @@ class Label(tk.Label):
tk.Label.__init__(self, master, **kw) # Just use tk.Label on all platforms tk.Label.__init__(self, master, **kw) # Just use tk.Label on all platforms
class Entry(sys.platform == 'darwin' and tk.Entry or ttk.Entry): class Entry(sys.platform == 'darwin' and tk.Entry or ttk.Entry): # type: ignore
"""Custom t(t)k.Entry class to fix some display issues.""" """Custom t(t)k.Entry class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
kw['highlightbackground'] = kw.pop('highlightbackground', PAGEBG) kw['highlightbackground'] = kw.pop('highlightbackground', PAGEBG)
tk.Entry.__init__(self, master, **kw) tk.Entry.__init__(self, master, **kw)
@ -92,10 +96,10 @@ class Entry(sys.platform == 'darwin' and tk.Entry or ttk.Entry):
ttk.Entry.__init__(self, master, **kw) ttk.Entry.__init__(self, master, **kw)
class Button(sys.platform == 'darwin' and tk.Button or ttk.Button): class Button(sys.platform == 'darwin' and tk.Button or ttk.Button): # type: ignore
"""Custom t(t)k.Button class to fix some display issues.""" """Custom t(t)k.Button class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
kw['highlightbackground'] = kw.pop('highlightbackground', PAGEBG) kw['highlightbackground'] = kw.pop('highlightbackground', PAGEBG)
tk.Button.__init__(self, master, **kw) tk.Button.__init__(self, master, **kw)
@ -105,10 +109,10 @@ class Button(sys.platform == 'darwin' and tk.Button or ttk.Button):
ttk.Button.__init__(self, master, **kw) ttk.Button.__init__(self, master, **kw)
class ColoredButton(sys.platform == 'darwin' and tk.Label or tk.Button): class ColoredButton(sys.platform == 'darwin' and tk.Label or tk.Button): # type: ignore
"""Custom t(t)k.ColoredButton class to fix some display issues.""" """Custom t(t)k.ColoredButton class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
# Can't set Button background on OSX, so use a Label instead # Can't set Button background on OSX, so use a Label instead
kw['relief'] = kw.pop('relief', tk.RAISED) kw['relief'] = kw.pop('relief', tk.RAISED)
@ -123,10 +127,10 @@ class ColoredButton(sys.platform == 'darwin' and tk.Label or tk.Button):
self._command() self._command()
class Checkbutton(sys.platform == 'darwin' and tk.Checkbutton or ttk.Checkbutton): class Checkbutton(sys.platform == 'darwin' and tk.Checkbutton or ttk.Checkbutton): # type: ignore
"""Custom t(t)k.Checkbutton class to fix some display issues.""" """Custom t(t)k.Checkbutton class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
kw['foreground'] = kw.pop('foreground', PAGEFG) kw['foreground'] = kw.pop('foreground', PAGEFG)
kw['background'] = kw.pop('background', PAGEBG) kw['background'] = kw.pop('background', PAGEBG)
@ -137,10 +141,10 @@ class Checkbutton(sys.platform == 'darwin' and tk.Checkbutton or ttk.Checkbutton
ttk.Checkbutton.__init__(self, master, **kw) ttk.Checkbutton.__init__(self, master, **kw)
class Radiobutton(sys.platform == 'darwin' and tk.Radiobutton or ttk.Radiobutton): class Radiobutton(sys.platform == 'darwin' and tk.Radiobutton or ttk.Radiobutton): # type: ignore
"""Custom t(t)k.Radiobutton class to fix some display issues.""" """Custom t(t)k.Radiobutton class to fix some display issues."""
def __init__(self, master=None, **kw): def __init__(self, master: Optional[ttk.Frame] = None, **kw):
if sys.platform == 'darwin': if sys.platform == 'darwin':
kw['foreground'] = kw.pop('foreground', PAGEFG) kw['foreground'] = kw.pop('foreground', PAGEFG)
kw['background'] = kw.pop('background', PAGEBG) kw['background'] = kw.pop('background', PAGEBG)
@ -151,7 +155,7 @@ class Radiobutton(sys.platform == 'darwin' and tk.Radiobutton or ttk.Radiobutton
ttk.Radiobutton.__init__(self, master, **kw) ttk.Radiobutton.__init__(self, master, **kw)
class OptionMenu(sys.platform == 'darwin' and tk.OptionMenu or ttk.OptionMenu): class OptionMenu(sys.platform == 'darwin' and tk.OptionMenu or ttk.OptionMenu): # type: ignore
"""Custom t(t)k.OptionMenu class to fix some display issues.""" """Custom t(t)k.OptionMenu class to fix some display issues."""
def __init__(self, master, variable, default=None, *values, **kw): def __init__(self, master, variable, default=None, *values, **kw):