updated wlan config dialog to use common dialog class
This commit is contained in:
parent
c5d5226384
commit
22601a4580
2 changed files with 139 additions and 237 deletions
|
@ -6,7 +6,7 @@ canvas graph action
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
||||||
from coretk.dialogs.wlanconfig import WlanConfiguration
|
from coretk.dialogs.wlanconfig import WlanConfigDialog
|
||||||
|
|
||||||
# TODO, finish classifying node types
|
# TODO, finish classifying node types
|
||||||
NODE_TO_TYPE = {
|
NODE_TO_TYPE = {
|
||||||
|
@ -36,8 +36,11 @@ class CanvasAction:
|
||||||
|
|
||||||
def display_wlan_configuration(self, canvas_node):
|
def display_wlan_configuration(self, canvas_node):
|
||||||
# print(self.canvas.grpc_manager.wlanconfig_management.configurations)
|
# print(self.canvas.grpc_manager.wlanconfig_management.configurations)
|
||||||
wlan_config = self.canvas.grpc_manager.wlanconfig_management.configurations[
|
wlan_config = self.master.core.wlanconfig_management.configurations[
|
||||||
canvas_node.core_id
|
canvas_node.core_id
|
||||||
]
|
]
|
||||||
WlanConfiguration(self.canvas, self.node_to_show_config, wlan_config)
|
dialog = WlanConfigDialog(
|
||||||
|
self.master, self.master, self.node_to_show_config, wlan_config
|
||||||
|
)
|
||||||
|
dialog.show()
|
||||||
self.node_to_show_config = None
|
self.node_to_show_config = None
|
||||||
|
|
|
@ -3,294 +3,193 @@ wlan configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.dialogs.nodeicon import NodeIconDialog
|
from coretk.dialogs.nodeicon import NodeIconDialog
|
||||||
|
|
||||||
|
|
||||||
class WlanConfiguration:
|
class WlanConfigDialog(Dialog):
|
||||||
def __init__(self, canvas, canvas_node, config):
|
def __init__(self, master, app, canvas_node, config):
|
||||||
"""
|
"""
|
||||||
create an instance of WlanConfiguration
|
create an instance of WlanConfiguration
|
||||||
|
|
||||||
:param coretk.grpah.CanvasGraph canvas: canvas object
|
:param coretk.grpah.CanvasGraph canvas: canvas object
|
||||||
:param coretk.graph.CanvasNode canvas_node: canvas node object
|
:param coretk.graph.CanvasNode canvas_node: canvas node object
|
||||||
"""
|
"""
|
||||||
|
super().__init__(
|
||||||
self.canvas = canvas
|
master, app, f"{canvas_node.name} Wlan Configuration", modal=True
|
||||||
|
)
|
||||||
self.image = canvas_node.image
|
self.image = canvas_node.image
|
||||||
self.node_type = canvas_node.node_type
|
|
||||||
self.name = canvas_node.name
|
|
||||||
self.canvas_node = canvas_node
|
self.canvas_node = canvas_node
|
||||||
|
|
||||||
self.top = tk.Toplevel()
|
|
||||||
self.top.title("wlan configuration")
|
|
||||||
self.node_name = tk.StringVar()
|
|
||||||
|
|
||||||
# self.range_var = tk.DoubleVar()
|
|
||||||
# self.range_var.set(275.0)
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.range_var = tk.StringVar()
|
self.name = tk.StringVar(value=canvas_node.name)
|
||||||
self.range_var.set(config["basic_range"])
|
self.range_var = tk.StringVar(value=config["basic_range"])
|
||||||
# self.bandwidth_var = tk.IntVar()
|
self.bandwidth_var = tk.StringVar(value=config["bandwidth"])
|
||||||
self.bandwidth_var = tk.StringVar()
|
self.delay_var = tk.StringVar(value=config["delay"])
|
||||||
self.bandwidth_var.set(config["bandwidth"])
|
self.loss_var = tk.StringVar(value=config["error"])
|
||||||
|
self.jitter_var = tk.StringVar(value=config["jitter"])
|
||||||
|
self.ip4_subnet = tk.StringVar()
|
||||||
|
self.ip6_subnet = tk.StringVar()
|
||||||
|
self.image_button = None
|
||||||
|
self.draw()
|
||||||
|
|
||||||
self.delay_var = tk.StringVar()
|
def draw(self):
|
||||||
|
self.columnconfigure(0, weight=1)
|
||||||
|
self.draw_name_config()
|
||||||
|
self.draw_wlan_config()
|
||||||
|
self.draw_subnet()
|
||||||
|
self.draw_wlan_buttons()
|
||||||
|
self.draw_apply_buttons()
|
||||||
|
|
||||||
self.image_modification()
|
def draw_name_config(self):
|
||||||
self.wlan_configuration()
|
|
||||||
self.subnet()
|
|
||||||
self.wlan_options()
|
|
||||||
self.config_option()
|
|
||||||
|
|
||||||
def image_modification(self):
|
|
||||||
"""
|
"""
|
||||||
draw image modification part
|
draw image modification part
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
f = tk.Frame(self.top, bg="#d9d9d9")
|
frame = tk.Frame(self)
|
||||||
lbl = tk.Label(f, text="Node name: ", bg="#d9d9d9")
|
frame.grid(pady=2, sticky="ew")
|
||||||
lbl.grid(row=0, column=0, padx=3, pady=3)
|
frame.columnconfigure(0, weight=1)
|
||||||
e = tk.Entry(f, textvariable=self.node_name, bg="white")
|
|
||||||
e.grid(row=0, column=1, padx=3, pady=3)
|
|
||||||
b = tk.Button(f, text="None")
|
|
||||||
b.grid(row=0, column=2, padx=3, pady=3)
|
|
||||||
b = tk.Button(f, image=self.image, command=lambda: self.click_image)
|
|
||||||
b.grid(row=0, column=3, padx=3, pady=3)
|
|
||||||
f.grid(padx=2, pady=2, ipadx=2, ipady=2)
|
|
||||||
|
|
||||||
def click_image(self):
|
entry = tk.Entry(frame, textvariable=self.name, bg="white")
|
||||||
NodeIconDialog(self.app, canvas_node=self.canvas_node, node_config=self)
|
entry.grid(row=0, column=0, padx=2, sticky="ew")
|
||||||
|
|
||||||
def create_string_var(self, val):
|
self.image_button = tk.Button(frame, image=self.image, command=self.click_icon)
|
||||||
"""
|
self.image_button.grid(row=0, column=1, padx=3)
|
||||||
create string variable for convenience
|
|
||||||
|
|
||||||
:param str val: text value
|
def draw_wlan_config(self):
|
||||||
:return: nothing
|
|
||||||
"""
|
|
||||||
v = tk.StringVar()
|
|
||||||
v.set(val)
|
|
||||||
return v
|
|
||||||
|
|
||||||
def scrollbar_command(self, entry_widget, delta, event):
|
|
||||||
"""
|
|
||||||
change text in entry based on scrollbar action (click up or down)
|
|
||||||
|
|
||||||
:param tkinter.Entry entry_widget: entry needed for changing text
|
|
||||||
:param int or float delta: the amount to change
|
|
||||||
:param event: scrollbar event
|
|
||||||
:return: nothing
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
value = int(entry_widget.get())
|
|
||||||
except ValueError:
|
|
||||||
value = float(entry_widget.get())
|
|
||||||
entry_widget.delete(0, tk.END)
|
|
||||||
if event == "-1":
|
|
||||||
entry_widget.insert(tk.END, str(round(value + delta, 1)))
|
|
||||||
elif event == "1":
|
|
||||||
entry_widget.insert(tk.END, str(round(value - delta, 1)))
|
|
||||||
|
|
||||||
def wlan_configuration(self):
|
|
||||||
"""
|
"""
|
||||||
create wireless configuration table
|
create wireless configuration table
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
lbl = tk.Label(self.top, text="Wireless")
|
label = tk.Label(self, text="Wireless")
|
||||||
lbl.grid(sticky=tk.W, padx=3, pady=3)
|
label.grid(sticky="w", pady=2)
|
||||||
|
|
||||||
f = tk.Frame(
|
frame = tk.Frame(self)
|
||||||
self.top,
|
frame.grid(pady=2, sticky="ew")
|
||||||
highlightbackground="#b3b3b3",
|
for i in range(2):
|
||||||
highlightcolor="#b3b3b3",
|
frame.columnconfigure(i, weight=1)
|
||||||
highlightthickness=0.5,
|
|
||||||
bd=0,
|
label = tk.Label(
|
||||||
bg="#d9d9d9",
|
frame,
|
||||||
|
text=(
|
||||||
|
"The basic range model calculates on/off "
|
||||||
|
"connectivity based on pixel distance between nodes."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
label.grid(row=0, columnspan=2, pady=2, sticky="ew")
|
||||||
|
|
||||||
lbl = tk.Label(
|
label = tk.Label(frame, text="Range")
|
||||||
f,
|
label.grid(row=1, column=0, sticky="w")
|
||||||
text="The basic range model calculates on/off connectivity based on pixel distance between nodes.",
|
entry = tk.Entry(frame, textvariable=self.range_var)
|
||||||
bg="#d9d9d9",
|
entry.grid(row=1, column=1, sticky="ew")
|
||||||
)
|
|
||||||
lbl.grid(padx=4, pady=4)
|
|
||||||
|
|
||||||
f1 = tk.Frame(f, bg="#d9d9d9")
|
label = tk.Label(frame, text="Bandwidth (bps)")
|
||||||
|
label.grid(row=2, column=0, sticky="w")
|
||||||
|
entry = tk.Entry(frame, textvariable=self.bandwidth_var)
|
||||||
|
entry.grid(row=2, column=1, sticky="ew")
|
||||||
|
|
||||||
lbl = tk.Label(f1, text="Range: ", bg="#d9d9d9")
|
label = tk.Label(frame, text="Delay (us)")
|
||||||
lbl.grid(row=0, column=0)
|
label.grid(row=3, column=0, sticky="w")
|
||||||
|
entry = tk.Entry(frame, textvariable=self.delay_var)
|
||||||
|
entry.grid(row=3, column=1, sticky="ew")
|
||||||
|
|
||||||
e = tk.Entry(
|
label = tk.Label(frame, text="Loss (%)")
|
||||||
f1,
|
label.grid(row=4, column=0, sticky="w")
|
||||||
textvariable=self.create_string_var(self.config["basic_range"]),
|
entry = tk.Entry(frame, textvariable=self.loss_var)
|
||||||
width=5,
|
entry.grid(row=4, column=1, sticky="ew")
|
||||||
bg="white",
|
|
||||||
)
|
|
||||||
e.grid(row=0, column=1)
|
|
||||||
|
|
||||||
lbl = tk.Label(f1, text="Bandwidth (bps): ", bg="#d9d9d9")
|
label = tk.Label(frame, text="Jitter (us)")
|
||||||
lbl.grid(row=0, column=2)
|
label.grid(row=5, column=0, sticky="w")
|
||||||
|
entry = tk.Entry(frame, textvariable=self.jitter_var)
|
||||||
|
entry.grid(row=5, column=1, sticky="ew")
|
||||||
|
|
||||||
f11 = tk.Frame(f1, bg="#d9d9d9")
|
def draw_subnet(self):
|
||||||
sb = tk.Scrollbar(f11, orient=tk.VERTICAL)
|
|
||||||
e = tk.Entry(
|
|
||||||
f11,
|
|
||||||
textvariable=self.create_string_var(self.config["bandwidth"]),
|
|
||||||
width=10,
|
|
||||||
bg="white",
|
|
||||||
)
|
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 1000000))
|
|
||||||
e.grid()
|
|
||||||
sb.grid(row=0, column=1)
|
|
||||||
f11.grid(row=0, column=3)
|
|
||||||
|
|
||||||
# e = tk.Entry(f1, textvariable=self.bandwidth_var, width=10)
|
|
||||||
# e.grid(row=0, column=4)
|
|
||||||
f1.grid(sticky=tk.W, padx=4, pady=4)
|
|
||||||
|
|
||||||
f2 = tk.Frame(f, bg="#d9d9d9")
|
|
||||||
lbl = tk.Label(f2, text="Delay (us): ", bg="#d9d9d9")
|
|
||||||
lbl.grid(row=0, column=0)
|
|
||||||
|
|
||||||
f21 = tk.Frame(f2, bg="#d9d9d9")
|
|
||||||
sb = tk.Scrollbar(f21, orient=tk.VERTICAL)
|
|
||||||
e = tk.Entry(
|
|
||||||
f21, textvariable=self.create_string_var(self.config["delay"]), bg="white"
|
|
||||||
)
|
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
|
||||||
e.grid()
|
|
||||||
sb.grid(row=0, column=1)
|
|
||||||
f21.grid(row=0, column=1)
|
|
||||||
|
|
||||||
lbl = tk.Label(f2, text="Loss (%): ", bg="#d9d9d9")
|
|
||||||
lbl.grid(row=0, column=2)
|
|
||||||
|
|
||||||
f22 = tk.Frame(f2, bg="#d9d9d9")
|
|
||||||
sb = tk.Scrollbar(f22, orient=tk.VERTICAL)
|
|
||||||
e = tk.Entry(
|
|
||||||
f22, textvariable=self.create_string_var(self.config["error"]), bg="white"
|
|
||||||
)
|
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 0.1))
|
|
||||||
e.grid()
|
|
||||||
sb.grid(row=0, column=1)
|
|
||||||
f22.grid(row=0, column=3)
|
|
||||||
|
|
||||||
# e = tk.Entry(f2, textvariable=self.create_string_var(0))
|
|
||||||
# e.grid(row=0, column=3)
|
|
||||||
f2.grid(sticky=tk.W, padx=4, pady=4)
|
|
||||||
|
|
||||||
f3 = tk.Frame(f, bg="#d9d9d9")
|
|
||||||
lbl = tk.Label(f3, text="Jitter (us): ", bg="#d9d9d9")
|
|
||||||
lbl.grid()
|
|
||||||
f31 = tk.Frame(f3, bg="#d9d9d9")
|
|
||||||
sb = tk.Scrollbar(f31, orient=tk.VERTICAL)
|
|
||||||
e = tk.Entry(
|
|
||||||
f31, textvariable=self.create_string_var(self.config["jitter"]), bg="white"
|
|
||||||
)
|
|
||||||
sb.config(command=partial(self.scrollbar_command, e, 5000))
|
|
||||||
e.grid()
|
|
||||||
sb.grid(row=0, column=1)
|
|
||||||
f31.grid(row=0, column=1)
|
|
||||||
|
|
||||||
f3.grid(sticky=tk.W, padx=4, pady=4)
|
|
||||||
f.grid(padx=3, pady=3)
|
|
||||||
|
|
||||||
def subnet(self):
|
|
||||||
"""
|
"""
|
||||||
create the entries for ipv4 subnet and ipv6 subnet
|
create the entries for ipv4 subnet and ipv6 subnet
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
f = tk.Frame(self.top)
|
frame = tk.Frame(self)
|
||||||
f1 = tk.Frame(f)
|
frame.grid(pady=3, sticky="ew")
|
||||||
lbl = tk.Label(f1, text="IPv4 subnet")
|
frame.columnconfigure(1, weight=1)
|
||||||
lbl.grid()
|
frame.columnconfigure(3, weight=1)
|
||||||
e = tk.Entry(f1, width=30, bg="white", textvariable=self.create_string_var(""))
|
|
||||||
e.grid(row=0, column=1)
|
|
||||||
f1.grid()
|
|
||||||
|
|
||||||
f2 = tk.Frame(f)
|
label = tk.Label(frame, text="IPv4 Subnet")
|
||||||
lbl = tk.Label(f2, text="IPv6 subnet")
|
label.grid(row=0, column=0, sticky="w")
|
||||||
lbl.grid()
|
entry = tk.Entry(frame, textvariable=self.ip4_subnet)
|
||||||
e = tk.Entry(f2, width=30, bg="white", textvariable=self.create_string_var(""))
|
entry.grid(row=0, column=1, sticky="ew")
|
||||||
e.grid(row=0, column=1)
|
|
||||||
f2.grid()
|
|
||||||
f.grid(sticky=tk.W, padx=3, pady=3)
|
|
||||||
|
|
||||||
def wlan_options(self):
|
label = tk.Label(frame, text="IPv6 Subnet")
|
||||||
|
label.grid(row=0, column=2, sticky="w")
|
||||||
|
entry = tk.Entry(frame, textvariable=self.ip6_subnet)
|
||||||
|
entry.grid(row=0, column=3, sticky="ew")
|
||||||
|
|
||||||
|
def draw_wlan_buttons(self):
|
||||||
"""
|
"""
|
||||||
create wireless node options
|
create wireless node options
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
f = tk.Frame(self.top)
|
frame = tk.Frame(self)
|
||||||
b = tk.Button(f, text="ns-2 mobility script...")
|
frame.grid(pady=2, sticky="ew")
|
||||||
b.pack(side=tk.LEFT, padx=1)
|
for i in range(3):
|
||||||
b = tk.Button(f, text="Link to all routers")
|
frame.columnconfigure(i, weight=1)
|
||||||
b.pack(side=tk.LEFT, padx=1)
|
|
||||||
b = tk.Button(f, text="Choose WLAN members")
|
|
||||||
b.pack(side=tk.LEFT, padx=1)
|
|
||||||
f.grid(sticky=tk.W)
|
|
||||||
|
|
||||||
def wlan_config_apply(self):
|
button = tk.Button(frame, text="ns-2 mobility script...")
|
||||||
"""
|
button.grid(row=0, column=0, padx=2, sticky="ew")
|
||||||
retrieve user's wlan configuration and store the new configuration values
|
|
||||||
|
|
||||||
:return: nothing
|
button = tk.Button(frame, text="Link to all routers")
|
||||||
"""
|
button.grid(row=0, column=1, padx=2, sticky="ew")
|
||||||
config_frame = self.top.grid_slaves(row=2, column=0)[0]
|
|
||||||
range_and_bandwidth_frame = config_frame.grid_slaves(row=1, column=0)[0]
|
|
||||||
range_val = range_and_bandwidth_frame.grid_slaves(row=0, column=1)[0].get()
|
|
||||||
bandwidth = (
|
|
||||||
range_and_bandwidth_frame.grid_slaves(row=0, column=3)[0]
|
|
||||||
.grid_slaves(row=0, column=0)[0]
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
|
|
||||||
delay_and_loss_frame = config_frame.grid_slaves(row=2, column=0)[0]
|
button = tk.Button(frame, text="Choose WLAN members")
|
||||||
delay = (
|
button.grid(row=0, column=2, padx=2, sticky="ew")
|
||||||
delay_and_loss_frame.grid_slaves(row=0, column=1)[0]
|
|
||||||
.grid_slaves(row=0, column=0)[0]
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
loss = (
|
|
||||||
delay_and_loss_frame.grid_slaves(row=0, column=3)[0]
|
|
||||||
.grid_slaves(row=0, column=0)[0]
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
|
|
||||||
jitter_frame = config_frame.grid_slaves(row=3, column=0)[0]
|
def draw_apply_buttons(self):
|
||||||
jitter_val = (
|
|
||||||
jitter_frame.grid_slaves(row=0, column=1)[0]
|
|
||||||
.grid_slaves(row=0, column=0)[0]
|
|
||||||
.get()
|
|
||||||
)
|
|
||||||
|
|
||||||
# set wireless node configuration here
|
|
||||||
wlanconfig_manager = self.canvas.grpc_manager.wlanconfig_management
|
|
||||||
wlanconfig_manager.set_custom_config(
|
|
||||||
node_id=self.canvas_node.core_id,
|
|
||||||
range=range_val,
|
|
||||||
bandwidth=bandwidth,
|
|
||||||
jitter=jitter_val,
|
|
||||||
delay=delay,
|
|
||||||
error=loss,
|
|
||||||
)
|
|
||||||
self.top.destroy()
|
|
||||||
|
|
||||||
def config_option(self):
|
|
||||||
"""
|
"""
|
||||||
create node configuration options
|
create node configuration options
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
f = tk.Frame(self.top, bg="#d9d9d9")
|
frame = tk.Frame(self)
|
||||||
b = tk.Button(f, text="Apply", bg="#d9d9d9", command=self.wlan_config_apply)
|
frame.grid(sticky="ew")
|
||||||
b.grid(padx=2, pady=2)
|
for i in range(2):
|
||||||
b = tk.Button(f, text="Cancel", bg="#d9d9d9", command=self.top.destroy)
|
frame.columnconfigure(i, weight=1)
|
||||||
b.grid(row=0, column=1, padx=2, pady=2)
|
|
||||||
f.grid(padx=4, pady=4)
|
button = tk.Button(frame, text="Apply", command=self.click_apply)
|
||||||
|
button.grid(row=0, column=0, padx=2, sticky="ew")
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
|
button.grid(row=0, column=1, padx=2, sticky="ew")
|
||||||
|
|
||||||
|
def click_icon(self):
|
||||||
|
dialog = NodeIconDialog(self, self.app, self.canvas_node)
|
||||||
|
dialog.show()
|
||||||
|
if dialog.image:
|
||||||
|
self.image = dialog.image
|
||||||
|
self.image_button.config(image=self.image)
|
||||||
|
|
||||||
|
def click_apply(self):
|
||||||
|
"""
|
||||||
|
retrieve user's wlan configuration and store the new configuration values
|
||||||
|
|
||||||
|
:return: nothing
|
||||||
|
"""
|
||||||
|
basic_range = self.range_var.get()
|
||||||
|
bandwidth = self.bandwidth_var.get()
|
||||||
|
delay = self.delay_var.get()
|
||||||
|
loss = self.loss_var.get()
|
||||||
|
jitter = self.jitter_var.get()
|
||||||
|
|
||||||
|
# set wireless node configuration here
|
||||||
|
wlanconfig_manager = self.app.core.wlanconfig_management
|
||||||
|
wlanconfig_manager.set_custom_config(
|
||||||
|
node_id=self.canvas_node.core_id,
|
||||||
|
range=basic_range,
|
||||||
|
bandwidth=bandwidth,
|
||||||
|
jitter=jitter,
|
||||||
|
delay=delay,
|
||||||
|
error=loss,
|
||||||
|
)
|
||||||
|
self.destroy()
|
||||||
|
|
Loading…
Add table
Reference in a new issue