gui: updated core.gui to not use deprecated type hinting

This commit is contained in:
Blake Harnden 2023-04-13 15:53:16 -07:00
parent 69f05a6712
commit e7351b594d
40 changed files with 268 additions and 257 deletions

View file

@ -3,7 +3,7 @@ check engine light
"""
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
from core.api.grpc.wrappers import ExceptionEvent, ExceptionLevel
from core.gui.dialogs.dialog import Dialog
@ -19,7 +19,7 @@ class AlertsDialog(Dialog):
super().__init__(app, "Alerts")
self.tree: Optional[ttk.Treeview] = None
self.codetext: Optional[CodeText] = None
self.alarm_map: Dict[int, ExceptionEvent] = {}
self.alarm_map: dict[int, ExceptionEvent] = {}
self.draw()
def draw(self) -> None:

View file

@ -4,7 +4,7 @@ set wallpaper
import logging
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional
from core.gui import images
from core.gui.appconfig import BACKGROUNDS_PATH
@ -32,7 +32,7 @@ class CanvasWallpaperDialog(Dialog):
)
self.filename: tk.StringVar = tk.StringVar(value=self.canvas.wallpaper_file)
self.image_label: Optional[ttk.Label] = None
self.options: List[ttk.Radiobutton] = []
self.options: list[ttk.Radiobutton] = []
self.draw()
def draw(self) -> None:

View file

@ -3,7 +3,7 @@ custom color picker
"""
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Optional, Tuple
from typing import TYPE_CHECKING, Optional
from core.gui import validation
from core.gui.dialogs.dialog import Dialog
@ -66,7 +66,9 @@ class ColorPickerDialog(Dialog):
)
scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX)
self.red_label = ttk.Label(
frame, background="#%02x%02x%02x" % (self.red.get(), 0, 0), width=5
frame,
background="#{:02x}{:02x}{:02x}".format(self.red.get(), 0, 0),
width=5,
)
self.red_label.grid(row=0, column=3, sticky=tk.EW)
@ -89,7 +91,9 @@ class ColorPickerDialog(Dialog):
)
scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX)
self.green_label = ttk.Label(
frame, background="#%02x%02x%02x" % (0, self.green.get(), 0), width=5
frame,
background="#{:02x}{:02x}{:02x}".format(0, self.green.get(), 0),
width=5,
)
self.green_label.grid(row=0, column=3, sticky=tk.EW)
@ -112,7 +116,9 @@ class ColorPickerDialog(Dialog):
)
scale.grid(row=0, column=2, sticky=tk.EW, padx=PADX)
self.blue_label = ttk.Label(
frame, background="#%02x%02x%02x" % (0, 0, self.blue.get()), width=5
frame,
background="#{:02x}{:02x}{:02x}".format(0, 0, self.blue.get()),
width=5,
)
self.blue_label.grid(row=0, column=3, sticky=tk.EW)
@ -157,7 +163,7 @@ class ColorPickerDialog(Dialog):
red = self.red_entry.get()
blue = self.blue_entry.get()
green = self.green_entry.get()
return "#%02x%02x%02x" % (int(red), int(green), int(blue))
return "#{:02x}{:02x}{:02x}".format(int(red), int(green), int(blue))
def current_focus(self, focus: str) -> None:
self.focus = focus
@ -169,7 +175,7 @@ class ColorPickerDialog(Dialog):
green = self.green_entry.get()
self.set_scale(red, green, blue)
if red and blue and green:
hex_code = "#%02x%02x%02x" % (int(red), int(green), int(blue))
hex_code = "#{:02x}{:02x}{:02x}".format(int(red), int(green), int(blue))
self.hex.set(hex_code)
self.display.config(background=hex_code)
self.set_label(red, green, blue)
@ -200,11 +206,17 @@ class ColorPickerDialog(Dialog):
self.blue.set(blue)
def set_label(self, red: str, green: str, blue: str) -> None:
self.red_label.configure(background="#%02x%02x%02x" % (int(red), 0, 0))
self.green_label.configure(background="#%02x%02x%02x" % (0, int(green), 0))
self.blue_label.configure(background="#%02x%02x%02x" % (0, 0, int(blue)))
self.red_label.configure(
background="#{:02x}{:02x}{:02x}".format(int(red), 0, 0)
)
self.green_label.configure(
background="#{:02x}{:02x}{:02x}".format(0, int(green), 0)
)
self.blue_label.configure(
background="#{:02x}{:02x}{:02x}".format(0, 0, int(blue))
)
def get_rgb(self, hex_code: str) -> Tuple[int, int, int]:
def get_rgb(self, hex_code: str) -> tuple[int, int, int]:
"""
convert a valid hex code to RGB values
"""

