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
|
2023-04-13 23:53:16 +01:00
|
|
|
from typing import TYPE_CHECKING, Optional
|
2019-11-04 06:58:45 +00:00
|
|
|
|
2019-12-10 06:50:26 +00:00
|
|
|
import grpc
|
|
|
|
|
2020-08-27 19:02:02 +01:00
|
|
|
from core.api.grpc.wrappers import ConfigOption, Node
|
2021-02-19 05:04:16 +00:00
|
|
|
from core.gui import images
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.dialog import Dialog
|
2021-02-19 05:04:16 +00:00
|
|
|
from core.gui.images import ImageEnum
|
2019-12-19 17:30:21 +00:00
|
|
|
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
|
|
|
|
|
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-07-28 08:03:15 +01:00
|
|
|
node: Node,
|
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-07-28 08:03:15 +01:00
|
|
|
super().__init__(app, f"{node.name} {model} Configuration", master=master)
|
|
|
|
self.node: Node = node
|
2020-06-22 19:04:33 +01:00
|
|
|
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-07-28 08:03:15 +01:00
|
|
|
config = self.node.emane_model_configs.get((self.model, self.iface_id))
|
2022-12-09 18:29:41 +00:00
|
|
|
if not config:
|
|
|
|
config = self.node.emane_model_configs.get((self.model, None))
|
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
|
|
|
)
|
2023-04-13 23:53:16 +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()
|
2020-08-02 18:36:14 +01:00
|
|
|
self.config_frame.grid(sticky=tk.NSEW, pady=PADY)
|
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)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW)
|
2019-11-07 04:49:09 +00:00
|
|
|
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)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=0, sticky=tk.EW, padx=PADX)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=1, sticky=tk.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-07-28 08:03:15 +01:00
|
|
|
self.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-07-28 08:03:15 +01:00
|
|
|
def __init__(self, app: "Application", node: Node) -> None:
|
|
|
|
super().__init__(app, f"{node.name} EMANE Configuration")
|
|
|
|
self.node: Node = node
|
2020-06-22 19:04:33 +01:00
|
|
|
self.radiovar: tk.IntVar = tk.IntVar()
|
2019-11-21 22:41:05 +00:00
|
|
|
self.radiovar.set(1)
|
2023-04-13 23:53:16 +01:00
|
|
|
self.emane_models: list[str] = [
|
2021-05-07 21:10:05 +01:00
|
|
|
x.split("_")[1] for x in self.app.core.emane_models
|
2020-06-22 19:04:33 +01:00
|
|
|
]
|
2021-05-29 06:18:13 +01:00
|
|
|
model = self.node.emane.split("_")[1]
|
2020-06-22 19:04:33 +01:00
|
|
|
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
|
|
|
|
2021-02-19 05:04:16 +00:00
|
|
|
image = images.from_enum(ImageEnum.EDITNODE, width=images.BUTTON_SIZE)
|
2019-11-21 22:41:05 +00:00
|
|
|
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
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(sticky=tk.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)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW, pady=PADY)
|
2019-11-21 22:41:05 +00:00
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
label = ttk.Label(frame, text="Model")
|
2020-08-02 18:36:14 +01:00
|
|
|
label.grid(row=0, column=0, sticky=tk.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
|
|
|
)
|
2020-08-02 18:36:14 +01:00
|
|
|
combobox.grid(row=0, column=1, sticky=tk.EW)
|
2019-11-21 22:41:05 +00:00
|
|
|
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)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW, pady=PADY)
|
2021-05-20 20:24:54 +01:00
|
|
|
frame.columnconfigure(0, weight=1)
|
2021-02-19 05:04:16 +00:00
|
|
|
image = images.from_enum(ImageEnum.EDITNODE, width=images.BUTTON_SIZE)
|
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
|
2021-05-20 20:24:54 +01:00
|
|
|
self.emane_model_button.grid(padx=PADX, sticky=tk.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)
|
2020-08-02 18:36:14 +01:00
|
|
|
frame.grid(sticky=tk.EW)
|
2019-11-21 22:41:05 +00:00
|
|
|
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)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=0, padx=PADX, sticky=tk.EW)
|
2019-11-21 22:41:05 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2020-08-02 18:36:14 +01:00
|
|
|
button.grid(row=0, column=1, sticky=tk.EW)
|
2019-11-04 18:48:22 +00:00
|
|
|
|
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-07-28 08:03:15 +01:00
|
|
|
dialog = EmaneModelDialog(self, self.app, self.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()
|