pygui: changes to make use of wrapped session object and wrapped nodes to maintain and retrieving configurations information
This commit is contained in:
parent
3bdd6292cd
commit
588afaad13
21 changed files with 284 additions and 455 deletions
|
@ -27,7 +27,7 @@ class SizeAndScaleDialog(Dialog):
|
|||
width, height = self.canvas.current_dimensions
|
||||
self.pixel_width: tk.IntVar = tk.IntVar(value=width)
|
||||
self.pixel_height: tk.IntVar = tk.IntVar(value=height)
|
||||
location = self.app.core.location
|
||||
location = self.app.core.session.location
|
||||
self.x: tk.DoubleVar = tk.DoubleVar(value=location.x)
|
||||
self.y: tk.DoubleVar = tk.DoubleVar(value=location.y)
|
||||
self.lat: tk.DoubleVar = tk.DoubleVar(value=location.lat)
|
||||
|
@ -192,7 +192,7 @@ class SizeAndScaleDialog(Dialog):
|
|||
self.canvas.redraw_canvas((width, height))
|
||||
if self.canvas.wallpaper:
|
||||
self.canvas.redraw_wallpaper()
|
||||
location = self.app.core.location
|
||||
location = self.app.core.session.location
|
||||
location.x = self.x.get()
|
||||
location.y = self.y.get()
|
||||
location.lat = self.lat.get()
|
||||
|
|
|
@ -11,28 +11,26 @@ import grpc
|
|||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ConfigFrame, ListboxScroll
|
||||
from core.gui.wrappers import ConfigOption, ServiceValidationMode
|
||||
from core.gui.wrappers import (
|
||||
ConfigOption,
|
||||
ConfigServiceData,
|
||||
Node,
|
||||
ServiceValidationMode,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
from core.gui.coreclient import CoreClient
|
||||
|
||||
|
||||
class ConfigServiceConfigDialog(Dialog):
|
||||
def __init__(
|
||||
self,
|
||||
master: tk.BaseWidget,
|
||||
app: "Application",
|
||||
service_name: str,
|
||||
canvas_node: "CanvasNode",
|
||||
node_id: int,
|
||||
self, master: tk.BaseWidget, app: "Application", service_name: str, node: Node
|
||||
) -> None:
|
||||
title = f"{service_name} Config Service"
|
||||
super().__init__(app, title, master=master)
|
||||
self.core: "CoreClient" = app.core
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node_id: int = node_id
|
||||
self.node: Node = node
|
||||
self.service_name: str = service_name
|
||||
self.radiovar: tk.IntVar = tk.IntVar()
|
||||
self.radiovar.set(2)
|
||||
|
@ -50,7 +48,7 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
self.validation_time: Optional[int] = None
|
||||
self.validation_period: tk.StringVar = tk.StringVar()
|
||||
self.modes: List[str] = []
|
||||
self.mode_configs: Dict[str, str] = {}
|
||||
self.mode_configs: Dict[str, Dict[str, str]] = {}
|
||||
|
||||
self.notebook: Optional[ttk.Notebook] = None
|
||||
self.templates_combobox: Optional[ttk.Combobox] = None
|
||||
|
@ -91,25 +89,18 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
response = self.core.client.get_config_service_defaults(self.service_name)
|
||||
self.original_service_files = response.templates
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
|
||||
self.modes = sorted(x.name for x in response.modes)
|
||||
self.mode_configs = {x.name: x.config for x in response.modes}
|
||||
|
||||
service_config = self.canvas_node.config_service_configs.get(
|
||||
self.service_name, {}
|
||||
)
|
||||
self.config = ConfigOption.from_dict(response.config)
|
||||
self.default_config = {x.name: x.value for x in self.config.values()}
|
||||
custom_config = service_config.get("config")
|
||||
if custom_config:
|
||||
for key, value in custom_config.items():
|
||||
service_config = self.node.config_service_configs.get(self.service_name)
|
||||
if service_config:
|
||||
for key, value in service_config.config.items():
|
||||
self.config[key].value = value
|
||||
logging.info("default config: %s", self.default_config)
|
||||
|
||||
custom_templates = service_config.get("templates", {})
|
||||
for file, data in custom_templates.items():
|
||||
self.modified_files.add(file)
|
||||
self.temp_service_files[file] = data
|
||||
logging.info("default config: %s", self.default_config)
|
||||
for file, data in service_config.templates.items():
|
||||
self.modified_files.add(file)
|
||||
self.temp_service_files[file] = data
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Get Config Service Error", e)
|
||||
self.has_error = True
|
||||
|
@ -313,20 +304,18 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
def click_apply(self) -> None:
|
||||
current_listbox = self.master.current.listbox
|
||||
if not self.is_custom():
|
||||
self.canvas_node.config_service_configs.pop(self.service_name, None)
|
||||
self.node.config_service_configs.pop(self.service_name, None)
|
||||
current_listbox.itemconfig(current_listbox.curselection()[0], bg="")
|
||||
self.destroy()
|
||||
return
|
||||
|
||||
service_config = self.canvas_node.config_service_configs.setdefault(
|
||||
self.service_name, {}
|
||||
)
|
||||
service_config = self.node.config_service_configs.get(self.service_name)
|
||||
if not service_config:
|
||||
service_config = ConfigServiceData()
|
||||
if self.config_frame:
|
||||
self.config_frame.parse_config()
|
||||
service_config["config"] = {x.name: x.value for x in self.config.values()}
|
||||
templates_config = service_config.setdefault("templates", {})
|
||||
service_config.config = {x.name: x.value for x in self.config.values()}
|
||||
for file in self.modified_files:
|
||||
templates_config[file] = self.temp_service_files[file]
|
||||
service_config.templates[file] = self.temp_service_files[file]
|
||||
all_current = current_listbox.get(0, tk.END)
|
||||
current_listbox.itemconfig(all_current.index(self.service_name), bg="green")
|
||||
self.destroy()
|
||||
|
@ -360,9 +349,9 @@ class ConfigServiceConfigDialog(Dialog):
|
|||
return has_custom_templates or has_custom_config
|
||||
|
||||
def click_defaults(self) -> None:
|
||||
self.canvas_node.config_service_configs.pop(self.service_name, None)
|
||||
self.node.config_service_configs.pop(self.service_name, None)
|
||||
logging.info(
|
||||
"cleared config service config: %s", self.canvas_node.config_service_configs
|
||||
"cleared config service config: %s", self.node.config_service_configs
|
||||
)
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
filename = self.templates_combobox.get()
|
||||
|
|
|
@ -43,16 +43,15 @@ class CopyServiceConfigDialog(Dialog):
|
|||
listbox_scroll = ListboxScroll(self.top)
|
||||
listbox_scroll.grid(sticky="nsew", pady=PADY)
|
||||
self.listbox = listbox_scroll.listbox
|
||||
for canvas_node in self.app.canvas.nodes.values():
|
||||
file_configs = canvas_node.service_file_configs.get(self.service)
|
||||
for node in self.app.core.session.nodes.values():
|
||||
file_configs = node.service_file_configs.get(self.service)
|
||||
if not file_configs:
|
||||
continue
|
||||
data = file_configs.get(self.file_name)
|
||||
if not data:
|
||||
continue
|
||||
name = canvas_node.core_node.name
|
||||
self.nodes[name] = canvas_node.id
|
||||
self.listbox.insert(tk.END, name)
|
||||
self.nodes[node.name] = node.id
|
||||
self.listbox.insert(tk.END, node.name)
|
||||
|
||||
frame = ttk.Frame(self.top)
|
||||
frame.grid(sticky="ew")
|
||||
|
@ -70,9 +69,9 @@ class CopyServiceConfigDialog(Dialog):
|
|||
if not selection:
|
||||
return
|
||||
name = self.listbox.get(selection)
|
||||
canvas_node_id = self.nodes[name]
|
||||
canvas_node = self.app.canvas.nodes[canvas_node_id]
|
||||
data = canvas_node.service_file_configs[self.service][self.file_name]
|
||||
node_id = self.nodes[name]
|
||||
node = self.app.core.session.nodes[node_id]
|
||||
data = node.service_file_configs[self.service][self.file_name]
|
||||
self.dialog.temp_service_files[self.file_name] = data
|
||||
self.dialog.modified_files.add(self.file_name)
|
||||
self.dialog.service_file_data.text.delete(1.0, tk.END)
|
||||
|
@ -84,9 +83,9 @@ class CopyServiceConfigDialog(Dialog):
|
|||
if not selection:
|
||||
return
|
||||
name = self.listbox.get(selection)
|
||||
canvas_node_id = self.nodes[name]
|
||||
canvas_node = self.app.canvas.nodes[canvas_node_id]
|
||||
data = canvas_node.service_file_configs[self.service][self.file_name]
|
||||
node_id = self.nodes[name]
|
||||
node = self.app.core.session.nodes[node_id]
|
||||
data = node.service_file_configs[self.service][self.file_name]
|
||||
dialog = ViewConfigDialog(
|
||||
self.app, self, name, self.service, self.file_name, data
|
||||
)
|
||||
|
|
|
@ -16,7 +16,6 @@ from core.gui.wrappers import ConfigOption, Node
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
|
||||
class GlobalEmaneDialog(Dialog):
|
||||
|
@ -29,8 +28,9 @@ class GlobalEmaneDialog(Dialog):
|
|||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.top.rowconfigure(0, weight=1)
|
||||
session = self.app.core.session
|
||||
self.config_frame = ConfigFrame(
|
||||
self.top, self.app, self.app.core.emane_config, self.enabled
|
||||
self.top, self.app, session.emane_config, self.enabled
|
||||
)
|
||||
self.config_frame.draw_config()
|
||||
self.config_frame.grid(sticky="nsew", pady=PADY)
|
||||
|
@ -58,24 +58,19 @@ class EmaneModelDialog(Dialog):
|
|||
self,
|
||||
master: tk.BaseWidget,
|
||||
app: "Application",
|
||||
canvas_node: "CanvasNode",
|
||||
node: Node,
|
||||
model: str,
|
||||
iface_id: int = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
app, f"{canvas_node.core_node.name} {model} Configuration", master=master
|
||||
)
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node: Node = canvas_node.core_node
|
||||
super().__init__(app, f"{node.name} {model} Configuration", master=master)
|
||||
self.node: Node = node
|
||||
self.model: str = f"emane_{model}"
|
||||
self.iface_id: int = iface_id
|
||||
self.config_frame: Optional[ConfigFrame] = None
|
||||
self.enabled: bool = not self.app.core.is_runtime()
|
||||
self.has_error: bool = False
|
||||
try:
|
||||
config = self.canvas_node.emane_model_configs.get(
|
||||
(self.model, self.iface_id)
|
||||
)
|
||||
config = self.node.emane_model_configs.get((self.model, self.iface_id))
|
||||
if not config:
|
||||
config = self.app.core.get_emane_model_config(
|
||||
self.node.id, self.model, self.iface_id
|
||||
|
@ -110,19 +105,18 @@ class EmaneModelDialog(Dialog):
|
|||
def click_apply(self) -> None:
|
||||
self.config_frame.parse_config()
|
||||
key = (self.model, self.iface_id)
|
||||
self.canvas_node.emane_model_configs[key] = self.config
|
||||
self.node.emane_model_configs[key] = self.config
|
||||
self.destroy()
|
||||
|
||||
|
||||
class EmaneConfigDialog(Dialog):
|
||||
def __init__(self, app: "Application", canvas_node: "CanvasNode") -> None:
|
||||
super().__init__(app, f"{canvas_node.core_node.name} EMANE Configuration")
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node: Node = canvas_node.core_node
|
||||
def __init__(self, app: "Application", node: Node) -> None:
|
||||
super().__init__(app, f"{node.name} EMANE Configuration")
|
||||
self.node: Node = node
|
||||
self.radiovar: tk.IntVar = tk.IntVar()
|
||||
self.radiovar.set(1)
|
||||
self.emane_models: List[str] = [
|
||||
x.split("_")[1] for x in self.app.core.emane_models
|
||||
x.split("_")[1] for x in self.app.core.session.emane_models
|
||||
]
|
||||
model = self.node.emane.split("_")[1]
|
||||
self.emane_model: tk.StringVar = tk.StringVar(value=model)
|
||||
|
@ -231,7 +225,7 @@ class EmaneConfigDialog(Dialog):
|
|||
draw emane model configuration
|
||||
"""
|
||||
model_name = self.emane_model.get()
|
||||
dialog = EmaneModelDialog(self, self.app, self.canvas_node, model_name)
|
||||
dialog = EmaneModelDialog(self, self.app, self.node, model_name)
|
||||
if not dialog.has_error:
|
||||
dialog.show()
|
||||
|
||||
|
|
|
@ -113,8 +113,9 @@ class HooksDialog(Dialog):
|
|||
listbox_scroll.grid(sticky="nsew", pady=PADY)
|
||||
self.listbox = listbox_scroll.listbox
|
||||
self.listbox.bind("<<ListboxSelect>>", self.select)
|
||||
for hook_file in self.app.core.hooks:
|
||||
self.listbox.insert(tk.END, hook_file)
|
||||
session = self.app.core.session
|
||||
for file in session.hooks:
|
||||
self.listbox.insert(tk.END, file)
|
||||
|
||||
frame = ttk.Frame(self.top)
|
||||
frame.grid(sticky="ew")
|
||||
|
@ -138,20 +139,22 @@ class HooksDialog(Dialog):
|
|||
dialog.show()
|
||||
hook = dialog.hook
|
||||
if hook:
|
||||
self.app.core.hooks[hook.file] = hook
|
||||
self.app.core.session.hooks[hook.file] = hook
|
||||
self.listbox.insert(tk.END, hook.file)
|
||||
|
||||
def click_edit(self) -> None:
|
||||
hook = self.app.core.hooks.pop(self.selected)
|
||||
session = self.app.core.session
|
||||
hook = session.hooks.pop(self.selected)
|
||||
dialog = HookDialog(self, self.app)
|
||||
dialog.set(hook)
|
||||
dialog.show()
|
||||
self.app.core.hooks[hook.file] = hook
|
||||
session.hooks[hook.file] = hook
|
||||
self.listbox.delete(self.selected_index)
|
||||
self.listbox.insert(self.selected_index, hook.file)
|
||||
|
||||
def click_delete(self) -> None:
|
||||
del self.app.core.hooks[self.selected]
|
||||
session = self.app.core.session
|
||||
del session.hooks[self.selected]
|
||||
self.listbox.delete(tk.ANCHOR)
|
||||
self.edit_button.config(state=tk.DISABLED)
|
||||
self.delete_button.config(state=tk.DISABLED)
|
||||
|
|
|
@ -269,7 +269,7 @@ class LinkConfigurationDialog(Dialog):
|
|||
self.edge.asymmetric_link = None
|
||||
|
||||
if self.app.core.is_runtime() and link.options:
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
self.app.core.client.edit_link(
|
||||
session_id,
|
||||
link.node1_id,
|
||||
|
|
|
@ -13,18 +13,16 @@ from core.gui.wrappers import ConfigOption, Node
|
|||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
|
||||
class MobilityConfigDialog(Dialog):
|
||||
def __init__(self, app: "Application", canvas_node: "CanvasNode") -> None:
|
||||
super().__init__(app, f"{canvas_node.core_node.name} Mobility Configuration")
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node: Node = canvas_node.core_node
|
||||
def __init__(self, app: "Application", node: Node) -> None:
|
||||
super().__init__(app, f"{node.name} Mobility Configuration")
|
||||
self.node: Node = node
|
||||
self.config_frame: Optional[ConfigFrame] = None
|
||||
self.has_error: bool = False
|
||||
try:
|
||||
config = self.canvas_node.mobility_config
|
||||
config = self.node.mobility_config
|
||||
if not config:
|
||||
config = self.app.core.get_mobility_config(self.node.id)
|
||||
self.config: Dict[str, ConfigOption] = config
|
||||
|
@ -56,5 +54,5 @@ class MobilityConfigDialog(Dialog):
|
|||
|
||||
def click_apply(self) -> None:
|
||||
self.config_frame.parse_config()
|
||||
self.canvas_node.mobility_config = self.config
|
||||
self.node.mobility_config = self.config
|
||||
self.destroy()
|
||||
|
|
|
@ -1,38 +1,31 @@
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from typing import TYPE_CHECKING, Dict, Optional
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
import grpc
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.images import ImageEnum
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.wrappers import ConfigOption, MobilityAction, Node
|
||||
from core.gui.wrappers import MobilityAction, Node
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
ICON_SIZE: int = 16
|
||||
|
||||
|
||||
class MobilityPlayer:
|
||||
def __init__(
|
||||
self,
|
||||
app: "Application",
|
||||
canvas_node: "CanvasNode",
|
||||
config: Dict[str, ConfigOption],
|
||||
) -> None:
|
||||
def __init__(self, app: "Application", node: Node) -> None:
|
||||
self.app: "Application" = app
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.config: Dict[str, ConfigOption] = config
|
||||
self.node: Node = node
|
||||
self.dialog: Optional[MobilityPlayerDialog] = None
|
||||
self.state: Optional[MobilityAction] = None
|
||||
|
||||
def show(self) -> None:
|
||||
if self.dialog:
|
||||
self.dialog.destroy()
|
||||
self.dialog = MobilityPlayerDialog(self.app, self.canvas_node, self.config)
|
||||
self.dialog = MobilityPlayerDialog(self.app, self.node)
|
||||
self.dialog.protocol("WM_DELETE_WINDOW", self.close)
|
||||
if self.state == MobilityAction.START:
|
||||
self.set_play()
|
||||
|
@ -64,20 +57,11 @@ class MobilityPlayer:
|
|||
|
||||
|
||||
class MobilityPlayerDialog(Dialog):
|
||||
def __init__(
|
||||
self,
|
||||
app: "Application",
|
||||
canvas_node: "CanvasNode",
|
||||
config: Dict[str, ConfigOption],
|
||||
) -> None:
|
||||
super().__init__(
|
||||
app, f"{canvas_node.core_node.name} Mobility Player", modal=False
|
||||
)
|
||||
def __init__(self, app: "Application", node: Node) -> None:
|
||||
super().__init__(app, f"{node.name} Mobility Player", modal=False)
|
||||
self.resizable(False, False)
|
||||
self.geometry("")
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node: Node = canvas_node.core_node
|
||||
self.config: Dict[str, ConfigOption] = config
|
||||
self.node: Node = node
|
||||
self.play_button: Optional[ttk.Button] = None
|
||||
self.pause_button: Optional[ttk.Button] = None
|
||||
self.stop_button: Optional[ttk.Button] = None
|
||||
|
@ -85,9 +69,10 @@ class MobilityPlayerDialog(Dialog):
|
|||
self.draw()
|
||||
|
||||
def draw(self) -> None:
|
||||
config = self.node.mobility_config
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
|
||||
file_name = self.config["file"].value
|
||||
file_name = config["file"].value
|
||||
label = ttk.Label(self.top, text=file_name)
|
||||
label.grid(sticky="ew", pady=PADY)
|
||||
|
||||
|
@ -114,13 +99,13 @@ class MobilityPlayerDialog(Dialog):
|
|||
self.stop_button.image = image
|
||||
self.stop_button.grid(row=0, column=2, sticky="ew", padx=PADX)
|
||||
|
||||
loop = tk.IntVar(value=int(self.config["loop"].value == "1"))
|
||||
loop = tk.IntVar(value=int(config["loop"].value == "1"))
|
||||
checkbutton = ttk.Checkbutton(
|
||||
frame, text="Loop?", variable=loop, state=tk.DISABLED
|
||||
)
|
||||
checkbutton.grid(row=0, column=3, padx=PADX)
|
||||
|
||||
rate = self.config["refresh_ms"].value
|
||||
rate = config["refresh_ms"].value
|
||||
label = ttk.Label(frame, text=f"rate {rate} ms")
|
||||
label.grid(row=0, column=4)
|
||||
|
||||
|
@ -146,7 +131,7 @@ class MobilityPlayerDialog(Dialog):
|
|||
|
||||
def click_play(self) -> None:
|
||||
self.set_play()
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
try:
|
||||
self.app.core.client.mobility_action(
|
||||
session_id, self.node.id, MobilityAction.START.value
|
||||
|
@ -156,7 +141,7 @@ class MobilityPlayerDialog(Dialog):
|
|||
|
||||
def click_pause(self) -> None:
|
||||
self.set_pause()
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
try:
|
||||
self.app.core.client.mobility_action(
|
||||
session_id, self.node.id, MobilityAction.PAUSE.value
|
||||
|
@ -166,7 +151,7 @@ class MobilityPlayerDialog(Dialog):
|
|||
|
||||
def click_stop(self) -> None:
|
||||
self.set_stop()
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
try:
|
||||
self.app.core.client.mobility_action(
|
||||
session_id, self.node.id, MobilityAction.STOP.value
|
||||
|
|
|
@ -10,25 +10,24 @@ from core.gui.dialogs.configserviceconfig import ConfigServiceConfigDialog
|
|||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CheckboxList, ListboxScroll
|
||||
from core.gui.wrappers import Node
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
|
||||
class NodeConfigServiceDialog(Dialog):
|
||||
def __init__(
|
||||
self, app: "Application", canvas_node: "CanvasNode", services: Set[str] = None
|
||||
self, app: "Application", node: Node, services: Set[str] = None
|
||||
) -> None:
|
||||
title = f"{canvas_node.core_node.name} Config Services"
|
||||
title = f"{node.name} Config Services"
|
||||
super().__init__(app, title)
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node_id: int = canvas_node.core_node.id
|
||||
self.node: Node = node
|
||||
self.groups: Optional[ListboxScroll] = None
|
||||
self.services: Optional[CheckboxList] = None
|
||||
self.current: Optional[ListboxScroll] = None
|
||||
if services is None:
|
||||
services = set(canvas_node.core_node.config_services)
|
||||
services = set(node.config_services)
|
||||
self.current_services: Set[str] = services
|
||||
self.draw()
|
||||
|
||||
|
@ -102,7 +101,7 @@ class NodeConfigServiceDialog(Dialog):
|
|||
elif not var.get() and name in self.current_services:
|
||||
self.current_services.remove(name)
|
||||
self.draw_current_services()
|
||||
self.canvas_node.core_node.config_services[:] = self.current_services
|
||||
self.node.config_services[:] = self.current_services
|
||||
|
||||
def click_configure(self) -> None:
|
||||
current_selection = self.current.listbox.curselection()
|
||||
|
@ -111,8 +110,7 @@ class NodeConfigServiceDialog(Dialog):
|
|||
self,
|
||||
self.app,
|
||||
self.current.listbox.get(current_selection[0]),
|
||||
self.canvas_node,
|
||||
self.node_id,
|
||||
self.node,
|
||||
)
|
||||
if not dialog.has_error:
|
||||
dialog.show()
|
||||
|
@ -132,10 +130,8 @@ class NodeConfigServiceDialog(Dialog):
|
|||
self.current.listbox.itemconfig(tk.END, bg="green")
|
||||
|
||||
def click_save(self) -> None:
|
||||
self.canvas_node.core_node.config_services[:] = self.current_services
|
||||
logging.info(
|
||||
"saved node config services: %s", self.canvas_node.core_node.config_services
|
||||
)
|
||||
self.node.config_services[:] = self.current_services
|
||||
logging.info("saved node config services: %s", self.node.config_services)
|
||||
self.destroy()
|
||||
|
||||
def click_cancel(self) -> None:
|
||||
|
@ -154,4 +150,4 @@ class NodeConfigServiceDialog(Dialog):
|
|||
return
|
||||
|
||||
def is_custom_service(self, service: str) -> bool:
|
||||
return service in self.canvas_node.config_service_configs
|
||||
return service in self.node.config_service_configs
|
||||
|
|
|
@ -9,22 +9,21 @@ 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
|
||||
from core.gui.wrappers import Node
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
|
||||
|
||||
class NodeServiceDialog(Dialog):
|
||||
def __init__(self, app: "Application", canvas_node: "CanvasNode") -> None:
|
||||
title = f"{canvas_node.core_node.name} Services"
|
||||
def __init__(self, app: "Application", node: Node) -> None:
|
||||
title = f"{node.name} Services"
|
||||
super().__init__(app, title)
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node_id: int = canvas_node.core_node.id
|
||||
self.node: Node = node
|
||||
self.groups: Optional[ListboxScroll] = None
|
||||
self.services: Optional[CheckboxList] = None
|
||||
self.current: Optional[ListboxScroll] = None
|
||||
services = set(canvas_node.core_node.services)
|
||||
services = set(node.services)
|
||||
self.current_services: Set[str] = services
|
||||
self.draw()
|
||||
|
||||
|
@ -104,7 +103,7 @@ class NodeServiceDialog(Dialog):
|
|||
self.current.listbox.insert(tk.END, name)
|
||||
if self.is_custom_service(name):
|
||||
self.current.listbox.itemconfig(tk.END, bg="green")
|
||||
self.canvas_node.core_node.services[:] = self.current_services
|
||||
self.node.services = self.current_services.copy()
|
||||
|
||||
def click_configure(self) -> None:
|
||||
current_selection = self.current.listbox.curselection()
|
||||
|
@ -113,8 +112,7 @@ class NodeServiceDialog(Dialog):
|
|||
self,
|
||||
self.app,
|
||||
self.current.listbox.get(current_selection[0]),
|
||||
self.canvas_node,
|
||||
self.node_id,
|
||||
self.node,
|
||||
)
|
||||
|
||||
# if error occurred when creating ServiceConfigDialog, don't show the dialog
|
||||
|
@ -128,8 +126,7 @@ class NodeServiceDialog(Dialog):
|
|||
)
|
||||
|
||||
def click_save(self) -> None:
|
||||
core_node = self.canvas_node.core_node
|
||||
core_node.services[:] = self.current_services
|
||||
self.node.services[:] = self.current_services
|
||||
self.destroy()
|
||||
|
||||
def click_remove(self) -> None:
|
||||
|
@ -144,6 +141,6 @@ class NodeServiceDialog(Dialog):
|
|||
return
|
||||
|
||||
def is_custom_service(self, service: str) -> bool:
|
||||
has_service_config = service in self.canvas_node.service_configs
|
||||
has_file_config = service in self.canvas_node.service_file_configs
|
||||
has_service_config = service in self.node.service_configs
|
||||
has_file_config = service in self.node.service_file_configs
|
||||
return has_service_config or has_file_config
|
||||
|
|
|
@ -107,7 +107,7 @@ class RunToolDialog(Dialog):
|
|||
node_name = self.node_list.listbox.get(selection)
|
||||
node_id = self.executable_nodes[node_name]
|
||||
response = self.app.core.client.node_command(
|
||||
self.app.core.session_id, node_id, command
|
||||
self.app.core.session.id, node_id, command
|
||||
)
|
||||
self.result.text.insert(
|
||||
tk.END, f"> {node_name} > {command}:\n{response.output}\n"
|
||||
|
|
|
@ -12,11 +12,10 @@ from core.gui.dialogs.dialog import Dialog
|
|||
from core.gui.images import ImageEnum, Images
|
||||
from core.gui.themes import FRAME_PAD, PADX, PADY
|
||||
from core.gui.widgets import CodeText, ListboxScroll
|
||||
from core.gui.wrappers import NodeServiceData, ServiceValidationMode
|
||||
from core.gui.wrappers import Node, NodeServiceData, ServiceValidationMode
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
from core.gui.graph.node import CanvasNode
|
||||
from core.gui.coreclient import CoreClient
|
||||
|
||||
ICON_SIZE: int = 16
|
||||
|
@ -24,18 +23,12 @@ ICON_SIZE: int = 16
|
|||
|
||||
class ServiceConfigDialog(Dialog):
|
||||
def __init__(
|
||||
self,
|
||||
master: tk.BaseWidget,
|
||||
app: "Application",
|
||||
service_name: str,
|
||||
canvas_node: "CanvasNode",
|
||||
node_id: int,
|
||||
self, master: tk.BaseWidget, app: "Application", service_name: str, node: Node
|
||||
) -> None:
|
||||
title = f"{service_name} Service"
|
||||
super().__init__(app, title, master=master)
|
||||
self.core: "CoreClient" = app.core
|
||||
self.canvas_node: "CanvasNode" = canvas_node
|
||||
self.node_id: int = node_id
|
||||
self.node: Node = node
|
||||
self.service_name: str = service_name
|
||||
self.radiovar: tk.IntVar = tk.IntVar(value=2)
|
||||
self.metadata: str = ""
|
||||
|
@ -84,15 +77,13 @@ class ServiceConfigDialog(Dialog):
|
|||
try:
|
||||
self.app.core.create_nodes_and_links()
|
||||
default_config = self.app.core.get_node_service(
|
||||
self.node_id, self.service_name
|
||||
self.node.id, self.service_name
|
||||
)
|
||||
self.default_startup = default_config.startup[:]
|
||||
self.default_validate = default_config.validate[:]
|
||||
self.default_shutdown = default_config.shutdown[:]
|
||||
self.default_directories = default_config.dirs[:]
|
||||
custom_service_config = self.canvas_node.service_configs.get(
|
||||
self.service_name
|
||||
)
|
||||
custom_service_config = self.node.service_configs.get(self.service_name)
|
||||
self.default_config = default_config
|
||||
service_config = (
|
||||
custom_service_config if custom_service_config else default_config
|
||||
|
@ -109,15 +100,13 @@ class ServiceConfigDialog(Dialog):
|
|||
self.temp_directories = service_config.dirs[:]
|
||||
self.original_service_files = {
|
||||
x: self.app.core.get_node_service_file(
|
||||
self.node_id, self.service_name, x
|
||||
self.node.id, self.service_name, x
|
||||
)
|
||||
for x in default_config.configs
|
||||
}
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
|
||||
file_configs = self.canvas_node.service_file_configs.get(
|
||||
self.service_name, {}
|
||||
)
|
||||
file_configs = self.node.service_file_configs.get(self.service_name, {})
|
||||
for file, data in file_configs.items():
|
||||
self.temp_service_files[file] = data
|
||||
except grpc.RpcError as e:
|
||||
|
@ -453,7 +442,7 @@ class ServiceConfigDialog(Dialog):
|
|||
and not self.has_new_files()
|
||||
and not self.is_custom_directory()
|
||||
):
|
||||
self.canvas_node.service_configs.pop(self.service_name, None)
|
||||
self.node.service_configs.pop(self.service_name, None)
|
||||
self.current_service_color("")
|
||||
self.destroy()
|
||||
return
|
||||
|
@ -466,7 +455,7 @@ class ServiceConfigDialog(Dialog):
|
|||
):
|
||||
startup, validate, shutdown = self.get_commands()
|
||||
config = self.core.set_node_service(
|
||||
self.node_id,
|
||||
self.node.id,
|
||||
self.service_name,
|
||||
dirs=self.temp_directories,
|
||||
files=list(self.filename_combobox["values"]),
|
||||
|
@ -474,15 +463,15 @@ class ServiceConfigDialog(Dialog):
|
|||
validations=validate,
|
||||
shutdowns=shutdown,
|
||||
)
|
||||
self.canvas_node.service_configs[self.service_name] = config
|
||||
self.node.service_configs[self.service_name] = config
|
||||
for file in self.modified_files:
|
||||
file_configs = self.canvas_node.service_file_configs.setdefault(
|
||||
file_configs = self.node.service_file_configs.setdefault(
|
||||
self.service_name, {}
|
||||
)
|
||||
file_configs[file] = self.temp_service_files[file]
|
||||
# TODO: check if this is really needed
|
||||
self.app.core.set_node_service_file(
|
||||
self.node_id, self.service_name, file, self.temp_service_files[file]
|
||||
self.node.id, self.service_name, file, self.temp_service_files[file]
|
||||
)
|
||||
self.current_service_color("green")
|
||||
except grpc.RpcError as e:
|
||||
|
@ -526,8 +515,8 @@ class ServiceConfigDialog(Dialog):
|
|||
clears out any custom configuration permanently
|
||||
"""
|
||||
# clear coreclient data
|
||||
self.canvas_node.service_configs.pop(self.service_name, None)
|
||||
file_configs = self.canvas_node.service_file_configs.pop(self.service_name, {})
|
||||
self.node.service_configs.pop(self.service_name, None)
|
||||
file_configs = self.node.service_file_configs.pop(self.service_name, {})
|
||||
file_configs.pop(self.service_name, None)
|
||||
self.temp_service_files = dict(self.original_service_files)
|
||||
self.modified_files.clear()
|
||||
|
@ -564,9 +553,8 @@ class ServiceConfigDialog(Dialog):
|
|||
|
||||
def click_copy(self) -> None:
|
||||
file_name = self.filename_combobox.get()
|
||||
name = self.canvas_node.core_node.name
|
||||
dialog = CopyServiceConfigDialog(
|
||||
self.app, self, name, self.service_name, file_name
|
||||
self.app, self, self.node.name, self.service_name, file_name
|
||||
)
|
||||
dialog.show()
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class SessionOptionsDialog(Dialog):
|
|||
|
||||
def get_config(self) -> Dict[str, ConfigOption]:
|
||||
try:
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
response = self.app.core.client.get_session_options(session_id)
|
||||
return ConfigOption.from_dict(response.config)
|
||||
except grpc.RpcError as e:
|
||||
|
@ -54,7 +54,7 @@ class SessionOptionsDialog(Dialog):
|
|||
def save(self) -> None:
|
||||
config = self.config_frame.parse_config()
|
||||
try:
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
response = self.app.core.client.set_session_options(session_id, config)
|
||||
logging.info("saved session config: %s", response)
|
||||
except grpc.RpcError as e:
|
||||
|
|
|
@ -201,7 +201,7 @@ class SessionsDialog(Dialog):
|
|||
logging.debug("delete session: %s", self.selected_session)
|
||||
self.tree.delete(self.selected_id)
|
||||
self.app.core.delete_session(self.selected_session)
|
||||
if self.selected_session == self.app.core.session_id:
|
||||
if self.selected_session == self.app.core.session.id:
|
||||
self.click_new()
|
||||
self.destroy()
|
||||
self.click_select()
|
||||
|
|
|
@ -29,7 +29,7 @@ class WlanConfigDialog(Dialog):
|
|||
self.ranges: Dict[int, int] = {}
|
||||
self.positive_int: int = self.app.master.register(self.validate_and_update)
|
||||
try:
|
||||
config = self.canvas_node.wlan_config
|
||||
config = self.node.wlan_config
|
||||
if not config:
|
||||
config = self.app.core.get_wlan_config(self.node.id)
|
||||
self.config: Dict[str, ConfigOption] = config
|
||||
|
@ -83,9 +83,9 @@ class WlanConfigDialog(Dialog):
|
|||
retrieve user's wlan configuration and store the new configuration values
|
||||
"""
|
||||
config = self.config_frame.parse_config()
|
||||
self.canvas_node.wlan_config = self.config
|
||||
self.node.wlan_config = self.config
|
||||
if self.app.core.is_runtime():
|
||||
session_id = self.app.core.session_id
|
||||
session_id = self.app.core.session.id
|
||||
self.app.core.client.set_wlan_config(session_id, self.node.id, config)
|
||||
self.remove_ranges()
|
||||
self.destroy()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue