2019-11-03 04:59:29 +00:00
|
|
|
"""
|
|
|
|
mobility configuration
|
|
|
|
"""
|
2019-11-21 17:40:57 +00:00
|
|
|
from tkinter import ttk
|
2020-06-22 19:04:33 +01:00
|
|
|
from typing import TYPE_CHECKING, Dict, Optional
|
2019-11-03 04:59:29 +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.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import ConfigFrame
|
2020-07-25 18:30:14 +01:00
|
|
|
from core.gui.wrappers import ConfigOption, Node
|
2019-11-21 17:40:57 +00:00
|
|
|
|
2020-01-13 23:31:41 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
|
|
|
|
2019-11-03 04:59:29 +00:00
|
|
|
|
2019-11-13 18:45:43 +00:00
|
|
|
class MobilityConfigDialog(Dialog):
|
2020-07-28 08:03:15 +01:00
|
|
|
def __init__(self, app: "Application", node: Node) -> None:
|
|
|
|
super().__init__(app, f"{node.name} Mobility Configuration")
|
|
|
|
self.node: Node = node
|
2020-06-22 19:04:33 +01:00
|
|
|
self.config_frame: Optional[ConfigFrame] = None
|
|
|
|
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.mobility_config
|
2020-06-22 19:04:33 +01:00
|
|
|
if not config:
|
|
|
|
config = self.app.core.get_mobility_config(self.node.id)
|
|
|
|
self.config: Dict[str, ConfigOption] = config
|
2020-02-05 23:09:33 +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 Mobility 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 17:40:57 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2019-11-21 17:40:57 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.top.rowconfigure(0, weight=1)
|
|
|
|
self.config_frame = ConfigFrame(self.top, self.app, self.config)
|
2019-11-21 17:40:57 +00:00
|
|
|
self.config_frame.draw_config()
|
2019-12-11 22:36:27 +00:00
|
|
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
2019-11-21 17:40:57 +00:00
|
|
|
self.draw_apply_buttons()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw_apply_buttons(self) -> None:
|
2019-11-21 17:40:57 +00:00
|
|
|
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, padx=PADX, sticky="ew")
|
2019-11-21 17:40:57 +00:00
|
|
|
|
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_apply(self) -> None:
|
2019-11-21 17:40:57 +00:00
|
|
|
self.config_frame.parse_config()
|
2020-07-28 08:03:15 +01:00
|
|
|
self.node.mobility_config = self.config
|
2019-11-03 04:59:29 +00:00
|
|
|
self.destroy()
|