pygui some cleanup for dialog constructors to avoid passing duplicate parameters in most cases

This commit is contained in:
Blake Harnden 2020-05-04 22:50:59 -07:00
parent 185c6736b3
commit 1d620a0b17
42 changed files with 143 additions and 209 deletions

View file

@ -134,7 +134,7 @@ class Application(ttk.Frame):
self.show_error(title, str(e)) self.show_error(title, str(e))
def show_error(self, title: str, message: str) -> None: def show_error(self, title: str, message: str) -> None:
self.after(0, lambda: ErrorDialog(self, self, title, message).show()) self.after(0, lambda: ErrorDialog(self, title, message).show())
def on_closing(self): def on_closing(self):
self.menubar.prompt_save_running_session(True) self.menubar.prompt_save_running_session(True)

View file

@ -467,11 +467,11 @@ class CoreClient:
if len(sessions) == 0: if len(sessions) == 0:
self.create_new_session() self.create_new_session()
else: else:
dialog = SessionsDialog(self.app, self.app, True) dialog = SessionsDialog(self.app, True)
dialog.show() dialog.show()
except grpc.RpcError as e: except grpc.RpcError as e:
logging.exception("core setup error") logging.exception("core setup error")
dialog = ErrorDialog(self.app, self.app, "Setup Error", e.details()) dialog = ErrorDialog(self.app, "Setup Error", e.details())
dialog.show() dialog.show()
self.app.close() self.app.close()

View file

@ -35,8 +35,8 @@ THE POSSIBILITY OF SUCH DAMAGE.\
class AboutDialog(Dialog): class AboutDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "About CORE") super().__init__(app, "About CORE")
self.draw() self.draw()
def draw(self): def draw(self):

View file

@ -15,9 +15,8 @@ if TYPE_CHECKING:
class AlertsDialog(Dialog): class AlertsDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Alerts") super().__init__(app, "Alerts")
self.app = app
self.tree = None self.tree = None
self.codetext = None self.codetext = None
self.alarm_map = {} self.alarm_map = {}
@ -93,16 +92,10 @@ class AlertsDialog(Dialog):
frame.grid(sticky="ew") frame.grid(sticky="ew")
frame.columnconfigure(0, weight=1) frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1) frame.columnconfigure(1, weight=1)
frame.columnconfigure(2, weight=1)
frame.columnconfigure(3, weight=1)
button = ttk.Button(frame, text="Reset", command=self.reset_alerts) button = ttk.Button(frame, text="Reset", command=self.reset_alerts)
button.grid(row=0, column=0, sticky="ew", padx=PADX) button.grid(row=0, column=0, sticky="ew", padx=PADX)
button = ttk.Button(frame, text="Daemon Log", command=self.daemon_log)
button.grid(row=0, column=1, sticky="ew", padx=PADX)
button = ttk.Button(frame, text="Node Log")
button.grid(row=0, column=2, sticky="ew", padx=PADX)
button = ttk.Button(frame, text="Close", command=self.destroy) button = ttk.Button(frame, text="Close", command=self.destroy)
button.grid(row=0, column=3, sticky="ew") button.grid(row=0, column=1, sticky="ew")
def reset_alerts(self): def reset_alerts(self):
self.codetext.text.delete("1.0", tk.END) self.codetext.text.delete("1.0", tk.END)
@ -110,10 +103,6 @@ class AlertsDialog(Dialog):
self.tree.delete(item) self.tree.delete(item)
self.app.statusbar.core_alarms.clear() self.app.statusbar.core_alarms.clear()
def daemon_log(self):
dialog = DaemonLog(self, self.app)
dialog.show()
def click_select(self, event: tk.Event): def click_select(self, event: tk.Event):
current = self.tree.selection()[0] current = self.tree.selection()[0]
alarm = self.alarm_map[current] alarm = self.alarm_map[current]
@ -121,33 +110,3 @@ class AlertsDialog(Dialog):
self.codetext.text.delete("1.0", "end") self.codetext.text.delete("1.0", "end")
self.codetext.text.insert("1.0", alarm.exception_event.text) self.codetext.text.insert("1.0", alarm.exception_event.text)
self.codetext.text.config(state=tk.DISABLED) self.codetext.text.config(state=tk.DISABLED)
class DaemonLog(Dialog):
def __init__(self, master: tk.Widget, app: "Application"):
super().__init__(master, app, "core-daemon log")
self.columnconfigure(0, weight=1)
self.path = tk.StringVar(value="/var/log/core-daemon.log")
self.draw()
def draw(self):
self.top.columnconfigure(0, weight=1)
self.top.rowconfigure(1, weight=1)
frame = ttk.Frame(self.top)
frame.grid(row=0, column=0, sticky="ew", pady=PADY)
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=9)
label = ttk.Label(frame, text="File", anchor="w")
label.grid(row=0, column=0, sticky="ew")
entry = ttk.Entry(frame, textvariable=self.path, state="disabled")
entry.grid(row=0, column=1, sticky="ew")
try:
file = open("/var/log/core-daemon.log", "r")
log = file.readlines()
except FileNotFoundError:
log = "Log file not found"
codetext = CodeText(self.top)
codetext.text.insert("1.0", log)
codetext.text.see("end")
codetext.text.config(state=tk.DISABLED)
codetext.grid(row=1, column=0, sticky="nsew")

