2019-11-04 06:58:45 +00:00
|
|
|
"""
|
|
|
|
emane configuration
|
|
|
|
"""
|
|
|
|
import tkinter as tk
|
2019-11-04 18:48:22 +00:00
|
|
|
import webbrowser
|
2019-11-05 22:25:25 +00:00
|
|
|
from tkinter import ttk
|
2020-06-22 19:04:33 +01:00
|
|
|
from typing import TYPE_CHECKING, Dict, List, Optional
|
2019-11-04 06:58:45 +00:00
|
|
|
|
2019-12-10 06:50:26 +00:00
|
|
|
import grpc
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
from core.api.grpc.common_pb2 import ConfigOption
|
|
|
|
from core.api.grpc.core_pb2 import Node
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
|
|
|
from core.gui.images import ImageEnum, Images
|
|
|
|
from core.gui.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import ConfigFrame
|
2019-11-04 06:58:45 +00:00
|
|
|
|
2020-01-13 23:31:41 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
from core.gui.graph.node import CanvasNode
|
|
|
|
|
2019-11-04 06:58:45 +00:00
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
class GlobalEmaneDialog(Dialog):
|
2020-06-22 19:04:33 +01:00
|
|
|
def __init__(self, master: tk.BaseWidget, app: "Application") -> None:
|
2020-05-05 06:50:59 +01:00
|
|
|
super().__init__(app, "EMANE Configuration", master=master)
|
2020-06-22 19:04:33 +01:00
|
|
|
self.config_frame: Optional[ConfigFrame] = None
|
2020-06-23 03:04:55 +01:00
|
|
|
self.enabled: bool = not self.app.core.is_runtime()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.draw()
|
2019-11-04 18:48:22 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2020-06-23 03:04:55 +01:00
|
|
|
self.config_frame = ConfigFrame(
|
|
|
|
self.top, self.app, self.app.core.emane_config, self.enabled
|
|
|
|
)
|
2019-11-21 22:41:05 +00:00
|
|
|
self.config_frame.draw_config()
|
2019-12-11 22:36:27 +00:00
|
|
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.draw_spacer()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.draw_buttons()
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_buttons(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2020-06-23 03:04:55 +01:00
|
|
|
state = tk.NORMAL if self.enabled else tk.DISABLED
|
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply, state=state)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
2019-11-04 18:48:22 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_apply(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.config_frame.parse_config()
|
|
|
|
self.destroy()
|
2019-11-04 06:58:45 +00:00
|
|
|
|
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
class EmaneModelDialog(Dialog):
|
2020-01-13 23:31:41 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
2020-05-05 06:50:59 +01:00
|
|
|
master: tk.BaseWidget,
|
2020-01-13 23:31:41 +00:00
|
|
|
app: "Application",
|
2020-04-21 08:38:36 +01:00
|
|
|
canvas_node: "CanvasNode",
|
2020-01-13 23:31:41 +00:00
|
|
|
model: str,
|
2020-06-16 17:30:16 +01:00
|
|
|
iface_id: int = None,
|
2020-06-22 19:04:33 +01:00
|
|
|
) -> None:
|
2020-04-21 08:38:36 +01:00
|
|
|
super().__init__(
|
2020-05-05 06:50:59 +01:00
|
|
|
app, f"{canvas_node.core_node.name} {model} Configuration", master=master
|
2020-04-21 08:38:36 +01:00
|
|
|
)
|
2020-06-22 19:04:33 +01:00
|
|
|
self.canvas_node: "CanvasNode" = canvas_node
|
|
|
|
self.node: Node = canvas_node.core_node
|
|
|
|
self.model: str = f"emane_{model}"
|
|
|
|
self.iface_id: int = iface_id
|
|
|
|
self.config_frame: Optional[ConfigFrame] = None
|
2020-06-23 03:04:55 +01:00
|
|
|
self.enabled: bool = not self.app.core.is_runtime()
|
2020-06-22 19:04:33 +01:00
|
|
|
self.has_error: bool = False
|
2019-12-10 06:50:26 +00:00
|
|
|
try:
|
2020-06-22 19:04:33 +01:00
|
|
|
config = self.canvas_node.emane_model_configs.get(
|
2020-06-16 17:30:16 +01:00
|
|
|
(self.model, self.iface_id)
|
2019-12-10 06:50:26 +00:00
|
|
|
)
|
2020-06-22 19:04:33 +01:00
|
|
|
if not config:
|
|
|
|
config = self.app.core.get_emane_model_config(
|
2020-06-16 17:30:16 +01:00
|
|
|
self.node.id, self.model, self.iface_id
|
2020-04-21 08:38:36 +01:00
|
|
|
)
|
2020-06-22 19:04:33 +01:00
|
|
|
self.config: Dict[str, ConfigOption] = config
|
2020-02-05 23:53:14 +00:00
|
|
|
self.draw()
|
2019-12-10 06:50:26 +00:00
|
|
|
except grpc.RpcError as e:
|
2020-05-03 20:42:56 +01:00
|
|
|
self.app.show_grpc_exception("Get EMANE Config Error", e)
|
2020-06-22 19:04:33 +01:00
|
|
|
self.has_error: bool = True
|
2019-12-10 06:50:26 +00:00
|
|
|
self.destroy()
|
2019-11-21 22:41:05 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2020-06-23 03:04:55 +01:00
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, self.config, self.enabled)
|
2019-11-21 22:41:05 +00:00
|
|
|
self.config_frame.draw_config()
|
2019-12-11 22:36:27 +00:00
|
|
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.draw_spacer()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.draw_buttons()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_buttons(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-07 04:49:09 +00:00
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2020-06-23 03:04:55 +01:00
|
|
|
state = tk.NORMAL if self.enabled else tk.DISABLED
|
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply, state=state)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_apply(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.config_frame.parse_config()
|
2020-06-16 17:30:16 +01:00
|
|
|
key = (self.model, self.iface_id)
|
2020-04-21 17:34:30 +01:00
|
|
|
self.canvas_node.emane_model_configs[key] = self.config
|
2019-11-21 22:41:05 +00:00
|
|
|
self.destroy()
|
2019-11-05 22:25:25 +00:00
|
|
|
|
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
class EmaneConfigDialog(Dialog):
|
2020-06-22 19:04:33 +01:00
|
|
|
def __init__(self, app: "Application", canvas_node: "CanvasNode") -> None:
|
2020-05-05 06:50:59 +01:00
|
|
|
super().__init__(app, f"{canvas_node.core_node.name} EMANE Configuration")
|
2020-06-22 19:04:33 +01:00
|
|
|
self.canvas_node: "CanvasNode" = canvas_node
|
|
|
|
self.node: Node = canvas_node.core_node
|
|
|
|
self.radiovar: tk.IntVar = tk.IntVar()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.radiovar.set(1)
|
2020-06-22 19:04:33 +01:00
|
|
|
self.emane_models: List[str] = [
|
|
|
|
x.split("_")[1] for x in self.app.core.emane_models
|
|
|
|
]
|
|
|
|
model = self.node.emane.split("_")[1]
|
|
|
|
self.emane_model: tk.StringVar = tk.StringVar(value=model)
|
|
|
|
self.emane_model_button: Optional[ttk.Button] = None
|
2020-06-23 03:04:55 +01:00
|
|
|
self.enabled: bool = not self.app.core.is_runtime()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.draw()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.draw_emane_configuration()
|
|
|
|
self.draw_emane_models()
|
|
|
|
self.draw_emane_buttons()
|
2019-12-11 22:09:50 +00:00
|
|
|
self.draw_spacer()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.draw_apply_and_cancel()
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_emane_configuration(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
"""
|
|
|
|
draw the main frame for emane configuration
|
|
|
|
"""
|
|
|
|
label = ttk.Label(
|
|
|
|
self.top,
|
2020-06-23 03:04:55 +01:00
|
|
|
text="The EMANE emulation system provides more complex wireless radio "
|
|
|
|
"emulation \nusing pluggable MAC and PHY modules. Refer to the wiki "
|
|
|
|
"for configuration option details",
|
2019-12-11 22:09:50 +00:00
|
|
|
justify=tk.CENTER,
|
2019-11-06 22:34:41 +00:00
|
|
|
)
|
2019-12-11 22:36:27 +00:00
|
|
|
label.grid(pady=PADY)
|
2019-11-06 22:34:41 +00:00
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
image = Images.get(ImageEnum.EDITNODE, 16)
|
|
|
|
button = ttk.Button(
|
|
|
|
self.top,
|
|
|
|
image=image,
|
|
|
|
text="EMANE Wiki",
|
|
|
|
compound=tk.RIGHT,
|
|
|
|
command=lambda: webbrowser.open_new(
|
|
|
|
"https://github.com/adjacentlink/emane/wiki"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
button.image = image
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(sticky="ew", pady=PADY)
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_emane_models(self) -> None:
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
create a combobox that has all the known emane models
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-12-11 22:36:27 +00:00
|
|
|
frame.grid(sticky="ew", pady=PADY)
|
2019-11-21 22:41:05 +00:00
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
label = ttk.Label(frame, text="Model")
|
|
|
|
label.grid(row=0, column=0, sticky="w")
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
# create combo box and its binding
|
2020-06-23 03:04:55 +01:00
|
|
|
state = "readonly" if self.enabled else tk.DISABLED
|
2019-11-21 22:41:05 +00:00
|
|
|
combobox = ttk.Combobox(
|
2020-06-23 03:04:55 +01:00
|
|
|
frame, textvariable=self.emane_model, values=self.emane_models, state=state
|
2019-11-05 22:25:25 +00:00
|
|
|
)
|
2019-11-21 22:41:05 +00:00
|
|
|
combobox.grid(row=0, column=1, sticky="ew")
|
|
|
|
combobox.bind("<<ComboboxSelected>>", self.emane_model_change)
|
2019-11-07 04:49:09 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_emane_buttons(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-12-11 22:36:27 +00:00
|
|
|
frame.grid(sticky="ew", pady=PADY)
|
2019-11-07 04:49:09 +00:00
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2019-11-13 01:32:34 +00:00
|
|
|
|
|
|
|
image = Images.get(ImageEnum.EDITNODE, 16)
|
2019-11-21 22:41:05 +00:00
|
|
|
self.emane_model_button = ttk.Button(
|
|
|
|
frame,
|
|
|
|
text=f"{self.emane_model.get()} options",
|
2019-11-13 01:32:34 +00:00
|
|
|
image=image,
|
2019-11-04 18:48:22 +00:00
|
|
|
compound=tk.RIGHT,
|
2019-11-21 22:41:05 +00:00
|
|
|
command=self.click_model_config,
|
2019-11-04 18:48:22 +00:00
|
|
|
)
|
2019-11-21 22:41:05 +00:00
|
|
|
self.emane_model_button.image = image
|
2019-12-11 22:36:27 +00:00
|
|
|
self.emane_model_button.grid(row=0, column=0, padx=PADX, sticky="ew")
|
2019-11-13 01:32:34 +00:00
|
|
|
|
|
|
|
image = Images.get(ImageEnum.EDITNODE, 16)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(
|
|
|
|
frame,
|
2019-11-04 18:48:22 +00:00
|
|
|
text="EMANE options",
|
2019-11-13 01:32:34 +00:00
|
|
|
image=image,
|
2019-11-04 18:48:22 +00:00
|
|
|
compound=tk.RIGHT,
|
2019-11-21 22:41:05 +00:00
|
|
|
command=self.click_emane_config,
|
2019-11-04 18:48:22 +00:00
|
|
|
)
|
2019-11-21 22:41:05 +00:00
|
|
|
button.image = image
|
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_apply_and_cancel(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2020-06-23 03:04:55 +01:00
|
|
|
state = tk.NORMAL if self.enabled else tk.DISABLED
|
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply, state=state)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, padx=PADX, sticky="ew")
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
2019-11-04 18:48:22 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_emane_config(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
dialog = GlobalEmaneDialog(self, self.app)
|
|
|
|
dialog.show()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_model_config(self) -> None:
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
draw emane model configuration
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
model_name = self.emane_model.get()
|
2020-04-21 08:38:36 +01:00
|
|
|
dialog = EmaneModelDialog(self, self.app, self.canvas_node, model_name)
|
2020-02-05 23:53:14 +00:00
|
|
|
if not dialog.has_error:
|
2020-02-05 23:09:33 +00:00
|
|
|
dialog.show()
|
2019-11-04 23:36:34 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def emane_model_change(self, event: tk.Event) -> None:
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
update emane model options button
|
2019-11-05 22:25:25 +00:00
|
|
|
"""
|
2019-11-21 22:41:05 +00:00
|
|
|
model_name = self.emane_model.get()
|
|
|
|
self.emane_model_button.config(text=f"{model_name} options")
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_apply(self) -> None:
|
2019-11-21 22:41:05 +00:00
|
|
|
self.node.emane = f"emane_{self.emane_model.get()}"
|
2019-11-05 22:25:25 +00:00
|
|
|
self.destroy()
|