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-01-15 20:59:54 +00:00
|
|
|
from typing import TYPE_CHECKING, Any
|
2019-11-04 06:58:45 +00:00
|
|
|
|
2019-12-10 06:50:26 +00:00
|
|
|
import grpc
|
|
|
|
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
|
|
|
from core.gui.errors import show_grpc_error
|
|
|
|
from core.gui.images import ImageEnum, Images
|
|
|
|
from core.gui.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import ConfigFrame
|
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-01-14 19:06:52 +00:00
|
|
|
def __init__(self, master: Any, app: "Application"):
|
2019-11-21 22:41:05 +00:00
|
|
|
super().__init__(master, app, "EMANE Configuration", modal=True)
|
|
|
|
self.config_frame = None
|
|
|
|
self.draw()
|
2019-11-04 18:48:22 +00:00
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw(self):
|
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, self.app.core.emane_config)
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw_buttons(self):
|
|
|
|
frame = ttk.Frame(self.top)
|
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
2019-11-05 22:25:25 +00:00
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def click_apply(self):
|
|
|
|
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-01-14 19:06:52 +00:00
|
|
|
master: Any,
|
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-01-15 20:59:54 +00:00
|
|
|
interface: int = None,
|
2020-01-13 23:31:41 +00:00
|
|
|
):
|
2020-04-21 08:38:36 +01:00
|
|
|
super().__init__(
|
|
|
|
master,
|
|
|
|
app,
|
|
|
|
f"{canvas_node.core_node.name} {model} Configuration",
|
|
|
|
modal=True,
|
|
|
|
)
|
|
|
|
self.canvas_node = canvas_node
|
|
|
|
self.node = canvas_node.core_node
|
2019-11-21 22:41:05 +00:00
|
|
|
self.model = f"emane_{model}"
|
2019-11-22 00:41:38 +00:00
|
|
|
self.interface = interface
|
2019-11-21 22:41:05 +00:00
|
|
|
self.config_frame = None
|
2020-02-05 23:53:14 +00:00
|
|
|
self.has_error = False
|
2019-12-10 06:50:26 +00:00
|
|
|
try:
|
2020-04-21 08:38:36 +01:00
|
|
|
self.config = self.canvas_node.emane_model_configs.get(
|
|
|
|
(self.model, self.interface)
|
2019-12-10 06:50:26 +00:00
|
|
|
)
|
2020-04-21 08:38:36 +01:00
|
|
|
if not self.config:
|
|
|
|
self.config = self.app.core.get_emane_model_config(
|
|
|
|
self.node.id, self.model, self.interface
|
|
|
|
)
|
2020-02-05 23:53:14 +00:00
|
|
|
self.draw()
|
2019-12-10 06:50:26 +00:00
|
|
|
except grpc.RpcError as e:
|
2020-02-05 23:09:33 +00:00
|
|
|
show_grpc_error(e, self.app, self.app)
|
2020-02-05 23:53:14 +00:00
|
|
|
self.has_error = True
|
2019-12-10 06:50:26 +00:00
|
|
|
self.destroy()
|
2019-11-21 22:41:05 +00:00
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, self.config)
|
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()
|
|
|
|
|
|
|
|
def draw_buttons(self):
|
|
|
|
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)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
2019-11-05 22:25:25 +00:00
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def click_apply(self):
|
|
|
|
self.config_frame.parse_config()
|
2020-04-21 08:38:36 +01:00
|
|
|
key = (self.model, self.interface)
|
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-01-14 19:06:52 +00:00
|
|
|
def __init__(
|
|
|
|
self, master: "Application", app: "Application", canvas_node: "CanvasNode"
|
|
|
|
):
|
2019-11-21 22:41:05 +00:00
|
|
|
super().__init__(
|
|
|
|
master, app, f"{canvas_node.core_node.name} EMANE Configuration", modal=True
|
2019-11-05 22:25:25 +00:00
|
|
|
)
|
2019-11-21 22:41:05 +00:00
|
|
|
self.app = app
|
|
|
|
self.canvas_node = canvas_node
|
|
|
|
self.node = canvas_node.core_node
|
|
|
|
self.radiovar = tk.IntVar()
|
|
|
|
self.radiovar.set(1)
|
|
|
|
self.emane_models = [x.split("_")[1] for x in self.app.core.emane_models]
|
2019-11-25 23:40:09 +00:00
|
|
|
self.emane_model = tk.StringVar(value=self.node.emane.split("_")[1])
|
2019-11-21 22:41:05 +00:00
|
|
|
self.emane_model_button = None
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw_emane_configuration(self):
|
|
|
|
"""
|
|
|
|
draw the main frame for emane configuration
|
|
|
|
"""
|
|
|
|
label = ttk.Label(
|
|
|
|
self.top,
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw_emane_models(self):
|
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
|
|
|
|
combobox = ttk.Combobox(
|
|
|
|
frame,
|
|
|
|
textvariable=self.emane_model,
|
|
|
|
values=self.emane_models,
|
|
|
|
state="readonly",
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw_emane_buttons(self):
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def draw_apply_and_cancel(self):
|
|
|
|
frame = ttk.Frame(self.top)
|
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2019-11-05 22:25:25 +00:00
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
2019-12-11 22:36:27 +00:00
|
|
|
button.grid(row=0, column=0, padx=PADX, sticky="ew")
|
2019-11-05 22:25:25 +00:00
|
|
|
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def click_emane_config(self):
|
|
|
|
dialog = GlobalEmaneDialog(self, self.app)
|
|
|
|
dialog.show()
|
|
|
|
|
|
|
|
def click_model_config(self):
|
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-01-13 20:03:13 +00:00
|
|
|
def emane_model_change(self, event: tk.Event):
|
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
|
|
|
|
2019-11-21 22:41:05 +00:00
|
|
|
def click_apply(self):
|
|
|
|
self.node.emane = f"emane_{self.emane_model.get()}"
|
2019-11-05 22:25:25 +00:00
|
|
|
self.destroy()
|