View file

@ -15,11 +15,11 @@ PIXEL_SCALE = 100
class SizeAndScaleDialog(Dialog): class SizeAndScaleDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
""" """
create an instance for size and scale object create an instance for size and scale object
""" """
super().__init__(master, app, "Canvas Size and Scale") super().__init__(app, "Canvas Size and Scale")
self.canvas = self.app.canvas self.canvas = self.app.canvas
self.validation = app.validation self.validation = app.validation
self.section_font = font.Font(weight="bold") self.section_font = font.Font(weight="bold")

View file

@ -17,11 +17,11 @@ if TYPE_CHECKING:
class CanvasWallpaperDialog(Dialog): class CanvasWallpaperDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
""" """
create an instance of CanvasWallpaper object create an instance of CanvasWallpaper object
""" """
super().__init__(master, app, "Canvas Background") super().__init__(app, "Canvas Background")
self.canvas = self.app.canvas self.canvas = self.app.canvas
self.scale_option = tk.IntVar(value=self.canvas.scale_option.get()) self.scale_option = tk.IntVar(value=self.canvas.scale_option.get())
self.adjust_to_dim = tk.BooleanVar(value=self.canvas.adjust_to_dim.get()) self.adjust_to_dim = tk.BooleanVar(value=self.canvas.adjust_to_dim.get())

View file

@ -3,7 +3,7 @@ custom color picker
""" """
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
@ -12,8 +12,10 @@ if TYPE_CHECKING:
class ColorPickerDialog(Dialog): class ColorPickerDialog(Dialog):
def __init__(self, master: Any, app: "Application", initcolor: str = "#000000"): def __init__(
super().__init__(master, app, "color picker") self, master: tk.BaseWidget, app: "Application", initcolor: str = "#000000"
):
super().__init__(app, "color picker", master=master)
self.red_entry = None self.red_entry = None
self.blue_entry = None self.blue_entry = None
self.green_entry = None self.green_entry = None

View file

@ -4,7 +4,7 @@ Service configuration dialog
import logging import logging
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any, List from typing import TYPE_CHECKING, List
import grpc import grpc
@ -21,16 +21,14 @@ if TYPE_CHECKING:
class ConfigServiceConfigDialog(Dialog): class ConfigServiceConfigDialog(Dialog):
def __init__( def __init__(
self, self,
master: Any, master: tk.BaseWidget,
app: "Application", app: "Application",
service_name: str, service_name: str,
canvas_node: "CanvasNode", canvas_node: "CanvasNode",
node_id: int, node_id: int,
): ):
title = f"{service_name} Config Service" title = f"{service_name} Config Service"
super().__init__(master, app, title) super().__init__(app, title, master=master)
self.master = master
self.app = app
self.core = app.core self.core = app.core
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node_id = node_id self.node_id = node_id

View file

@ -4,7 +4,7 @@ copy service config dialog
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any, Tuple from typing import TYPE_CHECKING, Tuple
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.themes import FRAME_PAD, PADX from core.gui.themes import FRAME_PAD, PADX
@ -15,10 +15,9 @@ if TYPE_CHECKING:
class CopyServiceConfigDialog(Dialog): class CopyServiceConfigDialog(Dialog):
def __init__(self, master: Any, app: "Application", node_id: int): def __init__(self, master: tk.BaseWidget, app: "Application", node_id: int):
super().__init__(master, app, f"Copy services to node {node_id}") super().__init__(app, f"Copy services to node {node_id}", master=master)
self.parent = master self.parent = master
self.app = app
self.node_id = node_id self.node_id = node_id
self.service_configs = app.core.service_configs self.service_configs = app.core.service_configs
self.file_configs = app.core.file_configs self.file_configs = app.core.file_configs
@ -171,13 +170,13 @@ class CopyServiceConfigDialog(Dialog):
class ViewConfigDialog(Dialog): class ViewConfigDialog(Dialog):
def __init__( def __init__(
self, self,
master: Any, master: tk.BaseWidget,
app: "Application", app: "Application",
node_id: int, node_id: int,
data: str, data: str,
filename: str = None, filename: str = None,
): ):
super().__init__(master, app, f"n{node_id} config data") super().__init__(app, f"n{node_id} config data", master=master)
self.data = data self.data = data
self.service_data = None self.service_data = None
self.filepath = tk.StringVar(value=f"/tmp/services.tmp-n{node_id}-{filename}") self.filepath = tk.StringVar(value=f"/tmp/services.tmp-n{node_id}-{filename}")

View file

