2019-11-01 15:35:14 +00:00
|
|
|
"""
|
|
|
|
core node services
|
|
|
|
"""
|
|
|
|
import tkinter as tk
|
2019-11-12 20:13:53 +00:00
|
|
|
from tkinter import messagebox, ttk
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
from coretk.dialogs.dialog import Dialog
|
|
|
|
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
class NodeServicesDialog(Dialog):
|
|
|
|
def __init__(self, master, app, canvas_node):
|
|
|
|
super().__init__(master, app, "Node Services", modal=True)
|
|
|
|
self.canvas_node = canvas_node
|
2019-11-01 15:35:14 +00:00
|
|
|
self.core_groups = []
|
|
|
|
self.service_to_config = None
|
2019-11-04 19:34:28 +00:00
|
|
|
self.config_frame = None
|
2019-11-06 00:16:46 +00:00
|
|
|
self.services_list = None
|
2019-11-04 19:34:28 +00:00
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
self.rowconfigure(0, weight=1)
|
2019-11-12 20:13:53 +00:00
|
|
|
self.config_frame = ttk.Frame(self)
|
2019-11-04 19:34:28 +00:00
|
|
|
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")
|
2019-11-01 15:35:14 +00:00
|
|
|
self.draw_group()
|
2019-11-04 19:34:28 +00:00
|
|
|
self.draw_services()
|
|
|
|
self.draw_current_services()
|
|
|
|
self.draw_buttons()
|
2019-11-01 15:35:14 +00:00
|
|
|
|
|
|
|
def draw_group(self):
|
|
|
|
"""
|
|
|
|
draw the group tab
|
|
|
|
|
|
|
|
:return: nothing
|
|
|
|
"""
|
2019-11-12 20:13:53 +00:00
|
|
|
frame = ttk.Frame(self.config_frame)
|
2019-11-04 19:34:28 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.rowconfigure(1, weight=1)
|
|
|
|
frame.grid(row=0, column=0, padx=3, pady=3, sticky="nsew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
label = ttk.Label(frame, text="Group")
|
2019-11-04 19:34:28 +00:00
|
|
|
label.grid(row=0, column=0, sticky="ew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL)
|
2019-11-04 19:34:28 +00:00
|
|
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
|
|
|
listbox = tk.Listbox(
|
2019-11-04 19:34:28 +00:00
|
|
|
frame,
|
2019-11-01 15:35:14 +00:00
|
|
|
selectmode=tk.SINGLE,
|
2019-11-04 19:34:28 +00:00
|
|
|
yscrollcommand=scrollbar.set,
|
2019-11-01 15:35:14 +00:00
|
|
|
relief=tk.FLAT,
|
|
|
|
highlightthickness=0.5,
|
|
|
|
bd=0,
|
|
|
|
)
|
2019-11-04 19:34:28 +00:00
|
|
|
listbox.grid(row=1, column=0, sticky="nsew")
|
|
|
|
listbox.bind("<<ListboxSelect>>", self.handle_group_change)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-06 00:16:46 +00:00
|
|
|
for group in sorted(self.app.core.services):
|
2019-11-04 19:34:28 +00:00
|
|
|
listbox.insert(tk.END, group)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
scrollbar.config(command=listbox.yview)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
def draw_services(self):
|
2019-11-12 20:13:53 +00:00
|
|
|
frame = ttk.Frame(self.config_frame)
|
2019-11-04 19:34:28 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.rowconfigure(1, weight=1)
|
|
|
|
frame.grid(row=0, column=1, padx=3, pady=3, sticky="nsew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
label = ttk.Label(frame, text="Group services")
|
2019-11-04 19:34:28 +00:00
|
|
|
label.grid(row=0, column=0, sticky="ew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL)
|
2019-11-04 19:34:28 +00:00
|
|
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-06 00:16:46 +00:00
|
|
|
self.services_list = tk.Listbox(
|
2019-11-04 19:34:28 +00:00
|
|
|
frame,
|
2019-11-01 15:35:14 +00:00
|
|
|
selectmode=tk.SINGLE,
|
2019-11-04 19:34:28 +00:00
|
|
|
yscrollcommand=scrollbar.set,
|
2019-11-01 15:35:14 +00:00
|
|
|
relief=tk.FLAT,
|
|
|
|
highlightthickness=0.5,
|
|
|
|
bd=0,
|
|
|
|
)
|
2019-11-06 00:16:46 +00:00
|
|
|
self.services_list.grid(row=1, column=0, sticky="nsew")
|
|
|
|
self.services_list.bind("<<ListboxSelect>>", self.handle_service_change)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-06 00:16:46 +00:00
|
|
|
scrollbar.config(command=self.services_list.yview)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
def draw_current_services(self):
|
2019-11-12 20:13:53 +00:00
|
|
|
frame = ttk.Frame(self.config_frame)
|
2019-11-04 19:34:28 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.rowconfigure(1, weight=1)
|
|
|
|
frame.grid(row=0, column=2, padx=3, pady=3, sticky="nsew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
label = ttk.Label(frame, text="Current services")
|
2019-11-04 19:34:28 +00:00
|
|
|
label.grid(row=0, column=0, sticky="ew")
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL)
|
2019-11-04 19:34:28 +00:00
|
|
|
scrollbar.grid(row=1, column=1, sticky="ns")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
|
|
|
listbox = tk.Listbox(
|
2019-11-04 19:34:28 +00:00
|
|
|
frame,
|
2019-11-01 15:35:14 +00:00
|
|
|
selectmode=tk.MULTIPLE,
|
2019-11-04 19:34:28 +00:00
|
|
|
yscrollcommand=scrollbar.set,
|
2019-11-01 15:35:14 +00:00
|
|
|
relief=tk.FLAT,
|
|
|
|
highlightthickness=0.5,
|
|
|
|
bd=0,
|
|
|
|
)
|
2019-11-04 19:34:28 +00:00
|
|
|
listbox.grid(row=1, column=0, sticky="nsew")
|
|
|
|
|
|
|
|
scrollbar.config(command=listbox.yview)
|
|
|
|
|
|
|
|
def draw_buttons(self):
|
2019-11-12 20:13:53 +00:00
|
|
|
frame = ttk.Frame(self)
|
2019-11-04 19:34:28 +00:00
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
frame.columnconfigure(2, weight=1)
|
|
|
|
frame.grid(row=1, column=0, sticky="ew")
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Configure", command=self.click_configure)
|
2019-11-04 19:34:28 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew")
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Apply")
|
2019-11-04 19:34:28 +00:00
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2019-11-04 19:34:28 +00:00
|
|
|
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):
|
2019-11-06 00:16:46 +00:00
|
|
|
self.services_list.delete(0, tk.END)
|
|
|
|
for service in sorted(self.app.core.services[group_name], key=lambda x: x.name):
|
|
|
|
self.services_list.insert(tk.END, service.name)
|
2019-11-04 19:34:28 +00:00
|
|
|
|
|
|
|
def handle_service_change(self, event):
|
|
|
|
print("select group service")
|
|
|
|
listbox = event.widget
|
|
|
|
cur_selection = listbox.curselection()
|
|
|
|
if cur_selection:
|
|
|
|
s = listbox.get(listbox.curselection())
|
|
|
|
self.service_to_config = s
|
|
|
|
else:
|
|
|
|
self.service_to_config = None
|
|
|
|
|
|
|
|
def click_configure(self):
|
2019-11-01 15:35:14 +00:00
|
|
|
if self.service_to_config is None:
|
|
|
|
messagebox.showinfo("CORE info", "Choose a service to configure.")
|
|
|
|
else:
|
|
|
|
print(self.service_to_config)
|