2019-10-30 20:33:22 +00:00
|
|
|
"""
|
|
|
|
wlan configuration
|
|
|
|
"""
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
from tkinter import ttk
|
2020-01-13 23:31:41 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2019-10-30 20:33:22 +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.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import ConfigFrame
|
2019-11-21 07:16:04 +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-10-30 20:33:22 +00:00
|
|
|
|
2019-11-05 01:18:59 +00:00
|
|
|
class WlanConfigDialog(Dialog):
|
2020-01-13 23:31:41 +00:00
|
|
|
def __init__(self, master, app: "Application", canvas_node: "CanvasNode"):
|
2019-11-05 01:18:59 +00:00
|
|
|
super().__init__(
|
2019-11-20 18:59:30 +00:00
|
|
|
master, app, f"{canvas_node.core_node.name} Wlan Configuration", modal=True
|
2019-11-05 01:18:59 +00:00
|
|
|
)
|
2019-10-30 20:33:22 +00:00
|
|
|
self.canvas_node = canvas_node
|
2019-11-20 18:59:30 +00:00
|
|
|
self.node = canvas_node.core_node
|
2019-11-21 07:16:04 +00:00
|
|
|
self.config_frame = None
|
2019-12-10 06:50:26 +00:00
|
|
|
try:
|
|
|
|
self.config = self.app.core.get_wlan_config(self.node.id)
|
|
|
|
except grpc.RpcError as e:
|
|
|
|
show_grpc_error(e)
|
|
|
|
self.destroy()
|
2019-11-05 01:18:59 +00:00
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
2019-11-13 18:45:43 +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 07:16:04 +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-05 01:18:59 +00:00
|
|
|
self.draw_apply_buttons()
|
|
|
|
|
|
|
|
def draw_apply_buttons(self):
|
2019-11-01 15:35:14 +00:00
|
|
|
"""
|
2019-11-05 01:18:59 +00:00
|
|
|
create node configuration options
|
2019-11-01 15:35:14 +00:00
|
|
|
"""
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-05 01:18:59 +00:00
|
|
|
frame.grid(sticky="ew")
|
|
|
|
for i in range(2):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +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-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2019-11-21 07:16:04 +00:00
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
2019-11-05 01:18:59 +00:00
|
|
|
|
|
|
|
def click_apply(self):
|
|
|
|
"""
|
|
|
|
retrieve user's wlan configuration and store the new configuration values
|
|
|
|
"""
|
2019-12-16 22:55:54 +00:00
|
|
|
config = self.config_frame.parse_config()
|
2019-11-21 07:16:04 +00:00
|
|
|
self.app.core.wlan_configs[self.node.id] = self.config
|
2019-12-16 22:55:54 +00:00
|
|
|
if self.app.core.is_runtime():
|
|
|
|
session_id = self.app.core.session_id
|
|
|
|
self.app.core.client.set_wlan_config(session_id, self.node.id, config)
|
2019-11-05 01:18:59 +00:00
|
|
|
self.destroy()
|