@ -2,7 +2,7 @@ import logging
import tkinter as tk import tkinter as tk
from pathlib import Path from pathlib import Path
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any, Set from typing import TYPE_CHECKING, Set
from core.gui import nodeutils from core.gui import nodeutils
from core.gui.appconfig import ICONS_PATH from core.gui.appconfig import ICONS_PATH
@ -17,8 +17,10 @@ if TYPE_CHECKING:
class ServicesSelectDialog(Dialog): class ServicesSelectDialog(Dialog):
def __init__(self, master: Any, app: "Application", current_services: Set[str]): def __init__(
super().__init__(master, app, "Node Services") self, master: tk.BaseWidget, app: "Application", current_services: Set[str]
):
super().__init__(app, "Node Services", master=master)
self.groups = None self.groups = None
self.services = None self.services = None
self.current = None self.current = None
@ -100,8 +102,8 @@ class ServicesSelectDialog(Dialog):
class CustomNodesDialog(Dialog): class CustomNodesDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Custom Nodes") super().__init__(app, "Custom Nodes")
self.edit_button = None self.edit_button = None
self.delete_button = None self.delete_button = None
self.nodes_list = None self.nodes_list = None

View file

@ -11,8 +11,14 @@ if TYPE_CHECKING:
class Dialog(tk.Toplevel): class Dialog(tk.Toplevel):
def __init__( def __init__(
self, master: tk.Widget, app: "Application", title: str, modal: bool = True self,
app: "Application",
title: str,
modal: bool = True,
master: tk.BaseWidget = None,
): ):
if master is None:
master = app
super().__init__(master) super().__init__(master)
self.withdraw() self.withdraw()
self.app = app self.app = app

View file

@ -4,7 +4,7 @@ emane configuration
import tkinter as tk import tkinter as tk
import webbrowser import webbrowser
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING
import grpc import grpc
@ -19,8 +19,8 @@ if TYPE_CHECKING:
class GlobalEmaneDialog(Dialog): class GlobalEmaneDialog(Dialog):
def __init__(self, master: Any, app: "Application"): def __init__(self, master: tk.BaseWidget, app: "Application"):
super().__init__(master, app, "EMANE Configuration") super().__init__(app, "EMANE Configuration", master=master)
self.config_frame = None self.config_frame = None
self.draw() self.draw()
@ -52,14 +52,14 @@ class GlobalEmaneDialog(Dialog):
class EmaneModelDialog(Dialog): class EmaneModelDialog(Dialog):
def __init__( def __init__(
self, self,
master: Any, master: tk.BaseWidget,
app: "Application", app: "Application",
canvas_node: "CanvasNode", canvas_node: "CanvasNode",
model: str, model: str,
interface: int = None, interface: int = None,
): ):
super().__init__( super().__init__(
master, app, f"{canvas_node.core_node.name} {model} Configuration" app, f"{canvas_node.core_node.name} {model} Configuration", master=master
) )
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node = canvas_node.core_node self.node = canvas_node.core_node
@ -109,13 +109,8 @@ class EmaneModelDialog(Dialog):
class EmaneConfigDialog(Dialog): class EmaneConfigDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode"):
self, master: "Application", app: "Application", canvas_node: "CanvasNode" super().__init__(app, f"{canvas_node.core_node.name} EMANE Configuration")
):
super().__init__(
master, app, f"{canvas_node.core_node.name} EMANE Configuration"
)
self.app = app
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node = canvas_node.core_node self.node = canvas_node.core_node
self.radiovar = tk.IntVar() self.radiovar = tk.IntVar()

View file

@ -11,8 +11,8 @@ if TYPE_CHECKING:
class ErrorDialog(Dialog): class ErrorDialog(Dialog):
def __init__(self, master, app: "Application", title: str, details: str) -> None: def __init__(self, app: "Application", title: str, details: str) -> None:
super().__init__(master, app, "CORE Exception") super().__init__(app, "CORE Exception")
self.title = title self.title = title
self.details = details self.details = details
self.error_message = None self.error_message = None

View file

@ -1,16 +1,19 @@
import logging import logging
import tkinter as tk import tkinter as tk
from tkinter import filedialog, ttk from tkinter import filedialog, ttk
from typing import TYPE_CHECKING
from core.gui.appconfig import SCRIPT_PATH from core.gui.appconfig import SCRIPT_PATH
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.themes import FRAME_PAD, PADX from core.gui.themes import FRAME_PAD, PADX
if TYPE_CHECKING:
from core.gui.app import Application
class ExecutePythonDialog(Dialog): class ExecutePythonDialog(Dialog):
def __init__(self, master, app): def __init__(self, app: "Application"):
super().__init__(master, app, "Execute Python Script") super().__init__(app, "Execute Python Script")
self.app = app
self.with_options = tk.IntVar(value=0) self.with_options = tk.IntVar(value=0)
self.options = tk.StringVar(value="") self.options = tk.StringVar(value="")
self.option_entry = None self.option_entry = None

View file

