update node service dialog to use common dialog class

This commit is contained in:
Blake Harnden 2019-11-04 11:34:28 -08:00
parent d4f77a01e3
commit 22a55b69d3
2 changed files with 122 additions and 102 deletions

View file

@ -3,7 +3,7 @@ from tkinter import ttk
from coretk.dialogs.dialog import Dialog
from coretk.dialogs.nodeicon import NodeIconDialog
from coretk.dialogs.nodeservice import NodeServices
from coretk.dialogs.nodeservice import NodeServicesDialog
NETWORKNODETYPES = ["switch", "hub", "wlan", "rj45", "tunnel"]
DEFAULTNODES = ["router", "host", "PC"]
@ -56,7 +56,7 @@ class NodeConfigDialog(Dialog):
frame.columnconfigure(0, 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")
self.image_button = tk.Button(
@ -80,6 +80,10 @@ class NodeConfigDialog(Dialog):
button = tk.Button(frame, text="Cancel", command=self.destroy)
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):
dialog = NodeIconDialog(self, self.app, self.canvas_node)
dialog.show()

View file

@ -4,6 +4,8 @@ core node services
import tkinter as tk
from tkinter import messagebox
from coretk.dialogs.dialog import Dialog
CORE_DEFAULT_GROUPS = ["EMANE", "FRR", "ProtoSvc", "Quagga", "Security", "Utility"]
DEFAULT_GROUP_RADIO_VALUE = {
"EMANE": 1,
@ -57,35 +59,28 @@ DEFAULT_GROUP_SERVICES = {
}
class NodeServices:
def __init__(self):
class NodeServicesDialog(Dialog):
def __init__(self, master, app, canvas_node):
super().__init__(master, app, "Node Services", modal=True)
self.canvas_node = canvas_node
self.core_groups = []
self.service_to_config = None
self.config_frame = None
self.draw()
self.top = tk.Toplevel()
self.top.title("Node services")
self.config_frame = tk.Frame(self.top)
self.config_frame.grid()
def draw(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
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.group_services()
self.current_services()
self.node_service_options()
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)
self.draw_services()
self.draw_current_services()
self.draw_buttons()
def draw_group(self):
"""
@ -93,36 +88,113 @@ class NodeServices:
: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")
lbl.grid()
label = tk.Label(frame, text="Group")
label.grid(row=0, column=0, sticky="ew")
sb = tk.Scrollbar(f, orient=tk.VERTICAL)
sb.grid(row=1, column=1, sticky=tk.S + tk.N)
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
scrollbar.grid(row=1, column=1, sticky="ns")
listbox = tk.Listbox(
f,
frame,
selectmode=tk.SINGLE,
yscrollcommand=sb.set,
yscrollcommand=scrollbar.set,
relief=tk.FLAT,
highlightbackground="#b3b3b3",
highlightcolor="#b3b3b3",
highlightthickness=0.5,
bd=0,
)
listbox.grid(row=1, column=0, sticky="nsew")
listbox.bind("<<ListboxSelect>>", self.handle_group_change)
for grp in CORE_DEFAULT_GROUPS:
listbox.insert(tk.END, grp)
for i in range(0, listbox.size()):
listbox.itemconfig(i, selectbackground="white")
listbox.grid(row=1, column=0)
for group in CORE_DEFAULT_GROUPS:
listbox.insert(tk.END, group)
sb.config(command=listbox.yview)
f.grid(padx=3, pady=3)
listbox.bind("<<ListboxSelect>>", self.group_select)
scrollbar.config(command=listbox.yview)
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")
listbox = event.widget
cur_selection = listbox.curselection()
@ -132,64 +204,8 @@ class NodeServices:
else:
self.service_to_config = None
def group_services(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):
def click_configure(self):
if self.service_to_config is None:
messagebox.showinfo("CORE info", "Choose a service to configure.")
else:
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)