update node service dialog to use common dialog class
This commit is contained in:
parent
d4f77a01e3
commit
22a55b69d3
2 changed files with 122 additions and 102 deletions
|
@ -3,7 +3,7 @@ from tkinter import ttk
|
||||||
|
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.dialogs.nodeicon import NodeIconDialog
|
from coretk.dialogs.nodeicon import NodeIconDialog
|
||||||
from coretk.dialogs.nodeservice import NodeServices
|
from coretk.dialogs.nodeservice import NodeServicesDialog
|
||||||
|
|
||||||
NETWORKNODETYPES = ["switch", "hub", "wlan", "rj45", "tunnel"]
|
NETWORKNODETYPES = ["switch", "hub", "wlan", "rj45", "tunnel"]
|
||||||
DEFAULTNODES = ["router", "host", "PC"]
|
DEFAULTNODES = ["router", "host", "PC"]
|
||||||
|
@ -56,7 +56,7 @@ class NodeConfigDialog(Dialog):
|
||||||
frame.columnconfigure(0, weight=1)
|
frame.columnconfigure(0, weight=1)
|
||||||
frame.columnconfigure(1, weight=1)
|
frame.columnconfigure(1, weight=1)
|
||||||
|
|
||||||
button = tk.Button(frame, text="Services", command=lambda: NodeServices())
|
button = tk.Button(frame, text="Services", command=self.click_services)
|
||||||
button.grid(row=0, column=0, padx=2, sticky="ew")
|
button.grid(row=0, column=0, padx=2, sticky="ew")
|
||||||
|
|
||||||
self.image_button = tk.Button(
|
self.image_button = tk.Button(
|
||||||
|
@ -80,6 +80,10 @@ class NodeConfigDialog(Dialog):
|
||||||
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
button.grid(row=0, column=1, sticky="ew")
|
button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
|
def click_services(self):
|
||||||
|
dialog = NodeServicesDialog(self, self.app, self.canvas_node)
|
||||||
|
dialog.show()
|
||||||
|
|
||||||
def click_icon(self):
|
def click_icon(self):
|
||||||
dialog = NodeIconDialog(self, self.app, self.canvas_node)
|
dialog = NodeIconDialog(self, self.app, self.canvas_node)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
|
@ -4,6 +4,8 @@ core node services
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
|
||||||
CORE_DEFAULT_GROUPS = ["EMANE", "FRR", "ProtoSvc", "Quagga", "Security", "Utility"]
|
CORE_DEFAULT_GROUPS = ["EMANE", "FRR", "ProtoSvc", "Quagga", "Security", "Utility"]
|
||||||
DEFAULT_GROUP_RADIO_VALUE = {
|
DEFAULT_GROUP_RADIO_VALUE = {
|
||||||
"EMANE": 1,
|
"EMANE": 1,
|
||||||
|
@ -57,35 +59,28 @@ DEFAULT_GROUP_SERVICES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NodeServices:
|
class NodeServicesDialog(Dialog):
|
||||||
def __init__(self):
|
def __init__(self, master, app, canvas_node):
|
||||||
|
super().__init__(master, app, "Node Services", modal=True)
|
||||||
|
self.canvas_node = canvas_node
|
||||||
self.core_groups = []
|
self.core_groups = []
|
||||||
self.service_to_config = None
|
self.service_to_config = None
|
||||||
|
self.config_frame = None
|
||||||
|
self.draw()
|
||||||
|
|
||||||
self.top = tk.Toplevel()
|
def draw(self):
|
||||||
self.top.title("Node services")
|
self.columnconfigure(0, weight=1)
|
||||||
self.config_frame = tk.Frame(self.top)
|
self.rowconfigure(0, weight=1)
|
||||||
self.config_frame.grid()
|
self.config_frame = tk.Frame(self)
|
||||||
|
self.config_frame.columnconfigure(0, weight=1)
|
||||||
|
self.config_frame.columnconfigure(1, weight=1)
|
||||||
|
self.config_frame.columnconfigure(2, weight=1)
|
||||||
|
self.config_frame.rowconfigure(0, weight=1)
|
||||||
|
self.config_frame.grid(row=0, column=0, sticky="nsew")
|
||||||
self.draw_group()
|
self.draw_group()
|
||||||
self.group_services()
|
self.draw_services()
|
||||||
self.current_services()
|
self.draw_current_services()
|
||||||
self.node_service_options()
|
self.draw_buttons()
|
||||||
|
|
||||||
def display_group_services(self, group_name):
|
|
||||||
group_services_frame = self.config_frame.grid_slaves(row=0, column=1)[0]
|
|
||||||
listbox = group_services_frame.grid_slaves(row=1, column=0)[0]
|
|
||||||
listbox.delete(0, tk.END)
|
|
||||||
for s in DEFAULT_GROUP_SERVICES[group_name]:
|
|
||||||
listbox.insert(tk.END, s)
|
|
||||||
for i in range(listbox.size()):
|
|
||||||
listbox.itemconfig(i, selectbackground="white")
|
|
||||||
|
|
||||||
def group_select(self, event):
|
|
||||||
listbox = event.widget
|
|
||||||
cur_selection = listbox.curselection()
|
|
||||||
if cur_selection:
|
|
||||||
s = listbox.get(listbox.curselection())
|
|
||||||
self.display_group_services(s)
|
|
||||||
|
|
||||||
def draw_group(self):
|
def draw_group(self):
|
||||||
"""
|
"""
|
||||||
|
@ -93,36 +88,113 @@ class NodeServices:
|
||||||
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
f = tk.Frame(self.config_frame)
|
frame = tk.Frame(self.config_frame)
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
frame.rowconfigure(1, weight=1)
|
||||||
|
frame.grid(row=0, column=0, padx=3, pady=3, sticky="nsew")
|
||||||
|
|
||||||
lbl = tk.Label(f, text="Group")
|
label = tk.Label(frame, text="Group")
|
||||||
lbl.grid()
|
label.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
||||||
|
|
||||||
listbox = tk.Listbox(
|
listbox = tk.Listbox(
|
||||||
f,
|
frame,
|
||||||
selectmode=tk.SINGLE,
|
selectmode=tk.SINGLE,
|
||||||
yscrollcommand=sb.set,
|
yscrollcommand=scrollbar.set,
|
||||||
relief=tk.FLAT,
|
relief=tk.FLAT,
|
||||||
highlightbackground="#b3b3b3",
|
|
||||||
highlightcolor="#b3b3b3",
|
|
||||||
highlightthickness=0.5,
|
highlightthickness=0.5,
|
||||||
bd=0,
|
bd=0,
|
||||||
)
|
)
|
||||||
|
listbox.grid(row=1, column=0, sticky="nsew")
|
||||||
|
listbox.bind("<<ListboxSelect>>", self.handle_group_change)
|
||||||
|
|
||||||
for grp in CORE_DEFAULT_GROUPS:
|
for group in CORE_DEFAULT_GROUPS:
|
||||||
listbox.insert(tk.END, grp)
|
listbox.insert(tk.END, group)
|
||||||
for i in range(0, listbox.size()):
|
|
||||||
listbox.itemconfig(i, selectbackground="white")
|
|
||||||
listbox.grid(row=1, column=0)
|
|
||||||
|
|
||||||
sb.config(command=listbox.yview)
|
scrollbar.config(command=listbox.yview)
|
||||||
f.grid(padx=3, pady=3)
|
|
||||||
listbox.bind("<<ListboxSelect>>", self.group_select)
|
|
||||||
|
|
||||||
def group_service_select(self, event):
|
def draw_services(self):
|
||||||
|
frame = tk.Frame(self.config_frame)
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
frame.rowconfigure(1, weight=1)
|
||||||
|
frame.grid(row=0, column=1, padx=3, pady=3, sticky="nsew")
|
||||||
|
|
||||||
|
label = tk.Label(frame, text="Group services")
|
||||||
|
label.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
||||||
|
|
||||||
|
listbox = tk.Listbox(
|
||||||
|
frame,
|
||||||
|
selectmode=tk.SINGLE,
|
||||||
|
yscrollcommand=scrollbar.set,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
highlightthickness=0.5,
|
||||||
|
bd=0,
|
||||||
|
)
|
||||||
|
listbox.grid(row=1, column=0, sticky="nsew")
|
||||||
|
listbox.bind("<<ListboxSelect>>", self.handle_service_change)
|
||||||
|
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
|
||||||
|
def draw_current_services(self):
|
||||||
|
frame = tk.Frame(self.config_frame)
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
frame.rowconfigure(1, weight=1)
|
||||||
|
frame.grid(row=0, column=2, padx=3, pady=3, sticky="nsew")
|
||||||
|
|
||||||
|
label = tk.Label(frame, text="Current services")
|
||||||
|
label.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
||||||
|
|
||||||
|
listbox = tk.Listbox(
|
||||||
|
frame,
|
||||||
|
selectmode=tk.MULTIPLE,
|
||||||
|
yscrollcommand=scrollbar.set,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
highlightthickness=0.5,
|
||||||
|
bd=0,
|
||||||
|
)
|
||||||
|
listbox.grid(row=1, column=0, sticky="nsew")
|
||||||
|
|
||||||
|
scrollbar.config(command=listbox.yview)
|
||||||
|
|
||||||
|
def draw_buttons(self):
|
||||||
|
frame = tk.Frame(self)
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
frame.columnconfigure(1, weight=1)
|
||||||
|
frame.columnconfigure(2, weight=1)
|
||||||
|
frame.grid(row=1, column=0, sticky="ew")
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Configure", command=self.click_configure)
|
||||||
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Apply")
|
||||||
|
button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
|
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
|
button.grid(row=0, column=2, sticky="ew")
|
||||||
|
|
||||||
|
def handle_group_change(self, event):
|
||||||
|
listbox = event.widget
|
||||||
|
cur_selection = listbox.curselection()
|
||||||
|
if cur_selection:
|
||||||
|
s = listbox.get(listbox.curselection())
|
||||||
|
self.display_group_services(s)
|
||||||
|
|
||||||
|
def display_group_services(self, group_name):
|
||||||
|
group_services_frame = self.config_frame.grid_slaves(row=0, column=1)[0]
|
||||||
|
listbox = group_services_frame.grid_slaves(row=1, column=0)[0]
|
||||||
|
listbox.delete(0, tk.END)
|
||||||
|
for s in DEFAULT_GROUP_SERVICES[group_name]:
|
||||||
|
listbox.insert(tk.END, s)
|
||||||
|
|
||||||
|
def handle_service_change(self, event):
|
||||||
print("select group service")
|
print("select group service")
|
||||||
listbox = event.widget
|
listbox = event.widget
|
||||||
cur_selection = listbox.curselection()
|
cur_selection = listbox.curselection()
|
||||||
|
@ -132,64 +204,8 @@ class NodeServices:
|
||||||
else:
|
else:
|
||||||
self.service_to_config = None
|
self.service_to_config = None
|
||||||
|
|
||||||
def group_services(self):
|
def click_configure(self):
|
||||||
f = tk.Frame(self.config_frame)
|
|
||||||
lbl = tk.Label(f, text="Group services")
|
|
||||||
lbl.grid()
|
|
||||||
|
|
||||||
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
|
||||||
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
|
||||||
|
|
||||||
listbox = tk.Listbox(
|
|
||||||
f,
|
|
||||||
selectmode=tk.SINGLE,
|
|
||||||
yscrollcommand=sb.set,
|
|
||||||
relief=tk.FLAT,
|
|
||||||
highlightbackground="#b3b3b3",
|
|
||||||
highlightcolor="#b3b3b3",
|
|
||||||
highlightthickness=0.5,
|
|
||||||
bd=0,
|
|
||||||
)
|
|
||||||
listbox.grid(row=1, column=0)
|
|
||||||
sb.config(command=listbox.yview)
|
|
||||||
f.grid(padx=3, pady=3, row=0, column=1)
|
|
||||||
|
|
||||||
listbox.bind("<<ListboxSelect>>", self.group_service_select)
|
|
||||||
|
|
||||||
def current_services(self):
|
|
||||||
f = tk.Frame(self.config_frame)
|
|
||||||
lbl = tk.Label(f, text="Current services")
|
|
||||||
lbl.grid()
|
|
||||||
|
|
||||||
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
|
|
||||||
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
|
|
||||||
|
|
||||||
listbox = tk.Listbox(
|
|
||||||
f,
|
|
||||||
selectmode=tk.MULTIPLE,
|
|
||||||
yscrollcommand=sb.set,
|
|
||||||
relief=tk.FLAT,
|
|
||||||
highlightbackground="#b3b3b3",
|
|
||||||
highlightcolor="#b3b3b3",
|
|
||||||
highlightthickness=0.5,
|
|
||||||
bd=0,
|
|
||||||
)
|
|
||||||
listbox.grid(row=1, column=0)
|
|
||||||
sb.config(command=listbox.yview)
|
|
||||||
f.grid(padx=3, pady=3, row=0, column=2)
|
|
||||||
|
|
||||||
def config_service(self):
|
|
||||||
if self.service_to_config is None:
|
if self.service_to_config is None:
|
||||||
messagebox.showinfo("CORE info", "Choose a service to configure.")
|
messagebox.showinfo("CORE info", "Choose a service to configure.")
|
||||||
else:
|
else:
|
||||||
print(self.service_to_config)
|
print(self.service_to_config)
|
||||||
|
|
||||||
def node_service_options(self):
|
|
||||||
f = tk.Frame(self.top)
|
|
||||||
b = tk.Button(f, text="Connfigure", command=self.config_service)
|
|
||||||
b.grid(row=0, column=0)
|
|
||||||
b = tk.Button(f, text="Apply")
|
|
||||||
b.grid(row=0, column=1)
|
|
||||||
b = tk.Button(f, text="Cancel", command=self.top.destroy)
|
|
||||||
b.grid(row=0, column=2)
|
|
||||||
f.grid(sticky=tk.E)
|
|
||||||
|
|
Loading…
Reference in a new issue