updates to get custom nodes dialog to a working state
This commit is contained in:
parent
1cf4847835
commit
613568ca28
2 changed files with 73 additions and 20 deletions
|
@ -64,6 +64,13 @@ class CoreServer:
|
||||||
self.port = port
|
self.port = port
|
||||||
|
|
||||||
|
|
||||||
|
class CustomNode:
|
||||||
|
def __init__(self, name, image, services):
|
||||||
|
self.name = name
|
||||||
|
self.image = image
|
||||||
|
self.services = services
|
||||||
|
|
||||||
|
|
||||||
class CoreClient:
|
class CoreClient:
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
"""
|
"""
|
||||||
|
@ -76,6 +83,7 @@ class CoreClient:
|
||||||
self.master = app.master
|
self.master = app.master
|
||||||
self.interface_helper = None
|
self.interface_helper = None
|
||||||
self.services = {}
|
self.services = {}
|
||||||
|
self.custom_nodes = {}
|
||||||
|
|
||||||
# distributed server data
|
# distributed server data
|
||||||
self.servers = {}
|
self.servers = {}
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
|
||||||
|
from coretk.coreclient import CustomNode
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.dialogs.nodeicon import IconDialog
|
from coretk.dialogs.nodeicon import IconDialog
|
||||||
from coretk.widgets import CheckboxList, ListboxScroll
|
from coretk.widgets import CheckboxList, ListboxScroll
|
||||||
|
|
||||||
|
|
||||||
class ServicesSelectDialog(Dialog):
|
class ServicesSelectDialog(Dialog):
|
||||||
def __init__(self, master, app):
|
def __init__(self, master, app, current_services):
|
||||||
super().__init__(master, app, "Node Services", modal=True)
|
super().__init__(master, app, "Node Services", modal=True)
|
||||||
self.groups = None
|
self.groups = None
|
||||||
self.services = None
|
self.services = None
|
||||||
self.current = None
|
self.current = None
|
||||||
self.current_services = set()
|
self.current_services = current_services
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
@ -37,14 +38,16 @@ class ServicesSelectDialog(Dialog):
|
||||||
|
|
||||||
self.current = ListboxScroll(frame, text="Selected")
|
self.current = ListboxScroll(frame, text="Selected")
|
||||||
self.current.grid(row=0, column=2, sticky="nsew")
|
self.current.grid(row=0, column=2, sticky="nsew")
|
||||||
|
for service in sorted(self.current_services):
|
||||||
|
self.current.listbox.insert(tk.END, service)
|
||||||
|
|
||||||
frame = tk.Frame(self)
|
frame = tk.Frame(self)
|
||||||
frame.grid(stick="ew")
|
frame.grid(stick="ew")
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
frame.columnconfigure(i, weight=1)
|
frame.columnconfigure(i, weight=1)
|
||||||
button = tk.Button(frame, text="Save")
|
button = tk.Button(frame, text="Save", command=self.click_cancel)
|
||||||
button.grid(row=0, column=0, sticky="ew")
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
button = tk.Button(frame, text="Cancel", command=self.click_cancel)
|
||||||
button.grid(row=0, column=1, sticky="ew")
|
button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
# trigger group change
|
# trigger group change
|
||||||
|
@ -69,15 +72,23 @@ class ServicesSelectDialog(Dialog):
|
||||||
for name in sorted(self.current_services):
|
for name in sorted(self.current_services):
|
||||||
self.current.listbox.insert(tk.END, name)
|
self.current.listbox.insert(tk.END, name)
|
||||||
|
|
||||||
|
def click_cancel(self):
|
||||||
|
self.current_services = None
|
||||||
|
self.destroy()
|
||||||
|
|
||||||
|
|
||||||
class CustomNodesDialog(Dialog):
|
class CustomNodesDialog(Dialog):
|
||||||
def __init__(self, master, app):
|
def __init__(self, master, app):
|
||||||
super().__init__(master, app, "Custom Nodes", modal=True)
|
super().__init__(master, app, "Custom Nodes", modal=True)
|
||||||
self.save_button = None
|
self.edit_button = None
|
||||||
self.delete_button = None
|
self.delete_button = None
|
||||||
|
self.nodes_list = None
|
||||||
self.name = tk.StringVar()
|
self.name = tk.StringVar()
|
||||||
self.image_button = None
|
self.image_button = None
|
||||||
self.image = None
|
self.image = None
|
||||||
|
self.services = set()
|
||||||
|
self.selected = None
|
||||||
|
self.selected_index = None
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
@ -93,13 +104,11 @@ class CustomNodesDialog(Dialog):
|
||||||
frame.columnconfigure(0, weight=1)
|
frame.columnconfigure(0, weight=1)
|
||||||
frame.rowconfigure(0, weight=1)
|
frame.rowconfigure(0, weight=1)
|
||||||
|
|
||||||
scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
|
self.nodes_list = ListboxScroll(frame)
|
||||||
scrollbar.grid(row=0, column=1, sticky="ns")
|
self.nodes_list.grid(row=0, column=0, sticky="nsew")
|
||||||
|
self.nodes_list.listbox.bind("<<ListboxSelect>>", self.handle_node_select)
|
||||||
listbox = tk.Listbox(frame, selectmode=tk.SINGLE, yscrollcommand=scrollbar.set)
|
for name in sorted(self.app.core.custom_nodes):
|
||||||
listbox.grid(row=0, column=0, sticky="nsew")
|
self.nodes_list.listbox.insert(tk.END, name)
|
||||||
|
|
||||||
scrollbar.config(command=listbox.yview)
|
|
||||||
|
|
||||||
frame = tk.Frame(frame)
|
frame = tk.Frame(frame)
|
||||||
frame.grid(row=0, column=2, sticky="nsew")
|
frame.grid(row=0, column=2, sticky="nsew")
|
||||||
|
@ -120,10 +129,10 @@ class CustomNodesDialog(Dialog):
|
||||||
button = tk.Button(frame, text="Create", command=self.click_create)
|
button = tk.Button(frame, text="Create", command=self.click_create)
|
||||||
button.grid(row=0, column=0, sticky="ew")
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
self.save_button = tk.Button(
|
self.edit_button = tk.Button(
|
||||||
frame, text="Save", state=tk.DISABLED, command=self.click_save
|
frame, text="Edit", state=tk.DISABLED, command=self.click_edit
|
||||||
)
|
)
|
||||||
self.save_button.grid(row=0, column=1, sticky="ew")
|
self.edit_button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
self.delete_button = tk.Button(
|
self.delete_button = tk.Button(
|
||||||
frame, text="Delete", state=tk.DISABLED, command=self.click_delete
|
frame, text="Delete", state=tk.DISABLED, command=self.click_delete
|
||||||
|
@ -136,7 +145,7 @@ class CustomNodesDialog(Dialog):
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
frame.columnconfigure(i, weight=1)
|
frame.columnconfigure(i, weight=1)
|
||||||
|
|
||||||
button = tk.Button(frame, text="Save", command=self.click_save)
|
button = tk.Button(frame, text="Save", command=self.click_edit)
|
||||||
button.grid(row=0, column=0, sticky="ew")
|
button.grid(row=0, column=0, sticky="ew")
|
||||||
|
|
||||||
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
button = tk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
|
@ -150,14 +159,50 @@ class CustomNodesDialog(Dialog):
|
||||||
self.image_button.config(image=self.image)
|
self.image_button.config(image=self.image)
|
||||||
|
|
||||||
def click_services(self):
|
def click_services(self):
|
||||||
dialog = ServicesSelectDialog(self, self.app)
|
dialog = ServicesSelectDialog(self, self.app, self.services)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
if dialog.current_services is not None:
|
||||||
|
self.services = dialog.current_services
|
||||||
|
|
||||||
def click_create(self):
|
def click_create(self):
|
||||||
pass
|
name = self.name.get()
|
||||||
|
if name not in self.app.core.custom_nodes:
|
||||||
|
custom_node = CustomNode(name, self.image, self.services)
|
||||||
|
self.app.core.custom_nodes[name] = custom_node
|
||||||
|
self.nodes_list.listbox.insert(tk.END, name)
|
||||||
|
self.reset_values()
|
||||||
|
|
||||||
def click_save(self):
|
def reset_values(self):
|
||||||
|
self.name.set("")
|
||||||
|
self.image = None
|
||||||
|
self.services = set()
|
||||||
|
self.image_button.config(image="")
|
||||||
|
|
||||||
|
def click_edit(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def click_delete(self):
|
def click_delete(self):
|
||||||
pass
|
if self.selected and self.selected in self.app.core.custom_nodes:
|
||||||
|
self.nodes_list.listbox.delete(self.selected_index)
|
||||||
|
del self.app.core.custom_nodes[self.selected]
|
||||||
|
self.reset_values()
|
||||||
|
self.nodes_list.listbox.selection_clear(0, tk.END)
|
||||||
|
self.nodes_list.listbox.event_generate("<<ListboxSelect>>")
|
||||||
|
|
||||||
|
def handle_node_select(self, event):
|
||||||
|
selection = self.nodes_list.listbox.curselection()
|
||||||
|
if selection:
|
||||||
|
self.selected_index = selection[0]
|
||||||
|
self.selected = self.nodes_list.listbox.get(self.selected_index)
|
||||||
|
custom_node = self.app.core.custom_nodes[self.selected]
|
||||||
|
self.name.set(custom_node.name)
|
||||||
|
self.services = custom_node.services
|
||||||
|
self.image = custom_node.image
|
||||||
|
self.image_button.config(image=self.image)
|
||||||
|
self.edit_button.config(state=tk.NORMAL)
|
||||||
|
self.delete_button.config(state=tk.NORMAL)
|
||||||
|
else:
|
||||||
|
self.selected = None
|
||||||
|
self.selected_index = None
|
||||||
|
self.edit_button.config(state=tk.DISABLED)
|
||||||
|
self.delete_button.config(state=tk.DISABLED)
|
||||||
|
|
Loading…
Add table
Reference in a new issue