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-11 18:57:26 +00:00
|
|
|
from coretk.dialogs.serviceconfiguration import ServiceConfiguration
|
|
|
|
from coretk.widgets import CheckboxList, ListboxScroll
|
2019-11-04 19:34:28 +00:00
|
|
|
|
2019-12-11 22:09:50 +00:00
|
|
|
PAD = 5
|
|
|
|
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-11 18:57:26 +00:00
|
|
|
class NodeService(Dialog):
|
2019-11-13 16:38:08 +00:00
|
|
|
def __init__(self, master, app, canvas_node, services=None):
|
2019-11-04 19:34:28 +00:00
|
|
|
super().__init__(master, app, "Node Services", modal=True)
|
2019-11-21 23:00:17 +00:00
|
|
|
self.app = app
|
2019-11-04 19:34:28 +00:00
|
|
|
self.canvas_node = canvas_node
|
2019-11-16 01:26:02 +00:00
|
|
|
self.node_id = canvas_node.core_node.id
|
2019-11-11 18:57:26 +00:00
|
|
|
self.groups = None
|
|
|
|
self.services = None
|
|
|
|
self.current = None
|
2019-11-22 00:59:55 +00:00
|
|
|
if services is None:
|
|
|
|
services = canvas_node.core_node.services
|
|
|
|
model = canvas_node.core_node.model
|
|
|
|
if len(services) == 0:
|
|
|
|
services = set(self.app.core.default_services[model])
|
|
|
|
else:
|
|
|
|
services = set(services)
|
|
|
|
|
2019-11-13 16:38:08 +00:00
|
|
|
self.current_services = services
|
2019-11-04 19:34:28 +00:00
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
2019-11-13 18:45:43 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
|
|
|
self.top.rowconfigure(0, weight=1)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-11 18:57:26 +00:00
|
|
|
frame.grid(stick="nsew")
|
|
|
|
frame.rowconfigure(0, weight=1)
|
|
|
|
for i in range(3):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2019-12-11 22:09:50 +00:00
|
|
|
self.groups = ListboxScroll(frame, text="Groups", padding=PAD)
|
2019-11-11 18:57:26 +00:00
|
|
|
self.groups.grid(row=0, column=0, sticky="nsew")
|
2019-11-06 00:16:46 +00:00
|
|
|
for group in sorted(self.app.core.services):
|
2019-11-11 18:57:26 +00:00
|
|
|
self.groups.listbox.insert(tk.END, group)
|
|
|
|
self.groups.listbox.bind("<<ListboxSelect>>", self.handle_group_change)
|
|
|
|
self.groups.listbox.selection_set(0)
|
2019-11-01 15:35:14 +00:00
|
|
|
|
2019-11-11 18:57:26 +00:00
|
|
|
self.services = CheckboxList(
|
2019-12-11 22:09:50 +00:00
|
|
|
frame, self.app, text="Services", clicked=self.service_clicked, padding=PAD
|
2019-11-01 15:35:14 +00:00
|
|
|
)
|
2019-11-11 18:57:26 +00:00
|
|
|
self.services.grid(row=0, column=1, sticky="nsew")
|
2019-11-04 19:34:28 +00:00
|
|
|
|
2019-12-11 22:09:50 +00:00
|
|
|
self.current = ListboxScroll(frame, text="Selected", padding=PAD)
|
2019-11-11 18:57:26 +00:00
|
|
|
self.current.grid(row=0, column=2, sticky="nsew")
|
|
|
|
for service in sorted(self.current_services):
|
|
|
|
self.current.listbox.insert(tk.END, service)
|
2019-11-04 19:34:28 +00:00
|
|
|
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-11 18:57:26 +00:00
|
|
|
frame.grid(stick="ew")
|
|
|
|
for i in range(3):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Configure", command=self.click_configure)
|
2019-12-11 22:09:50 +00:00
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PAD)
|
2019-11-13 16:38:08 +00:00
|
|
|
button = ttk.Button(frame, text="Save", command=self.click_save)
|
2019-12-11 22:09:50 +00:00
|
|
|
button.grid(row=0, column=1, sticky="ew", padx=PAD)
|
2019-11-13 16:38:08 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.click_cancel)
|
2019-11-04 19:34:28 +00:00
|
|
|
button.grid(row=0, column=2, sticky="ew")
|
|
|
|
|
2019-11-11 18:57:26 +00:00
|
|
|
# trigger group change
|
|
|
|
self.groups.listbox.event_generate("<<ListboxSelect>>")
|
2019-11-04 19:34:28 +00:00
|
|
|
|
2019-11-11 18:57:26 +00:00
|
|
|
def handle_group_change(self, event):
|
|
|
|
selection = self.groups.listbox.curselection()
|
|
|
|
if selection:
|
|
|
|
index = selection[0]
|
|
|
|
group = self.groups.listbox.get(index)
|
|
|
|
self.services.clear()
|
2019-11-21 23:07:43 +00:00
|
|
|
for name in sorted(self.app.core.services[group]):
|
|
|
|
checked = name in self.current_services
|
|
|
|
self.services.add(name, checked)
|
2019-11-11 18:57:26 +00:00
|
|
|
|
|
|
|
def service_clicked(self, name, var):
|
|
|
|
if var.get() and name not in self.current_services:
|
2019-11-22 18:32:25 +00:00
|
|
|
self.current_services.add(name)
|
2019-11-11 18:57:26 +00:00
|
|
|
elif not var.get() and name in self.current_services:
|
|
|
|
self.current_services.remove(name)
|
|
|
|
self.current.listbox.delete(0, tk.END)
|
|
|
|
for name in sorted(self.current_services):
|
|
|
|
self.current.listbox.insert(tk.END, name)
|
2019-12-06 23:06:35 +00:00
|
|
|
self.canvas_node.core_node.services[:] = self.current_services
|
2019-11-04 19:34:28 +00:00
|
|
|
|
|
|
|
def click_configure(self):
|
2019-11-11 18:57:26 +00:00
|
|
|
current_selection = self.current.listbox.curselection()
|
|
|
|
if len(current_selection):
|
|
|
|
dialog = ServiceConfiguration(
|
|
|
|
master=self,
|
|
|
|
app=self.app,
|
|
|
|
service_name=self.current.listbox.get(current_selection[0]),
|
2019-11-21 00:52:02 +00:00
|
|
|
node_id=self.node_id,
|
2019-11-11 18:57:26 +00:00
|
|
|
)
|
|
|
|
dialog.show()
|
2019-11-01 15:35:14 +00:00
|
|
|
else:
|
2019-11-11 18:57:26 +00:00
|
|
|
messagebox.showinfo(
|
|
|
|
"Node service configuration", "Select a service to configure"
|
|
|
|
)
|
|
|
|
|
|
|
|
def click_save(self):
|
2019-11-21 23:00:17 +00:00
|
|
|
if (
|
|
|
|
self.current_services
|
|
|
|
!= self.app.core.default_services[self.canvas_node.core_node.model]
|
|
|
|
):
|
|
|
|
self.canvas_node.core_node.services[:] = self.current_services
|
|
|
|
else:
|
|
|
|
if len(self.canvas_node.core_node.services) > 0:
|
|
|
|
self.canvas_node.core_node.services[:] = []
|
|
|
|
self.destroy()
|
2019-11-11 18:57:26 +00:00
|
|
|
|
|
|
|
def click_cancel(self):
|
|
|
|
self.current_services = None
|
|
|
|
self.destroy()
|