@ -1,14 +1,18 @@
import logging import logging
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.themes import FRAME_PAD, PADX, PADY
if TYPE_CHECKING:
from core.gui.app import Application
class FindDialog(Dialog): class FindDialog(Dialog):
def __init__(self, master, app) -> None: def __init__(self, app: "Application") -> None:
super().__init__(master, app, "Find", modal=False) super().__init__(app, "Find", modal=False)
self.find_text = tk.StringVar(value="") self.find_text = tk.StringVar(value="")
self.tree = None self.tree = None
self.draw() self.draw()
@ -90,7 +94,8 @@ class FindDialog(Dialog):
if not node_name or node_name == name: if not node_name or node_name == name:
pos_x = round(node.core_node.position.x, 1) pos_x = round(node.core_node.position.x, 1)
pos_y = round(node.core_node.position.y, 1) pos_y = round(node.core_node.position.y, 1)
# TODO I am not sure what to insert for Detail column, leaving in blank for now # TODO: I am not sure what to insert for Detail column
# leaving it blank for now
self.tree.insert( self.tree.insert(
"", "",
tk.END, tk.END,

View file

@ -1,6 +1,6 @@
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING
from core.api.grpc import core_pb2 from core.api.grpc import core_pb2
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
@ -12,8 +12,8 @@ if TYPE_CHECKING:
class HookDialog(Dialog): class HookDialog(Dialog):
def __init__(self, master: Any, app: "Application"): def __init__(self, master: tk.BaseWidget, app: "Application"):
super().__init__(master, app, "Hook") super().__init__(app, "Hook", master=master)
self.name = tk.StringVar() self.name = tk.StringVar()
self.codetext = None self.codetext = None
self.hook = core_pb2.Hook() self.hook = core_pb2.Hook()
@ -88,8 +88,8 @@ class HookDialog(Dialog):
class HooksDialog(Dialog): class HooksDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Hooks") super().__init__(app, "Hooks")
self.listbox = None self.listbox = None
self.edit_button = None self.edit_button = None
self.delete_button = None self.delete_button = None

View file

@ -14,8 +14,8 @@ if TYPE_CHECKING:
class IpConfigDialog(Dialog): class IpConfigDialog(Dialog):
def __init__(self, master: "Application", app: "Application") -> None: def __init__(self, app: "Application") -> None:
super().__init__(master, app, "IP Configuration") super().__init__(app, "IP Configuration")
ip_config = self.app.guiconfig.setdefault("ips") ip_config = self.app.guiconfig.setdefault("ips")
self.ip4 = ip_config.setdefault("ip4", appconfig.DEFAULT_IP4) self.ip4 = ip_config.setdefault("ip4", appconfig.DEFAULT_IP4)
self.ip6 = ip_config.setdefault("ip6", appconfig.DEFAULT_IP6) self.ip6 = ip_config.setdefault("ip6", appconfig.DEFAULT_IP6)

View file

@ -12,7 +12,7 @@ from core.gui.themes import PADX, PADY
if TYPE_CHECKING: if TYPE_CHECKING:
from core.gui.app import Application from core.gui.app import Application
from core.gui.graph.graph import CanvasGraph, CanvasEdge from core.gui.graph.graph import CanvasEdge
def get_int(var: tk.StringVar) -> Union[int, None]: def get_int(var: tk.StringVar) -> Union[int, None]:
@ -32,9 +32,8 @@ def get_float(var: tk.StringVar) -> Union[float, None]:
class LinkConfigurationDialog(Dialog): class LinkConfigurationDialog(Dialog):
def __init__(self, master: "CanvasGraph", app: "Application", edge: "CanvasEdge"): def __init__(self, app: "Application", edge: "CanvasEdge"):
super().__init__(master, app, "Link Configuration") super().__init__(app, "Link Configuration")
self.app = app
self.edge = edge self.edge = edge
self.is_symmetric = edge.link.options.unidirectional is False self.is_symmetric = edge.link.options.unidirectional is False
if self.is_symmetric: if self.is_symmetric:

View file

@ -13,8 +13,8 @@ if TYPE_CHECKING:
class MacConfigDialog(Dialog): class MacConfigDialog(Dialog):
def __init__(self, master: "Application", app: "Application") -> None: def __init__(self, app: "Application") -> None:
super().__init__(master, app, "MAC Configuration") super().__init__(app, "MAC Configuration")
mac = self.app.guiconfig.get("mac", appconfig.DEFAULT_MAC) mac = self.app.guiconfig.get("mac", appconfig.DEFAULT_MAC)
self.mac_var = tk.StringVar(value=mac) self.mac_var = tk.StringVar(value=mac)
self.draw() self.draw()

View file

@ -17,11 +17,8 @@ MARKER_THICKNESS = [3, 5, 8, 10]
class MarkerDialog(Dialog): class MarkerDialog(Dialog):
def __init__( def __init__(self, app: "Application", initcolor: str = "#000000"):
self, master: "Application", app: "Application", initcolor: str = "#000000" super().__init__(app, "Marker Tool", modal=False)
):
super().__init__(master, app, "Marker Tool", modal=False)
self.app = app
self.color = initcolor self.color = initcolor
self.radius = MARKER_THICKNESS[0] self.radius = MARKER_THICKNESS[0]
self.marker_thickness = tk.IntVar(value=MARKER_THICKNESS[0]) self.marker_thickness = tk.IntVar(value=MARKER_THICKNESS[0])

View file

@ -16,12 +16,8 @@ if TYPE_CHECKING:
class MobilityConfigDialog(Dialog): class MobilityConfigDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode"):
self, master: "Application", app: "Application", canvas_node: "CanvasNode" super().__init__(app, f"{canvas_node.core_node.name} Mobility Configuration")
):
super().__init__(
master, app, f"{canvas_node.core_node.name} Mobility Configuration"
)
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node = canvas_node.core_node self.node = canvas_node.core_node
self.config_frame = None self.config_frame = None

View file

@ -1,6 +1,6 @@
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING
import grpc import grpc
@ -17,14 +17,7 @@ ICON_SIZE = 16
class MobilityPlayer: class MobilityPlayer:
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode", config):
self,
master: "Application",
app: "Application",
canvas_node: "CanvasNode",
config,
):
self.master = master
self.app = app self.app = app
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.config = config self.config = config
@ -34,9 +27,7 @@ class MobilityPlayer:
def show(self): def show(self):
if self.dialog: if self.dialog:
self.dialog.destroy() self.dialog.destroy()
self.dialog = MobilityPlayerDialog( self.dialog = MobilityPlayerDialog(self.app, self.canvas_node, self.config)
self.master, self.app, self.canvas_node, self.config
)
self.dialog.protocol("WM_DELETE_WINDOW", self.close) self.dialog.protocol("WM_DELETE_WINDOW", self.close)
if self.state == MobilityAction.START: if self.state == MobilityAction.START:
self.set_play() self.set_play()
@ -68,11 +59,9 @@ class MobilityPlayer:
class MobilityPlayerDialog(Dialog): class MobilityPlayerDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode", config):
self, master: Any, app: "Application", canvas_node: "CanvasNode", config
):
super().__init__( super().__init__(
master, app, f"{canvas_node.core_node.name} Mobility Player", modal=False app, f"{canvas_node.core_node.name} Mobility Player", modal=False
) )
self.resizable(False, False) self.resizable(False, False)
self.geometry("") self.geometry("")

View file

@ -94,13 +94,11 @@ class InterfaceData:
class NodeConfigDialog(Dialog): class NodeConfigDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode"):
self, master: "Application", app: "Application", canvas_node: "CanvasNode"
):
""" """
create an instance of node configuration create an instance of node configuration
""" """
super().__init__(master, app, f"{canvas_node.core_node.name} Configuration") super().__init__(app, f"{canvas_node.core_node.name} Configuration")
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node = canvas_node.core_node self.node = canvas_node.core_node
self.image = canvas_node.image self.image = canvas_node.image

View file

@ -18,15 +18,10 @@ if TYPE_CHECKING:
class NodeConfigServiceDialog(Dialog): class NodeConfigServiceDialog(Dialog):
def __init__( def __init__(
self, self, app: "Application", canvas_node: "CanvasNode", services: Set[str] = None
master: tk.Widget,
app: "Application",
canvas_node: "CanvasNode",
services: Set[str] = None,
): ):
title = f"{canvas_node.core_node.name} Config Services" title = f"{canvas_node.core_node.name} Config Services"
super().__init__(master, app, title) super().__init__(app, title)
self.app = app
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node_id = canvas_node.core_node.id self.node_id = canvas_node.core_node.id
self.groups = None self.groups = None

View file

@ -16,12 +16,9 @@ if TYPE_CHECKING:
class NodeServiceDialog(Dialog): class NodeServiceDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode"):
self, master: tk.Widget, app: "Application", canvas_node: "CanvasNode"
):
title = f"{canvas_node.core_node.name} Services" title = f"{canvas_node.core_node.name} Services"
super().__init__(master, app, title) super().__init__(app, title)
self.app = app
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node_id = canvas_node.core_node.id self.node_id = canvas_node.core_node.id
self.groups = None self.groups = None

View file

@ -12,8 +12,8 @@ if TYPE_CHECKING:
class ObserverDialog(Dialog): class ObserverDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Observer Widgets") super().__init__(app, "Observer Widgets")
self.observers = None self.observers = None
self.save_button = None self.save_button = None
self.delete_button = None self.delete_button = None

View file

@ -16,8 +16,8 @@ SCALE_INTERVAL = 0.01
class PreferencesDialog(Dialog): class PreferencesDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Preferences") super().__init__(app, "Preferences")
self.gui_scale = tk.DoubleVar(value=self.app.app_scale) self.gui_scale = tk.DoubleVar(value=self.app.app_scale)
preferences = self.app.guiconfig["preferences"] preferences = self.app.guiconfig["preferences"]
self.editor = tk.StringVar(value=preferences["editor"]) self.editor = tk.StringVar(value=preferences["editor"])

View file

@ -1,17 +1,20 @@
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from typing import TYPE_CHECKING
from core.gui.dialogs.dialog import Dialog from core.gui.dialogs.dialog import Dialog
from core.gui.nodeutils import NodeUtils from core.gui.nodeutils import NodeUtils
from core.gui.themes import FRAME_PAD, PADX, PADY from core.gui.themes import FRAME_PAD, PADX, PADY
from core.gui.widgets import CodeText, ListboxScroll from core.gui.widgets import CodeText, ListboxScroll
if TYPE_CHECKING:
from core.gui.app import Application
class RunToolDialog(Dialog): class RunToolDialog(Dialog):
def __init__(self, master, app) -> None: def __init__(self, app: "Application") -> None:
super().__init__(master, app, "Run Tool") super().__init__(app, "Run Tool")
self.cmd = tk.StringVar(value="ps ax") self.cmd = tk.StringVar(value="ps ax")
self.app = app
self.result = None self.result = None
self.node_list = None self.node_list = None
self.executable_nodes = {} self.executable_nodes = {}

View file

@ -16,8 +16,8 @@ DEFAULT_PORT = 50051
class ServersDialog(Dialog): class ServersDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "CORE Servers") super().__init__(app, "CORE Servers")
self.name = tk.StringVar(value=DEFAULT_NAME) self.name = tk.StringVar(value=DEFAULT_NAME)
self.address = tk.StringVar(value=DEFAULT_ADDRESS) self.address = tk.StringVar(value=DEFAULT_ADDRESS)
self.port = tk.IntVar(value=DEFAULT_PORT) self.port = tk.IntVar(value=DEFAULT_PORT)

View file

@ -2,7 +2,7 @@ import logging
import os import os
import tkinter as tk import tkinter as tk
from tkinter import filedialog, ttk from tkinter import filedialog, ttk
from typing import TYPE_CHECKING, Any, List from typing import TYPE_CHECKING, List
import grpc import grpc
@ -21,16 +21,14 @@ if TYPE_CHECKING:
class ServiceConfigDialog(Dialog): class ServiceConfigDialog(Dialog):
def __init__( def __init__(
self, self,
master: Any, master: tk.BaseWidget,
app: "Application", app: "Application",
service_name: str, service_name: str,
canvas_node: "CanvasNode", canvas_node: "CanvasNode",
node_id: int, node_id: int,
): ):
title = f"{service_name} Service" title = f"{service_name} Service"
super().__init__(master, app, title) super().__init__(app, title, master=master)
self.master = master
self.app = app
self.core = app.core self.core = app.core
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node_id = node_id self.node_id = node_id

View file

@ -13,8 +13,8 @@ if TYPE_CHECKING:
class SessionOptionsDialog(Dialog): class SessionOptionsDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Session Options") super().__init__(app, "Session Options")
self.config_frame = None self.config_frame = None
self.has_error = False self.has_error = False
self.config = self.get_config() self.config = self.get_config()

View file

@ -16,10 +16,8 @@ if TYPE_CHECKING:
class SessionsDialog(Dialog): class SessionsDialog(Dialog):
def __init__( def __init__(self, app: "Application", is_start_app: bool = False) -> None:
self, master: "Application", app: "Application", is_start_app: bool = False super().__init__(app, "Sessions")
) -> None:
super().__init__(master, app, "Sessions")
self.is_start_app = is_start_app self.is_start_app = is_start_app
self.selected_session = None self.selected_session = None
self.selected_id = None self.selected_id = None

View file

@ -20,12 +20,12 @@ BORDER_WIDTH = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
class ShapeDialog(Dialog): class ShapeDialog(Dialog):
def __init__(self, master: "Application", app: "Application", shape: "Shape"): def __init__(self, app: "Application", shape: "Shape"):
if is_draw_shape(shape.shape_type): if is_draw_shape(shape.shape_type):
title = "Add Shape" title = "Add Shape"
else: else:
title = "Add Text" title = "Add Text"
super().__init__(master, app, title) super().__init__(app, title)
self.canvas = app.canvas self.canvas = app.canvas
self.fill = None self.fill = None
self.border = None self.border = None

View file

@ -14,9 +14,8 @@ if TYPE_CHECKING:
class ThroughputDialog(Dialog): class ThroughputDialog(Dialog):
def __init__(self, master: "Application", app: "Application"): def __init__(self, app: "Application"):
super().__init__(master, app, "Throughput Config") super().__init__(app, "Throughput Config")
self.app = app
self.canvas = app.canvas self.canvas = app.canvas
self.show_throughput = tk.IntVar(value=1) self.show_throughput = tk.IntVar(value=1)
self.exponential_weight = tk.IntVar(value=1) self.exponential_weight = tk.IntVar(value=1)

View file