View file

@ -4,7 +4,7 @@ Service configuration dialog
import logging
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, List, Optional, Set
from typing import TYPE_CHECKING, Optional
import grpc
@ -35,22 +35,22 @@ class ConfigServiceConfigDialog(Dialog):
self.node: Node = node
self.service_name: str = service_name
self.radiovar: tk.IntVar = tk.IntVar(value=2)
self.directories: List[str] = []
self.templates: List[str] = []
self.rendered: Dict[str, str] = {}
self.dependencies: List[str] = []
self.executables: List[str] = []
self.startup_commands: List[str] = []
self.validation_commands: List[str] = []
self.shutdown_commands: List[str] = []
self.default_startup: List[str] = []
self.default_validate: List[str] = []
self.default_shutdown: List[str] = []
self.directories: list[str] = []
self.templates: list[str] = []
self.rendered: dict[str, str] = {}
self.dependencies: list[str] = []
self.executables: list[str] = []
self.startup_commands: list[str] = []
self.validation_commands: list[str] = []
self.shutdown_commands: list[str] = []
self.default_startup: list[str] = []
self.default_validate: list[str] = []
self.default_shutdown: list[str] = []
self.validation_mode: Optional[ServiceValidationMode] = None
self.validation_time: Optional[int] = None
self.validation_period: tk.DoubleVar = tk.DoubleVar()
self.modes: List[str] = []
self.mode_configs: Dict[str, Dict[str, str]] = {}
self.modes: list[str] = []
self.mode_configs: dict[str, dict[str, str]] = {}
self.notebook: Optional[ttk.Notebook] = None
self.templates_combobox: Optional[ttk.Combobox] = None
self.modes_combobox: Optional[ttk.Combobox] = None
@ -62,12 +62,12 @@ class ConfigServiceConfigDialog(Dialog):
self.template_text: Optional[CodeText] = None
self.rendered_text: Optional[CodeText] = None
self.validation_period_entry: Optional[ttk.Entry] = None
self.original_service_files: Dict[str, str] = {}
self.temp_service_files: Dict[str, str] = {}
self.modified_files: Set[str] = set()
self.original_service_files: dict[str, str] = {}
self.temp_service_files: dict[str, str] = {}
self.modified_files: set[str] = set()
self.config_frame: Optional[ConfigFrame] = None
self.default_config: Dict[str, str] = {}
self.config: Dict[str, ConfigOption] = {}
self.default_config: dict[str, str] = {}
self.config: dict[str, ConfigOption] = {}
self.has_error: bool = False
self.load()
if not self.has_error:
@ -405,7 +405,7 @@ class ConfigServiceConfigDialog(Dialog):
pass
def append_commands(
self, commands: List[str], listbox: tk.Listbox, to_add: List[str]
self, commands: list[str], listbox: tk.Listbox, to_add: list[str]
) -> None:
for cmd in to_add:
commands.append(cmd)

View file

@ -4,7 +4,7 @@ copy service config dialog
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
from core.gui.dialogs.dialog import Dialog
from core.gui.themes import PADX, PADY
@ -29,7 +29,7 @@ class CopyServiceConfigDialog(Dialog):
self.service: str = service
self.file_name: str = file_name
self.listbox: Optional[tk.Listbox] = None
self.nodes: Dict[str, int] = {}
self.nodes: dict[str, int] = {}
self.draw()
def draw(self) -> None:

View file

@ -2,7 +2,7 @@ import logging
import tkinter as tk
from pathlib import Path
from tkinter import ttk
from typing import TYPE_CHECKING, Optional, Set
from typing import TYPE_CHECKING, Optional
from PIL.ImageTk import PhotoImage
@ -21,13 +21,13 @@ if TYPE_CHECKING:
class ServicesSelectDialog(Dialog):
def __init__(
self, master: tk.BaseWidget, app: "Application", current_services: Set[str]
self, master: tk.BaseWidget, app: "Application", current_services: set[str]
) -> None:
super().__init__(app, "Node Config Services", master=master)
self.groups: Optional[ListboxScroll] = None
self.services: Optional[CheckboxList] = None
self.current: Optional[ListboxScroll] = None
self.current_services: Set[str] = current_services
self.current_services: set[str] = current_services
self.draw()
def draw(self) -> None:
@ -114,7 +114,7 @@ class CustomNodesDialog(Dialog):
self.image_button: Optional[ttk.Button] = None
self.image: Optional[PhotoImage] = None
self.image_file: Optional[str] = None
self.services: Set[str] = set()
self.services: set[str] = set()
self.selected: Optional[str] = None
self.selected_index: Optional[int] = None
self.draw()

View file

@ -4,7 +4,7 @@ emane configuration
import tkinter as tk
import webbrowser
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Optional
import grpc
@ -43,7 +43,7 @@ class EmaneModelDialog(Dialog):
config = self.app.core.get_emane_model_config(
self.node.id, self.model, self.iface_id
)
self.config: Dict[str, ConfigOption] = config
self.config: dict[str, ConfigOption] = config
self.draw()
except grpc.RpcError as e:
self.app.show_grpc_exception("Get EMANE Config Error", e)
@ -82,7 +82,7 @@ class EmaneConfigDialog(Dialog):
self.node: Node = node
self.radiovar: tk.IntVar = tk.IntVar()
self.radiovar.set(1)
self.emane_models: List[str] = [
self.emane_models: list[str] = [
x.split("_")[1] for x in self.app.core.emane_models
]
model = self.node.emane.split("_")[1]

View file

@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import messagebox, ttk
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional
import netaddr
@ -17,8 +17,8 @@ class IpConfigDialog(Dialog):
super().__init__(app, "IP Configuration")
self.ip4: str = self.app.guiconfig.ips.ip4
self.ip6: str = self.app.guiconfig.ips.ip6
self.ip4s: List[str] = self.app.guiconfig.ips.ip4s
self.ip6s: List[str] = self.app.guiconfig.ips.ip6s
self.ip4s: list[str] = self.app.guiconfig.ips.ip4s
self.ip6s: list[str] = self.app.guiconfig.ips.ip6s
self.ip4_entry: Optional[ttk.Entry] = None
self.ip4_listbox: Optional[ListboxScroll] = None
self.ip6_entry: Optional[ttk.Entry] = None

View file

@ -3,7 +3,7 @@ mobility configuration
"""
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
import grpc
@ -26,7 +26,7 @@ class MobilityConfigDialog(Dialog):
config = self.node.mobility_config
if not config:
config = self.app.core.get_mobility_config(self.node.id)
self.config: Dict[str, ConfigOption] = config
self.config: dict[str, ConfigOption] = config
self.draw()
except grpc.RpcError as e:
self.app.show_grpc_exception("Get Mobility Config Error", e)

View file

@ -2,7 +2,7 @@ import logging
import tkinter as tk
from functools import partial
from tkinter import messagebox, ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
import netaddr
from PIL.ImageTk import PhotoImage
@ -190,7 +190,7 @@ class NodeConfigDialog(Dialog):
if self.node.server:
server = self.node.server
self.server: tk.StringVar = tk.StringVar(value=server)
self.ifaces: Dict[int, InterfaceData] = {}
self.ifaces: dict[int, InterfaceData] = {}
self.draw()
def draw(self) -> None:

View file

@ -4,7 +4,7 @@ core node services
import logging
import tkinter as tk
from tkinter import messagebox, ttk
from typing import TYPE_CHECKING, Optional, Set
from typing import TYPE_CHECKING, Optional
from core.api.grpc.wrappers import Node
from core.gui.dialogs.configserviceconfig import ConfigServiceConfigDialog
@ -20,7 +20,7 @@ if TYPE_CHECKING:
class NodeConfigServiceDialog(Dialog):
def __init__(
self, app: "Application", node: Node, services: Set[str] = None
self, app: "Application", node: Node, services: set[str] = None
) -> None:
title = f"{node.name} Config Services"
super().__init__(app, title)
@ -30,7 +30,7 @@ class NodeConfigServiceDialog(Dialog):
self.current: Optional[ListboxScroll] = None
if services is None:
services = set(node.config_services)
self.current_services: Set[str] = services
self.current_services: set[str] = services
self.protocol("WM_DELETE_WINDOW", self.click_cancel)
self.draw()

View file

@ -3,7 +3,7 @@ core node services
"""
import tkinter as tk
from tkinter import messagebox, ttk
from typing import TYPE_CHECKING, Optional, Set
from typing import TYPE_CHECKING, Optional
from core.api.grpc.wrappers import Node
from core.gui.dialogs.dialog import Dialog
@ -24,7 +24,7 @@ class NodeServiceDialog(Dialog):
self.services: Optional[CheckboxList] = None
self.current: Optional[ListboxScroll] = None
services = set(node.services)
self.current_services: Set[str] = services
self.current_services: set[str] = services
self.protocol("WM_DELETE_WINDOW", self.click_cancel)
self.draw()

View file

@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
from core.gui import nodeutils as nutils
from core.gui.dialogs.dialog import Dialog
@ -17,7 +17,7 @@ class RunToolDialog(Dialog):
self.cmd: tk.StringVar = tk.StringVar(value="ps ax")
self.result: Optional[CodeText] = None
self.node_list: Optional[ListboxScroll] = None
self.executable_nodes: Dict[str, int] = {}
self.executable_nodes: dict[str, int] = {}
self.store_nodes()
self.draw()

View file

@ -2,7 +2,7 @@ import logging
import tkinter as tk
from pathlib import Path
from tkinter import filedialog, messagebox, ttk
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple
from typing import TYPE_CHECKING, Optional
import grpc
from PIL.ImageTk import PhotoImage
@ -35,21 +35,21 @@ class ServiceConfigDialog(Dialog):
self.service_name: str = service_name
self.radiovar: tk.IntVar = tk.IntVar(value=2)
self.metadata: str = ""
self.filenames: List[str] = []
self.dependencies: List[str] = []
self.executables: List[str] = []
self.startup_commands: List[str] = []
self.validation_commands: List[str] = []
self.shutdown_commands: List[str] = []
self.default_startup: List[str] = []
self.default_validate: List[str] = []
self.default_shutdown: List[str] = []
self.filenames: list[str] = []
self.dependencies: list[str] = []
self.executables: list[str] = []
self.startup_commands: list[str] = []
self.validation_commands: list[str] = []
self.shutdown_commands: list[str] = []
self.default_startup: list[str] = []
self.default_validate: list[str] = []
self.default_shutdown: list[str] = []
self.validation_mode: Optional[ServiceValidationMode] = None
self.validation_time: Optional[int] = None
self.validation_period: Optional[float] = None
self.directory_entry: Optional[ttk.Entry] = None
self.default_directories: List[str] = []
self.temp_directories: List[str] = []
self.default_directories: list[str] = []
self.temp_directories: list[str] = []
self.documentnew_img: PhotoImage = self.app.get_enum_icon(
ImageEnum.DOCUMENTNEW, width=ICON_SIZE
)
@ -67,10 +67,10 @@ class ServiceConfigDialog(Dialog):
self.validation_mode_entry: Optional[ttk.Entry] = None
self.service_file_data: Optional[CodeText] = None
self.validation_period_entry: Optional[ttk.Entry] = None
self.original_service_files: Dict[str, str] = {}
self.original_service_files: dict[str, str] = {}
self.default_config: Optional[NodeServiceData] = None
self.temp_service_files: Dict[str, str] = {}
self.modified_files: Set[str] = set()
self.temp_service_files: dict[str, str] = {}
self.modified_files: set[str] = set()
self.has_error: bool = False
self.load()
if not self.has_error:
@ -558,13 +558,13 @@ class ServiceConfigDialog(Dialog):
@classmethod
def append_commands(
cls, commands: List[str], listbox: tk.Listbox, to_add: List[str]
cls, commands: list[str], listbox: tk.Listbox, to_add: list[str]
) -> None:
for cmd in to_add:
commands.append(cmd)
listbox.insert(tk.END, cmd)
def get_commands(self) -> Tuple[List[str], List[str], List[str]]:
def get_commands(self) -> tuple[list[str], list[str], list[str]]:
startup = self.startup_commands_listbox.get(0, "end")
shutdown = self.shutdown_commands_listbox.get(0, "end")
validate = self.validate_commands_listbox.get(0, "end")

View file

@ -1,7 +1,7 @@
import logging
import tkinter as tk
from tkinter import messagebox, ttk
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional
import grpc
@ -30,7 +30,7 @@ class SessionsDialog(Dialog):
self.protocol("WM_DELETE_WINDOW", self.on_closing)
self.draw()
def get_sessions(self) -> List[SessionSummary]:
def get_sessions(self) -> list[SessionSummary]:
try:
sessions = self.app.core.client.get_sessions()
logger.info("sessions: %s", sessions)

View file

@ -3,7 +3,7 @@ shape input dialog
"""
import tkinter as tk
from tkinter import font, ttk
from typing import TYPE_CHECKING, List, Optional, Union
from typing import TYPE_CHECKING, Optional, Union
from core.gui.dialogs.colorpicker import ColorPickerDialog
from core.gui.dialogs.dialog import Dialog
@ -16,8 +16,8 @@ if TYPE_CHECKING:
from core.gui.graph.graph import CanvasGraph
from core.gui.graph.shape import Shape
FONT_SIZES: List[int] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
BORDER_WIDTH: List[int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
FONT_SIZES: list[int] = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
BORDER_WIDTH: list[int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
class ShapeDialog(Dialog):
@ -168,7 +168,7 @@ class ShapeDialog(Dialog):
self.add_text()
self.destroy()
def make_font(self) -> List[Union[int, str]]:
def make_font(self) -> list[Union[int, str]]:
"""
create font for text or shape label
"""

View file

@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
import grpc
@ -19,12 +19,12 @@ class WirelessConfigDialog(Dialog):
super().__init__(app, f"Wireless Configuration - {canvas_node.core_node.name}")
self.node: Node = canvas_node.core_node
self.config_frame: Optional[ConfigFrame] = None
self.config: Dict[str, ConfigOption] = {}
self.config: dict[str, ConfigOption] = {}
try:
config = self.node.wireless_config
if not config:
config = self.app.core.get_wireless_config(self.node.id)
self.config: Dict[str, ConfigOption] = config
self.config: dict[str, ConfigOption] = config
self.draw()
except grpc.RpcError as e:
self.app.show_grpc_exception("Wireless Config Error", e)

View file

@ -1,6 +1,6 @@
import tkinter as tk
from tkinter import ttk
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional
import grpc
@ -27,13 +27,13 @@ class WlanConfigDialog(Dialog):
self.config_frame: Optional[ConfigFrame] = None
self.range_entry: Optional[ttk.Entry] = None
self.has_error: bool = False
self.ranges: Dict[int, int] = {}
self.ranges: dict[int, int] = {}
self.positive_int: int = self.app.master.register(self.validate_and_update)
try:
config = self.node.wlan_config
if not config:
config = self.app.core.get_wlan_config(self.node.id)
self.config: Dict[str, ConfigOption] = config
self.config: dict[str, ConfigOption] = config
self.init_draw_range()
self.draw()
except grpc.RpcError as e: