display the range while configuring wlan node
This commit is contained in:
parent
d8f586bd2b
commit
23aeb40f54
3 changed files with 51 additions and 10 deletions
|
@ -1,7 +1,3 @@
|
||||||
"""
|
|
||||||
wlan configuration
|
|
||||||
"""
|
|
||||||
|
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
@ -16,6 +12,9 @@ if TYPE_CHECKING:
|
||||||
from core.gui.app import Application
|
from core.gui.app import Application
|
||||||
from core.gui.graph.node import CanvasNode
|
from core.gui.graph.node import CanvasNode
|
||||||
|
|
||||||
|
RANGE_COLOR = "#009933"
|
||||||
|
RANGE_WIDTH = 3
|
||||||
|
|
||||||
|
|
||||||
class WlanConfigDialog(Dialog):
|
class WlanConfigDialog(Dialog):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -29,14 +28,27 @@ class WlanConfigDialog(Dialog):
|
||||||
self.config_frame = None
|
self.config_frame = None
|
||||||
self.range_entry = None
|
self.range_entry = None
|
||||||
self.has_error = False
|
self.has_error = False
|
||||||
|
self.canvas = app.canvas
|
||||||
|
self.ranges = {}
|
||||||
|
self.positive_int = self.app.master.register(self.validate_and_update)
|
||||||
try:
|
try:
|
||||||
self.config = self.app.core.get_wlan_config(self.node.id)
|
self.config = self.app.core.get_wlan_config(self.node.id)
|
||||||
|
self.init_draw_range()
|
||||||
self.draw()
|
self.draw()
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
show_grpc_error(e, self.app, self.app)
|
show_grpc_error(e, self.app, self.app)
|
||||||
self.has_error = True
|
self.has_error = True
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
|
def init_draw_range(self):
|
||||||
|
if self.canvas_node.id in self.canvas.wireless_network:
|
||||||
|
for cid in self.canvas.wireless_network[self.canvas_node.id]:
|
||||||
|
x, y = self.canvas.coords(cid)
|
||||||
|
range_id = self.canvas.create_oval(
|
||||||
|
x, y, x, y, width=RANGE_WIDTH, outline=RANGE_COLOR, tags="range"
|
||||||
|
)
|
||||||
|
self.ranges[cid] = range_id
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.top.columnconfigure(0, weight=1)
|
self.top.columnconfigure(0, weight=1)
|
||||||
self.top.rowconfigure(0, weight=1)
|
self.top.rowconfigure(0, weight=1)
|
||||||
|
@ -44,6 +56,7 @@ class WlanConfigDialog(Dialog):
|
||||||
self.config_frame.draw_config()
|
self.config_frame.draw_config()
|
||||||
self.config_frame.grid(sticky="nsew", pady=PADY)
|
self.config_frame.grid(sticky="nsew", pady=PADY)
|
||||||
self.draw_apply_buttons()
|
self.draw_apply_buttons()
|
||||||
|
self.top.bind("<Destroy>", self.remove_ranges)
|
||||||
|
|
||||||
def draw_apply_buttons(self):
|
def draw_apply_buttons(self):
|
||||||
"""
|
"""
|
||||||
|
@ -57,7 +70,7 @@ class WlanConfigDialog(Dialog):
|
||||||
self.range_entry = self.config_frame.winfo_children()[0].frame.winfo_children()[
|
self.range_entry = self.config_frame.winfo_children()[0].frame.winfo_children()[
|
||||||
-1
|
-1
|
||||||
]
|
]
|
||||||
self.range_entry.bind("<Key>", self.update_range)
|
self.range_entry.config(validatecommand=(self.positive_int, "%P"))
|
||||||
|
|
||||||
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
||||||
button.grid(row=0, column=0, padx=PADX, sticky="ew")
|
button.grid(row=0, column=0, padx=PADX, sticky="ew")
|
||||||
|
@ -74,8 +87,35 @@ class WlanConfigDialog(Dialog):
|
||||||
if self.app.core.is_runtime():
|
if self.app.core.is_runtime():
|
||||||
session_id = self.app.core.session_id
|
session_id = self.app.core.session_id
|
||||||
self.app.core.client.set_wlan_config(session_id, self.node.id, config)
|
self.app.core.client.set_wlan_config(session_id, self.node.id, config)
|
||||||
|
self.remove_ranges()
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
def update_range(self, event):
|
def remove_ranges(self, event=None):
|
||||||
if event.char.isdigit():
|
for cid in self.canvas.find_withtag("range"):
|
||||||
print(self.range_entry.get() + event.char)
|
self.canvas.delete(cid)
|
||||||
|
self.ranges.clear()
|
||||||
|
|
||||||
|
def validate_and_update(self, s: str) -> bool:
|
||||||
|
"""
|
||||||
|
custom validation to also redraw the mdr ranges when the range value changes
|
||||||
|
"""
|
||||||
|
if len(s) == 0:
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
int_value = int(s)
|
||||||
|
if int_value >= 0:
|
||||||
|
net_range = int_value * self.canvas.ratio
|
||||||
|
if self.canvas_node.id in self.canvas.wireless_network:
|
||||||
|
for cid in self.canvas.wireless_network[self.canvas_node.id]:
|
||||||
|
x, y = self.canvas.coords(cid)
|
||||||
|
self.canvas.coords(
|
||||||
|
self.ranges[cid],
|
||||||
|
x - net_range,
|
||||||
|
y - net_range,
|
||||||
|
x + net_range,
|
||||||
|
y + net_range,
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
|
@ -14,6 +14,7 @@ if TYPE_CHECKING:
|
||||||
TEXT_DISTANCE = 0.30
|
TEXT_DISTANCE = 0.30
|
||||||
EDGE_WIDTH = 3
|
EDGE_WIDTH = 3
|
||||||
EDGE_COLOR = "#ff0000"
|
EDGE_COLOR = "#ff0000"
|
||||||
|
WIRELESS_COLOR = "#009933"
|
||||||
|
|
||||||
|
|
||||||
class CanvasWirelessEdge:
|
class CanvasWirelessEdge:
|
||||||
|
@ -31,7 +32,7 @@ class CanvasWirelessEdge:
|
||||||
self.dst = dst
|
self.dst = dst
|
||||||
self.canvas = canvas
|
self.canvas = canvas
|
||||||
self.id = self.canvas.create_line(
|
self.id = self.canvas.create_line(
|
||||||
*position, tags=tags.WIRELESS_EDGE, width=1.5, fill="#009933"
|
*position, tags=tags.WIRELESS_EDGE, width=EDGE_WIDTH, fill="#009933"
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
|
|
Loading…
Reference in a new issue