@ -16,12 +16,8 @@ RANGE_WIDTH = 3
class WlanConfigDialog(Dialog): class WlanConfigDialog(Dialog):
def __init__( def __init__(self, app: "Application", canvas_node: "CanvasNode"):
self, master: "Application", app: "Application", canvas_node: "CanvasNode" super().__init__(app, f"{canvas_node.core_node.name} WLAN Configuration")
):
super().__init__(
master, app, f"{canvas_node.core_node.name} WLAN Configuration"
)
self.canvas_node = canvas_node self.canvas_node = canvas_node
self.node = canvas_node.core_node self.node = canvas_node.core_node
self.config_frame = None self.config_frame = None

View file

@ -389,5 +389,5 @@ class CanvasEdge(Edge):
self.canvas.delete_edge(self) self.canvas.delete_edge(self)
def click_configure(self) -> None: def click_configure(self) -> None:
dialog = LinkConfigurationDialog(self.canvas, self.canvas.app, self) dialog = LinkConfigurationDialog(self.canvas.app, self)
dialog.show() dialog.show()

View file

@ -720,7 +720,7 @@ class CanvasGraph(tk.Canvas):
selected = self.get_selected(event) selected = self.get_selected(event)
if selected is not None and selected in self.shapes: if selected is not None and selected in self.shapes:
shape = self.shapes[selected] shape = self.shapes[selected]
dialog = ShapeDialog(self.app, self.app, shape) dialog = ShapeDialog(self.app, shape)
dialog.show() dialog.show()
def add_node(self, x: float, y: float) -> CanvasNode: def add_node(self, x: float, y: float) -> CanvasNode:

View file

@ -265,16 +265,16 @@ class CanvasNode:
self.canvas.copy() self.canvas.copy()
def show_config(self): def show_config(self):
dialog = NodeConfigDialog(self.app, self.app, self) dialog = NodeConfigDialog(self.app, self)
dialog.show() dialog.show()
def show_wlan_config(self): def show_wlan_config(self):
dialog = WlanConfigDialog(self.app, self.app, self) dialog = WlanConfigDialog(self.app, self)
if not dialog.has_error: if not dialog.has_error:
dialog.show() dialog.show()
def show_mobility_config(self): def show_mobility_config(self):
dialog = MobilityConfigDialog(self.app, self.app, self) dialog = MobilityConfigDialog(self.app, self)
if not dialog.has_error: if not dialog.has_error:
dialog.show() dialog.show()
@ -283,15 +283,15 @@ class CanvasNode:
mobility_player.show() mobility_player.show()
def show_emane_config(self): def show_emane_config(self):
dialog = EmaneConfigDialog(self.app, self.app, self) dialog = EmaneConfigDialog(self.app, self)
dialog.show() dialog.show()
def show_services(self): def show_services(self):
dialog = NodeServiceDialog(self.app, self.app, self) dialog = NodeServiceDialog(self.app, self)
dialog.show() dialog.show()
def show_config_services(self): def show_config_services(self):
dialog = NodeConfigServiceDialog(self.app, self.app, self) dialog = NodeConfigServiceDialog(self.app, self)
dialog.show() dialog.show()
def has_emane_link(self, interface_id: int) -> core_pb2.Node: def has_emane_link(self, interface_id: int) -> core_pb2.Node:

View file

@ -148,7 +148,7 @@ class Shape:
def shape_complete(self, x: float, y: float): def shape_complete(self, x: float, y: float):
for component in tags.ABOVE_SHAPE: for component in tags.ABOVE_SHAPE:
self.canvas.tag_raise(component) self.canvas.tag_raise(component)
s = ShapeDialog(self.app, self.app, self) s = ShapeDialog(self.app, self)
s.show() s.show()
def disappear(self): def disappear(self):

View file

