From b9b8e3a5f16eb99b2fd12b17d2e16ce02615a547 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Mon, 13 Jan 2020 15:31:41 -0800 Subject: [PATCH] more on python type hint --- daemon/core/gui/app.py | 3 ++- daemon/core/gui/dialogs/about.py | 6 +++++- daemon/core/gui/dialogs/alerts.py | 6 +++++- daemon/core/gui/dialogs/canvassizeandscale.py | 6 +++++- daemon/core/gui/dialogs/canvaswallpaper.py | 6 +++++- daemon/core/gui/dialogs/colorpicker.py | 11 ++++++++++- daemon/core/gui/dialogs/copyserviceconfig.py | 8 ++++++-- daemon/core/gui/dialogs/customnodes.py | 8 ++++++-- daemon/core/gui/dialogs/dialog.py | 13 +++++++++++-- daemon/core/gui/dialogs/emaneconfig.py | 19 ++++++++++++++++--- daemon/core/gui/dialogs/hooks.py | 8 ++++++-- daemon/core/gui/dialogs/linkconfig.py | 10 +++++++--- daemon/core/gui/dialogs/marker.py | 8 +++++++- daemon/core/gui/dialogs/mobilityconfig.py | 7 ++++++- daemon/core/gui/dialogs/mobilityplayer.py | 7 ++++++- daemon/core/gui/dialogs/nodeconfig.py | 7 ++++++- daemon/core/gui/dialogs/nodeservice.py | 9 ++++++++- daemon/core/gui/dialogs/observers.py | 6 +++++- daemon/core/gui/dialogs/preferences.py | 6 +++++- daemon/core/gui/dialogs/servers.py | 6 +++++- daemon/core/gui/dialogs/serviceconfig.py | 7 +++++-- daemon/core/gui/dialogs/sessionoptions.py | 6 +++++- daemon/core/gui/dialogs/sessions.py | 7 +++++-- daemon/core/gui/dialogs/shapemod.py | 13 ++++++------- daemon/core/gui/dialogs/throughput.py | 6 +++++- daemon/core/gui/dialogs/wlanconfig.py | 7 ++++++- daemon/core/gui/graph/node.py | 14 +++++++++++++- daemon/core/gui/statusbar.py | 2 +- daemon/core/gui/task.py | 5 ++++- daemon/core/gui/themes.py | 2 +- daemon/core/gui/toolbar.py | 2 +- daemon/core/gui/widgets.py | 2 +- 32 files changed, 185 insertions(+), 48 deletions(-) diff --git a/daemon/core/gui/app.py b/daemon/core/gui/app.py index dba22068..72e74e2b 100644 --- a/daemon/core/gui/app.py +++ b/daemon/core/gui/app.py @@ -1,5 +1,6 @@ import tkinter as tk from tkinter import ttk +from typing import Optional from core.gui import appconfig, themes from core.gui.coreclient import CoreClient @@ -17,7 +18,7 @@ HEIGHT = 800 class Application(tk.Frame): - def __init__(self, master=None): + def __init__(self, master: Optional[tk.Widget] = None): super().__init__(master) # load node icons NodeUtils.setup() diff --git a/daemon/core/gui/dialogs/about.py b/daemon/core/gui/dialogs/about.py index d54266f4..5e6b5d56 100644 --- a/daemon/core/gui/dialogs/about.py +++ b/daemon/core/gui/dialogs/about.py @@ -1,9 +1,13 @@ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui.dialogs.dialog import Dialog from core.gui.widgets import CodeText +if TYPE_CHECKING: + from core.gui.app import Application + LICENSE = """\ Copyright (c) 2005-2020, the Boeing Company. @@ -31,7 +35,7 @@ THE POSSIBILITY OF SUCH DAMAGE.\ class AboutDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master: tk.Widget, app: "Application"): super().__init__(master, app, "About CORE", modal=True) self.draw() diff --git a/daemon/core/gui/dialogs/alerts.py b/daemon/core/gui/dialogs/alerts.py index 38de8d38..57596f4b 100644 --- a/daemon/core/gui/dialogs/alerts.py +++ b/daemon/core/gui/dialogs/alerts.py @@ -3,15 +3,19 @@ check engine light """ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.api.grpc.core_pb2 import ExceptionLevel from core.gui.dialogs.dialog import Dialog from core.gui.themes import PADX, PADY from core.gui.widgets import CodeText +if TYPE_CHECKING: + from core.gui.app import Application + class AlertsDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master: tk.Widget, app: "Application"): super().__init__(master, app, "Alerts", modal=True) self.app = app self.tree = None diff --git a/daemon/core/gui/dialogs/canvassizeandscale.py b/daemon/core/gui/dialogs/canvassizeandscale.py index b48f6296..f04b991c 100644 --- a/daemon/core/gui/dialogs/canvassizeandscale.py +++ b/daemon/core/gui/dialogs/canvassizeandscale.py @@ -3,15 +3,19 @@ size and scale """ import tkinter as tk from tkinter import font, ttk +from typing import TYPE_CHECKING from core.gui.dialogs.dialog import Dialog from core.gui.themes import FRAME_PAD, PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + PIXEL_SCALE = 100 class SizeAndScaleDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master: "Application", app: "Application"): """ create an instance for size and scale object """ diff --git a/daemon/core/gui/dialogs/canvaswallpaper.py b/daemon/core/gui/dialogs/canvaswallpaper.py index 14e9ad26..3f79d50b 100644 --- a/daemon/core/gui/dialogs/canvaswallpaper.py +++ b/daemon/core/gui/dialogs/canvaswallpaper.py @@ -4,6 +4,7 @@ set wallpaper import logging import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui.appconfig import BACKGROUNDS_PATH from core.gui.dialogs.dialog import Dialog @@ -11,9 +12,12 @@ from core.gui.images import Images from core.gui.themes import PADX, PADY from core.gui.widgets import image_chooser +if TYPE_CHECKING: + from core.gui.app import Application + class CanvasWallpaperDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master: tk.Widget, app: "Application"): """ create an instance of CanvasWallpaper object diff --git a/daemon/core/gui/dialogs/colorpicker.py b/daemon/core/gui/dialogs/colorpicker.py index cf24054d..32e0f64b 100644 --- a/daemon/core/gui/dialogs/colorpicker.py +++ b/daemon/core/gui/dialogs/colorpicker.py @@ -4,12 +4,21 @@ custom color picker import logging import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING, Optional from core.gui.dialogs.dialog import Dialog +if TYPE_CHECKING: + from core.gui.app import Application + class ColorPickerDialog(Dialog): - def __init__(self, master, app, initcolor="#000000"): + def __init__( + self, + master: tk.Widget, + app: "Application", + initcolor: Optional[str] = "#000000", + ): super().__init__(master, app, "color picker", modal=True) self.red_entry = None self.blue_entry = None diff --git a/daemon/core/gui/dialogs/copyserviceconfig.py b/daemon/core/gui/dialogs/copyserviceconfig.py index 39c40ef2..207514d5 100644 --- a/daemon/core/gui/dialogs/copyserviceconfig.py +++ b/daemon/core/gui/dialogs/copyserviceconfig.py @@ -5,15 +5,19 @@ copy service config dialog import logging import tkinter as tk from tkinter import ttk -from typing import Tuple +from typing import TYPE_CHECKING, Tuple from core.gui.dialogs.dialog import Dialog from core.gui.themes import FRAME_PAD, PADX from core.gui.widgets import CodeText +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.dialogs.serviceconfig import ServiceConfigDialog + class CopyServiceConfigDialog(Dialog): - def __init__(self, master, app, node_id): + def __init__(self, master: "ServiceConfigDialog", app: "Application", node_id: int): super().__init__(master, app, f"Copy services to node {node_id}", modal=True) self.parent = master self.app = app diff --git a/daemon/core/gui/dialogs/customnodes.py b/daemon/core/gui/dialogs/customnodes.py index 1bf2a158..ba786491 100644 --- a/daemon/core/gui/dialogs/customnodes.py +++ b/daemon/core/gui/dialogs/customnodes.py @@ -2,6 +2,7 @@ import logging import tkinter as tk from pathlib import Path from tkinter import ttk +from typing import TYPE_CHECKING, Set from core.gui import nodeutils from core.gui.appconfig import ICONS_PATH @@ -11,9 +12,12 @@ from core.gui.nodeutils import NodeDraw from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.widgets import CheckboxList, ListboxScroll, image_chooser +if TYPE_CHECKING: + from core.gui.app import Application + class ServicesSelectDialog(Dialog): - def __init__(self, master, app, current_services): + def __init__(self, master, app: "Application", current_services: Set[str]): super().__init__(master, app, "Node Services", modal=True) self.groups = None self.services = None @@ -96,7 +100,7 @@ class ServicesSelectDialog(Dialog): class CustomNodesDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Custom Nodes", modal=True) self.edit_button = None self.delete_button = None diff --git a/daemon/core/gui/dialogs/dialog.py b/daemon/core/gui/dialogs/dialog.py index c392ba04..c349f898 100644 --- a/daemon/core/gui/dialogs/dialog.py +++ b/daemon/core/gui/dialogs/dialog.py @@ -1,13 +1,22 @@ import tkinter as tk from tkinter import ttk -from typing import Optional +from typing import TYPE_CHECKING, Optional from core.gui.images import ImageEnum, Images from core.gui.themes import DIALOG_PAD +if TYPE_CHECKING: + from core.gui.app import Application + class Dialog(tk.Toplevel): - def __init__(self, master, app, title, modal=False): + def __init__( + self, + master: tk.Widget, + app: "Application", + title: str, + modal: Optional[bool] = False, + ): super().__init__(master) self.withdraw() self.app = app diff --git a/daemon/core/gui/dialogs/emaneconfig.py b/daemon/core/gui/dialogs/emaneconfig.py index 29bb4f74..b7c99f02 100644 --- a/daemon/core/gui/dialogs/emaneconfig.py +++ b/daemon/core/gui/dialogs/emaneconfig.py @@ -5,18 +5,24 @@ import logging import tkinter as tk import webbrowser from tkinter import ttk +from typing import TYPE_CHECKING, Optional import grpc +from core.api.grpc import core_pb2 from core.gui.dialogs.dialog import Dialog from core.gui.errors import show_grpc_error from core.gui.images import ImageEnum, Images from core.gui.themes import PADX, PADY from core.gui.widgets import ConfigFrame +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + class GlobalEmaneDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "EMANE Configuration", modal=True) self.config_frame = None self.draw() @@ -47,7 +53,14 @@ class GlobalEmaneDialog(Dialog): class EmaneModelDialog(Dialog): - def __init__(self, master, app, node, model, interface=None): + def __init__( + self, + master, + app: "Application", + node: core_pb2.Node, + model: str, + interface: Optional[int] = None, + ): super().__init__(master, app, f"{node.name} {model} Configuration", modal=True) self.node = node self.model = f"emane_{model}" @@ -91,7 +104,7 @@ class EmaneModelDialog(Dialog): class EmaneConfigDialog(Dialog): - def __init__(self, master, app, canvas_node): + def __init__(self, master, app: "Application", canvas_node: "CanvasNode"): super().__init__( master, app, f"{canvas_node.core_node.name} EMANE Configuration", modal=True ) diff --git a/daemon/core/gui/dialogs/hooks.py b/daemon/core/gui/dialogs/hooks.py index 97b58c3b..ec74c525 100644 --- a/daemon/core/gui/dialogs/hooks.py +++ b/daemon/core/gui/dialogs/hooks.py @@ -1,14 +1,18 @@ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.api.grpc import core_pb2 from core.gui.dialogs.dialog import Dialog from core.gui.themes import PADX, PADY from core.gui.widgets import CodeText, ListboxScroll +if TYPE_CHECKING: + from core.gui.app import Application + class HookDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Hook", modal=True) self.name = tk.StringVar() self.codetext = None @@ -84,7 +88,7 @@ class HookDialog(Dialog): class HooksDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Hooks", modal=True) self.listbox = None self.edit_button = None diff --git a/daemon/core/gui/dialogs/linkconfig.py b/daemon/core/gui/dialogs/linkconfig.py index 4c6960a8..e7411182 100644 --- a/daemon/core/gui/dialogs/linkconfig.py +++ b/daemon/core/gui/dialogs/linkconfig.py @@ -4,13 +4,17 @@ link configuration import logging import tkinter as tk from tkinter import ttk -from typing import Union +from typing import TYPE_CHECKING, Union from core.api.grpc import core_pb2 from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.dialog import Dialog from core.gui.themes import PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.edges import CanvasEdge + def get_int(var: tk.StringVar) -> Union[int, None]: value = var.get() @@ -20,7 +24,7 @@ def get_int(var: tk.StringVar) -> Union[int, None]: return None -def get_float(var: tk.StringVar) -> Union[int, None]: +def get_float(var: tk.StringVar) -> Union[float, None]: value = var.get() if value != "": return float(value) @@ -29,7 +33,7 @@ def get_float(var: tk.StringVar) -> Union[int, None]: class LinkConfigurationDialog(Dialog): - def __init__(self, master, app, edge): + def __init__(self, master, app: "Application", edge: "CanvasEdge"): super().__init__(master, app, "Link Configuration", modal=True) self.app = app self.edge = edge diff --git a/daemon/core/gui/dialogs/marker.py b/daemon/core/gui/dialogs/marker.py index 6cc8d9c3..2f2ed100 100644 --- a/daemon/core/gui/dialogs/marker.py +++ b/daemon/core/gui/dialogs/marker.py @@ -4,15 +4,21 @@ marker dialog import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING, Optional from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.dialog import Dialog +if TYPE_CHECKING: + from core.gui.app import Application + MARKER_THICKNESS = [3, 5, 8, 10] class MarkerDialog(Dialog): - def __init__(self, master, app, initcolor="#000000"): + def __init__( + self, master, app: "Application", initcolor: Optional[str] = "#000000" + ): super().__init__(master, app, "marker tool", modal=False) self.app = app self.color = initcolor diff --git a/daemon/core/gui/dialogs/mobilityconfig.py b/daemon/core/gui/dialogs/mobilityconfig.py index 3b9c1ca6..91601ae5 100644 --- a/daemon/core/gui/dialogs/mobilityconfig.py +++ b/daemon/core/gui/dialogs/mobilityconfig.py @@ -2,6 +2,7 @@ mobility configuration """ from tkinter import ttk +from typing import TYPE_CHECKING import grpc @@ -10,9 +11,13 @@ from core.gui.errors import show_grpc_error from core.gui.themes import PADX, PADY from core.gui.widgets import ConfigFrame +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + class MobilityConfigDialog(Dialog): - def __init__(self, master, app, canvas_node): + def __init__(self, master, app: "Application", canvas_node: "CanvasNode"): super().__init__( master, app, diff --git a/daemon/core/gui/dialogs/mobilityplayer.py b/daemon/core/gui/dialogs/mobilityplayer.py index 9c2848d8..cf9a46a8 100644 --- a/daemon/core/gui/dialogs/mobilityplayer.py +++ b/daemon/core/gui/dialogs/mobilityplayer.py @@ -1,5 +1,6 @@ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING import grpc @@ -9,11 +10,15 @@ from core.gui.errors import show_grpc_error from core.gui.images import ImageEnum, Images from core.gui.themes import PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + ICON_SIZE = 16 class MobilityPlayer: - def __init__(self, master, app, canvas_node, config): + def __init__(self, master, app: "Application", canvas_node: "CanvasNode", config): self.master = master self.app = app self.canvas_node = canvas_node diff --git a/daemon/core/gui/dialogs/nodeconfig.py b/daemon/core/gui/dialogs/nodeconfig.py index 030099e6..4f17b499 100644 --- a/daemon/core/gui/dialogs/nodeconfig.py +++ b/daemon/core/gui/dialogs/nodeconfig.py @@ -2,6 +2,7 @@ import logging import tkinter as tk from functools import partial from tkinter import ttk +from typing import TYPE_CHECKING from core.gui import nodeutils from core.gui.appconfig import ICONS_PATH @@ -12,6 +13,10 @@ from core.gui.nodeutils import NodeUtils from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.widgets import ListboxScroll, image_chooser +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + def mac_auto(is_auto, entry: ttk.Entry): logging.info("mac auto clicked") @@ -33,7 +38,7 @@ class InterfaceData: class NodeConfigDialog(Dialog): - def __init__(self, master, app, canvas_node): + def __init__(self, master, app: "Application", canvas_node: "CanvasNode"): """ create an instance of node configuration diff --git a/daemon/core/gui/dialogs/nodeservice.py b/daemon/core/gui/dialogs/nodeservice.py index d7eec1fe..768182af 100644 --- a/daemon/core/gui/dialogs/nodeservice.py +++ b/daemon/core/gui/dialogs/nodeservice.py @@ -3,15 +3,22 @@ core node services """ import tkinter as tk from tkinter import messagebox, ttk +from typing import TYPE_CHECKING from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.serviceconfig import ServiceConfigDialog from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.widgets import CheckboxList, ListboxScroll +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + class NodeServiceDialog(Dialog): - def __init__(self, master, app, canvas_node, services=None): + def __init__( + self, master, app: "Application", canvas_node: "CanvasNode", services=None + ): title = f"{canvas_node.core_node.name} Services" super().__init__(master, app, title, modal=True) self.app = app diff --git a/daemon/core/gui/dialogs/observers.py b/daemon/core/gui/dialogs/observers.py index 2a3b8e43..bc244f5c 100644 --- a/daemon/core/gui/dialogs/observers.py +++ b/daemon/core/gui/dialogs/observers.py @@ -1,14 +1,18 @@ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui.coreclient import Observer from core.gui.dialogs.dialog import Dialog from core.gui.themes import PADX, PADY from core.gui.widgets import ListboxScroll +if TYPE_CHECKING: + from core.gui.app import Application + class ObserverDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Observer Widgets", modal=True) self.observers = None self.save_button = None diff --git a/daemon/core/gui/dialogs/preferences.py b/daemon/core/gui/dialogs/preferences.py index 614b149e..102d49fe 100644 --- a/daemon/core/gui/dialogs/preferences.py +++ b/daemon/core/gui/dialogs/preferences.py @@ -1,14 +1,18 @@ import logging import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui import appconfig from core.gui.dialogs.dialog import Dialog from core.gui.themes import FRAME_PAD, PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + class PreferencesDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Preferences", modal=True) preferences = self.app.guiconfig["preferences"] self.editor = tk.StringVar(value=preferences["editor"]) diff --git a/daemon/core/gui/dialogs/servers.py b/daemon/core/gui/dialogs/servers.py index 30495d5a..8d46e6de 100644 --- a/daemon/core/gui/dialogs/servers.py +++ b/daemon/core/gui/dialogs/servers.py @@ -1,18 +1,22 @@ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui.coreclient import CoreServer from core.gui.dialogs.dialog import Dialog from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.widgets import ListboxScroll +if TYPE_CHECKING: + from core.gui.app import Application + DEFAULT_NAME = "example" DEFAULT_ADDRESS = "127.0.0.1" DEFAULT_PORT = 50051 class ServersDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "CORE Servers", modal=True) self.name = tk.StringVar(value=DEFAULT_NAME) self.address = tk.StringVar(value=DEFAULT_ADDRESS) diff --git a/daemon/core/gui/dialogs/serviceconfig.py b/daemon/core/gui/dialogs/serviceconfig.py index 35d30033..7171e1a0 100644 --- a/daemon/core/gui/dialogs/serviceconfig.py +++ b/daemon/core/gui/dialogs/serviceconfig.py @@ -1,7 +1,7 @@ "Service configuration dialog" import tkinter as tk from tkinter import ttk -from typing import List +from typing import TYPE_CHECKING, List import grpc @@ -13,9 +13,12 @@ from core.gui.images import ImageEnum, Images from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.widgets import CodeText, ListboxScroll +if TYPE_CHECKING: + from core.gui.app import Application + class ServiceConfigDialog(Dialog): - def __init__(self, master, app, service_name, node_id): + def __init__(self, master, app: "Application", service_name: str, node_id: int): title = f"{service_name} Service" super().__init__(master, app, title, modal=True) self.master = master diff --git a/daemon/core/gui/dialogs/sessionoptions.py b/daemon/core/gui/dialogs/sessionoptions.py index 040629b5..f201674d 100644 --- a/daemon/core/gui/dialogs/sessionoptions.py +++ b/daemon/core/gui/dialogs/sessionoptions.py @@ -1,5 +1,6 @@ import logging from tkinter import ttk +from typing import TYPE_CHECKING import grpc @@ -8,9 +9,12 @@ from core.gui.errors import show_grpc_error from core.gui.themes import PADX, PADY from core.gui.widgets import ConfigFrame +if TYPE_CHECKING: + from core.gui.app import Application + class SessionOptionsDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Session Options", modal=True) self.config_frame = None self.config = self.get_config() diff --git a/daemon/core/gui/dialogs/sessions.py b/daemon/core/gui/dialogs/sessions.py index 6fa6e04b..d466356e 100644 --- a/daemon/core/gui/dialogs/sessions.py +++ b/daemon/core/gui/dialogs/sessions.py @@ -1,7 +1,7 @@ import logging import tkinter as tk from tkinter import ttk -from typing import Iterable +from typing import TYPE_CHECKING, Iterable import grpc @@ -12,9 +12,12 @@ from core.gui.images import ImageEnum, Images from core.gui.task import BackgroundTask from core.gui.themes import PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + class SessionsDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Sessions", modal=True) self.selected = False self.selected_id = None diff --git a/daemon/core/gui/dialogs/shapemod.py b/daemon/core/gui/dialogs/shapemod.py index ba799220..ccb9c70b 100644 --- a/daemon/core/gui/dialogs/shapemod.py +++ b/daemon/core/gui/dialogs/shapemod.py @@ -3,6 +3,7 @@ shape input dialog """ import tkinter as tk from tkinter import font, ttk +from typing import TYPE_CHECKING from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.dialog import Dialog @@ -10,12 +11,16 @@ from core.gui.graph import tags from core.gui.graph.shapeutils import is_draw_shape, is_shape_text from core.gui.themes import FRAME_PAD, PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.shape import Shape + FONT_SIZES = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] BORDER_WIDTH = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] class ShapeDialog(Dialog): - def __init__(self, master, app, shape): + def __init__(self, master, app: "Application", shape: "Shape"): if is_draw_shape(shape.shape_type): title = "Add Shape" else: @@ -180,8 +185,6 @@ class ShapeDialog(Dialog): def save_text(self): """ save info related to text or shape label - - :return: nothing """ data = self.shape.shape_data data.text = self.shape_text.get() @@ -195,8 +198,6 @@ class ShapeDialog(Dialog): def save_shape(self): """ save info related to shape - - :return: nothing """ data = self.shape.shape_data data.fill_color = self.fill_color @@ -206,8 +207,6 @@ class ShapeDialog(Dialog): def add_text(self): """ add text to canvas - - :return: nothing """ text = self.shape_text.get() text_font = self.make_font() diff --git a/daemon/core/gui/dialogs/throughput.py b/daemon/core/gui/dialogs/throughput.py index 150a3c5a..bb10531e 100644 --- a/daemon/core/gui/dialogs/throughput.py +++ b/daemon/core/gui/dialogs/throughput.py @@ -3,14 +3,18 @@ throughput dialog """ import tkinter as tk from tkinter import ttk +from typing import TYPE_CHECKING from core.gui.dialogs.colorpicker import ColorPickerDialog from core.gui.dialogs.dialog import Dialog from core.gui.themes import FRAME_PAD, PADX, PADY +if TYPE_CHECKING: + from core.gui.app import Application + class ThroughputDialog(Dialog): - def __init__(self, master, app): + def __init__(self, master, app: "Application"): super().__init__(master, app, "Throughput Config", modal=False) self.app = app self.canvas = app.canvas diff --git a/daemon/core/gui/dialogs/wlanconfig.py b/daemon/core/gui/dialogs/wlanconfig.py index 1d74e3c1..525dbc40 100644 --- a/daemon/core/gui/dialogs/wlanconfig.py +++ b/daemon/core/gui/dialogs/wlanconfig.py @@ -3,6 +3,7 @@ wlan configuration """ from tkinter import ttk +from typing import TYPE_CHECKING import grpc @@ -11,9 +12,13 @@ from core.gui.errors import show_grpc_error from core.gui.themes import PADX, PADY from core.gui.widgets import ConfigFrame +if TYPE_CHECKING: + from core.gui.app import Application + from core.gui.graph.node import CanvasNode + class WlanConfigDialog(Dialog): - def __init__(self, master, app, canvas_node): + def __init__(self, master, app: "Application", canvas_node: "CanvasNode"): super().__init__( master, app, f"{canvas_node.core_node.name} Wlan Configuration", modal=True ) diff --git a/daemon/core/gui/graph/node.py b/daemon/core/gui/graph/node.py index 191f6d5f..3602920a 100644 --- a/daemon/core/gui/graph/node.py +++ b/daemon/core/gui/graph/node.py @@ -1,5 +1,6 @@ import tkinter as tk from tkinter import font +from typing import TYPE_CHECKING import grpc @@ -16,11 +17,22 @@ from core.gui.graph import tags from core.gui.graph.tooltip import CanvasTooltip from core.gui.nodeutils import NodeUtils +if TYPE_CHECKING: + from core.gui.app import Application + from PIL.ImageTk import PhotoImage + NODE_TEXT_OFFSET = 5 class CanvasNode: - def __init__(self, app, x: float, y: float, core_node: core_pb2.Node, image): + def __init__( + self, + app: "Application", + x: float, + y: float, + core_node: core_pb2.Node, + image: "PhotoImage", + ): self.app = app self.canvas = app.canvas self.image = image diff --git a/daemon/core/gui/statusbar.py b/daemon/core/gui/statusbar.py index d0fac322..36fde4dc 100644 --- a/daemon/core/gui/statusbar.py +++ b/daemon/core/gui/statusbar.py @@ -9,7 +9,7 @@ from core.gui.themes import Styles class StatusBar(ttk.Frame): - def __init__(self, master, app, **kwargs): + def __init__(self, master: tk.Widget, app, **kwargs): super().__init__(master, **kwargs) self.app = app self.status = None diff --git a/daemon/core/gui/task.py b/daemon/core/gui/task.py index bf731dd4..dc2c1d34 100644 --- a/daemon/core/gui/task.py +++ b/daemon/core/gui/task.py @@ -1,9 +1,12 @@ import logging import threading +from typing import Callable, Optional class BackgroundTask: - def __init__(self, master, task, callback=None, args=()): + def __init__( + self, master, task: Callable, callback: Optional[Callable] = None, args=() + ): self.master = master self.args = args self.task = task diff --git a/daemon/core/gui/themes.py b/daemon/core/gui/themes.py index dbd02dbf..b8266a0e 100644 --- a/daemon/core/gui/themes.py +++ b/daemon/core/gui/themes.py @@ -147,7 +147,7 @@ def theme_change_menu(event: tk.Event): style_menu(event.widget) -def style_menu(widget: ttk.Widget): +def style_menu(widget: tk.Widget): style = ttk.Style() bg = style.lookup(".", "background") fg = style.lookup(".", "foreground") diff --git a/daemon/core/gui/toolbar.py b/daemon/core/gui/toolbar.py index a879eacc..827c2393 100644 --- a/daemon/core/gui/toolbar.py +++ b/daemon/core/gui/toolbar.py @@ -429,7 +429,7 @@ class Toolbar(ttk.Frame): if not response.result: messagebox.showerror("Stop Error", "Errors stopping session") - def update_annotation(self, image, shape_type: str): + def update_annotation(self, image: ImageTk.PhotoImage, shape_type: str): logging.info("clicked annotation: ") self.hide_pickers() self.annotation_button.configure(image=image) diff --git a/daemon/core/gui/widgets.py b/daemon/core/gui/widgets.py index dc395023..513ef0dc 100644 --- a/daemon/core/gui/widgets.py +++ b/daemon/core/gui/widgets.py @@ -195,7 +195,7 @@ class CheckboxList(FrameScroll): self.clicked = clicked self.frame.columnconfigure(0, weight=1) - def add(self, name, checked): + def add(self, name: str, checked: bool): var = tk.BooleanVar(value=checked) func = partial(self.clicked, name, var) checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func)