2019-11-03 06:47:43 +00:00
|
|
|
import tkinter as tk
|
|
|
|
from tkinter import ttk
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
from coretk.coreclient import DEFAULT_NODES
|
2019-11-03 06:47:43 +00:00
|
|
|
from coretk.dialogs.dialog import Dialog
|
2019-11-07 19:33:40 +00:00
|
|
|
from coretk.dialogs.icondialog import IconDialog
|
2019-11-11 18:57:26 +00:00
|
|
|
from coretk.dialogs.nodeservice import NodeService
|
2019-11-03 06:47:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NodeConfigDialog(Dialog):
|
|
|
|
def __init__(self, master, app, canvas_node):
|
|
|
|
"""
|
|
|
|
create an instance of node configuration
|
|
|
|
|
|
|
|
:param master: dialog master
|
|
|
|
:param coretk.app.Application: main app
|
|
|
|
:param coretk.graph.CanvasNode canvas_node: canvas node object
|
|
|
|
"""
|
|
|
|
super().__init__(master, app, f"{canvas_node.name} Configuration", modal=True)
|
|
|
|
self.canvas_node = canvas_node
|
|
|
|
self.image = canvas_node.image
|
|
|
|
self.image_button = None
|
|
|
|
self.name = tk.StringVar(value=canvas_node.name)
|
2019-11-15 18:22:30 +00:00
|
|
|
self.type = tk.StringVar(value=canvas_node.core_node.model)
|
2019-11-03 06:47:43 +00:00
|
|
|
self.server = tk.StringVar()
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
2019-11-13 18:45:43 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
2019-11-03 06:47:43 +00:00
|
|
|
self.draw_first_row()
|
|
|
|
self.draw_second_row()
|
|
|
|
self.draw_third_row()
|
|
|
|
|
|
|
|
def draw_first_row(self):
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-03 06:47:43 +00:00
|
|
|
frame.grid(row=0, column=0, pady=2, sticky="ew")
|
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
frame.columnconfigure(2, weight=1)
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
entry = ttk.Entry(frame, textvariable=self.name)
|
2019-11-03 06:47:43 +00:00
|
|
|
entry.grid(row=0, column=0, padx=2, sticky="ew")
|
|
|
|
|
2019-11-05 20:37:47 +00:00
|
|
|
combobox = ttk.Combobox(
|
2019-11-12 20:13:53 +00:00
|
|
|
frame, textvariable=self.type, values=DEFAULT_NODES, state="readonly"
|
2019-11-05 20:37:47 +00:00
|
|
|
)
|
2019-11-03 06:47:43 +00:00
|
|
|
combobox.grid(row=0, column=1, padx=2, sticky="ew")
|
|
|
|
|
2019-11-05 20:37:47 +00:00
|
|
|
servers = [""]
|
|
|
|
servers.extend(list(sorted(self.app.core.servers.keys())))
|
|
|
|
combobox = ttk.Combobox(
|
|
|
|
frame, textvariable=self.server, values=servers, state="readonly"
|
|
|
|
)
|
2019-11-03 06:47:43 +00:00
|
|
|
combobox.current(0)
|
|
|
|
combobox.grid(row=0, column=2, sticky="ew")
|
|
|
|
|
|
|
|
def draw_second_row(self):
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-03 06:47:43 +00:00
|
|
|
frame.grid(row=1, column=0, pady=2, sticky="ew")
|
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Services", command=self.click_services)
|
2019-11-03 06:47:43 +00:00
|
|
|
button.grid(row=0, column=0, padx=2, sticky="ew")
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
self.image_button = ttk.Button(
|
2019-11-03 06:47:43 +00:00
|
|
|
frame,
|
|
|
|
text="Icon",
|
|
|
|
image=self.image,
|
|
|
|
compound=tk.LEFT,
|
|
|
|
command=self.click_icon,
|
|
|
|
)
|
|
|
|
self.image_button.grid(row=0, column=1, sticky="ew")
|
|
|
|
|
|
|
|
def draw_third_row(self):
|
2019-11-13 18:45:43 +00:00
|
|
|
frame = ttk.Frame(self.top)
|
2019-11-03 06:47:43 +00:00
|
|
|
frame.grid(row=2, column=0, sticky="ew")
|
|
|
|
frame.columnconfigure(0, weight=1)
|
|
|
|
frame.columnconfigure(1, weight=1)
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Apply", command=self.config_apply)
|
2019-11-03 06:47:43 +00:00
|
|
|
button.grid(row=0, column=0, padx=2, sticky="ew")
|
|
|
|
|
2019-11-12 20:13:53 +00:00
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2019-11-03 06:47:43 +00:00
|
|
|
button.grid(row=0, column=1, sticky="ew")
|
|
|
|
|
2019-11-04 19:34:28 +00:00
|
|
|
def click_services(self):
|
2019-11-11 18:57:26 +00:00
|
|
|
dialog = NodeService(self, self.app, self.canvas_node)
|
2019-11-04 19:34:28 +00:00
|
|
|
dialog.show()
|
|
|
|
|
2019-11-03 06:47:43 +00:00
|
|
|
def click_icon(self):
|
2019-11-06 06:44:50 +00:00
|
|
|
dialog = IconDialog(
|
|
|
|
self, self.app, self.canvas_node.name, self.canvas_node.image
|
|
|
|
)
|
2019-11-03 06:47:43 +00:00
|
|
|
dialog.show()
|
|
|
|
if dialog.image:
|
|
|
|
self.image = dialog.image
|
|
|
|
self.image_button.config(image=self.image)
|
|
|
|
|
|
|
|
def config_apply(self):
|
|
|
|
self.canvas_node.name = self.name.get()
|
|
|
|
self.canvas_node.image = self.image
|
|
|
|
self.canvas_node.canvas.itemconfig(self.canvas_node.id, image=self.image)
|
|
|
|
self.destroy()
|