@ -345,8 +345,8 @@ class Menubar(tk.Menu):
task = ProgressTask(self.app, "Open XML", self.core.open_xml, args=(filename,)) task = ProgressTask(self.app, "Open XML", self.core.open_xml, args=(filename,))
task.start() task.start()
def execute_python(self): def execute_python(self) -> None:
dialog = ExecutePythonDialog(self.app, self.app) dialog = ExecutePythonDialog(self.app)
dialog.show() dialog.show()
def add_recent_file_to_gui_config(self, file_path) -> None: def add_recent_file_to_gui_config(self, file_path) -> None:
@ -399,19 +399,19 @@ class Menubar(tk.Menu):
self.core.xml_file = None self.core.xml_file = None
def click_find(self, _event: tk.Event = None) -> None: def click_find(self, _event: tk.Event = None) -> None:
dialog = FindDialog(self.app, self.app) dialog = FindDialog(self.app)
dialog.show() dialog.show()
def click_preferences(self) -> None: def click_preferences(self) -> None:
dialog = PreferencesDialog(self.app, self.app) dialog = PreferencesDialog(self.app)
dialog.show() dialog.show()
def click_canvas_size_and_scale(self) -> None: def click_canvas_size_and_scale(self) -> None:
dialog = SizeAndScaleDialog(self.app, self.app) dialog = SizeAndScaleDialog(self.app)
dialog.show() dialog.show()
def click_canvas_wallpaper(self) -> None: def click_canvas_wallpaper(self) -> None:
dialog = CanvasWallpaperDialog(self.app, self.app) dialog = CanvasWallpaperDialog(self.app)
dialog.show() dialog.show()
def click_core_github(self) -> None: def click_core_github(self) -> None:
@ -421,7 +421,7 @@ class Menubar(tk.Menu):
webbrowser.open_new("http://coreemu.github.io/core/") webbrowser.open_new("http://coreemu.github.io/core/")
def click_about(self) -> None: def click_about(self) -> None:
dialog = AboutDialog(self.app, self.app) dialog = AboutDialog(self.app)
dialog.show() dialog.show()
def click_throughput(self) -> None: def click_throughput(self) -> None:
@ -431,7 +431,7 @@ class Menubar(tk.Menu):
self.core.cancel_throughputs() self.core.cancel_throughputs()
def click_config_throughput(self) -> None: def click_config_throughput(self) -> None:
dialog = ThroughputDialog(self.app, self.app) dialog = ThroughputDialog(self.app)
dialog.show() dialog.show()
def click_copy(self, _event: tk.Event = None) -> None: def click_copy(self, _event: tk.Event = None) -> None:
@ -449,27 +449,27 @@ class Menubar(tk.Menu):
def click_session_options(self) -> None: def click_session_options(self) -> None:
logging.debug("Click options") logging.debug("Click options")
dialog = SessionOptionsDialog(self.app, self.app) dialog = SessionOptionsDialog(self.app)
if not dialog.has_error: if not dialog.has_error:
dialog.show() dialog.show()
def click_sessions(self) -> None: def click_sessions(self) -> None:
logging.debug("Click change sessions") logging.debug("Click change sessions")
dialog = SessionsDialog(self.app, self.app) dialog = SessionsDialog(self.app)
dialog.show() dialog.show()
def click_hooks(self) -> None: def click_hooks(self) -> None:
logging.debug("Click hooks") logging.debug("Click hooks")
dialog = HooksDialog(self.app, self.app) dialog = HooksDialog(self.app)
dialog.show() dialog.show()
def click_servers(self) -> None: def click_servers(self) -> None:
logging.debug("Click emulation servers") logging.debug("Click emulation servers")
dialog = ServersDialog(self.app, self.app) dialog = ServersDialog(self.app)
dialog.show() dialog.show()
def click_edit_observer_widgets(self) -> None: def click_edit_observer_widgets(self) -> None:
dialog = ObserverDialog(self.app, self.app) dialog = ObserverDialog(self.app)
dialog.show() dialog.show()
def click_autogrid(self) -> None: def click_autogrid(self) -> None:
@ -492,13 +492,13 @@ class Menubar(tk.Menu):
edge.draw_labels() edge.draw_labels()
def click_mac_config(self) -> None: def click_mac_config(self) -> None:
dialog = MacConfigDialog(self.app, self.app) dialog = MacConfigDialog(self.app)
dialog.show() dialog.show()
def click_ip_config(self) -> None: def click_ip_config(self) -> None:
dialog = IpConfigDialog(self.app, self.app) dialog = IpConfigDialog(self.app)
dialog.show() dialog.show()
def click_custom_nodes(self) -> None: def click_custom_nodes(self) -> None:
dialog = CustomNodesDialog(self.app, self.app) dialog = CustomNodesDialog(self.app)
dialog.show() dialog.show()

View file

@ -65,7 +65,7 @@ class StatusBar(ttk.Frame):
self.alerts_button.grid(row=0, column=3, sticky="ew") self.alerts_button.grid(row=0, column=3, sticky="ew")
def click_alerts(self): def click_alerts(self):
dialog = AlertsDialog(self.app, self.app) dialog = AlertsDialog(self.app)
dialog.show() dialog.show()
def set_status(self, message: str): def set_status(self, message: str):

View file

@ -459,12 +459,12 @@ class Toolbar(ttk.Frame):
if is_marker(shape_type): if is_marker(shape_type):
if self.marker_tool: if self.marker_tool:
self.marker_tool.destroy() self.marker_tool.destroy()
self.marker_tool = MarkerDialog(self.app, self.app) self.marker_tool = MarkerDialog(self.app)
self.marker_tool.show() self.marker_tool.show()
def click_run_button(self): def click_run_button(self):
logging.debug("Click on RUN button") logging.debug("Click on RUN button")
dialog = RunToolDialog(self.app, self.app) dialog = RunToolDialog(self.app)
dialog.show() dialog.show()
def click_marker_button(self): def click_marker_button(self):
@ -474,7 +474,7 @@ class Toolbar(ttk.Frame):
self.app.canvas.annotation_type = ShapeType.MARKER self.app.canvas.annotation_type = ShapeType.MARKER
if self.marker_tool: if self.marker_tool:
self.marker_tool.destroy() self.marker_tool.destroy()
self.marker_tool = MarkerDialog(self.app, self.app) self.marker_tool = MarkerDialog(self.app)
self.marker_tool.show() self.marker_tool.show()
def scale_button(self, button, image_enum): def scale_button(self, button, image_enum):