2020-01-09 00:48:04 +00:00
|
|
|
"""
|
|
|
|
copy service config dialog
|
|
|
|
"""
|
|
|
|
|
|
|
|
import tkinter as tk
|
|
|
|
from tkinter import ttk
|
2020-06-24 00:11:39 +01:00
|
|
|
from typing import TYPE_CHECKING, Dict, Optional
|
2020-01-09 00:48:04 +00:00
|
|
|
|
|
|
|
from core.gui.dialogs.dialog import Dialog
|
2020-06-24 00:11:39 +01:00
|
|
|
from core.gui.themes import PADX, PADY
|
|
|
|
from core.gui.widgets import CodeText, ListboxScroll
|
2020-01-09 00:48:04 +00:00
|
|
|
|
2020-01-13 23:31:41 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from core.gui.app import Application
|
2020-06-24 00:11:39 +01:00
|
|
|
from core.gui.dialogs.serviceconfig import ServiceConfigDialog
|
2020-01-13 23:31:41 +00:00
|
|
|
|
2020-01-09 00:48:04 +00:00
|
|
|
|
|
|
|
class CopyServiceConfigDialog(Dialog):
|
2020-06-24 00:11:39 +01:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
app: "Application",
|
|
|
|
dialog: "ServiceConfigDialog",
|
|
|
|
name: str,
|
|
|
|
service: str,
|
|
|
|
file_name: str,
|
|
|
|
) -> None:
|
|
|
|
super().__init__(app, f"Copy Custom File to {name}", master=dialog)
|
|
|
|
self.dialog: "ServiceConfigDialog" = dialog
|
|
|
|
self.service: str = service
|
|
|
|
self.file_name: str = file_name
|
|
|
|
self.listbox: Optional[tk.Listbox] = None
|
|
|
|
self.nodes: Dict[str, int] = {}
|
2020-01-09 00:48:04 +00:00
|
|
|
self.draw()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2020-01-09 00:48:04 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
2020-06-24 00:11:39 +01:00
|
|
|
self.top.rowconfigure(1, weight=1)
|
|
|
|
label = ttk.Label(
|
|
|
|
self.top, text=f"{self.service} - {self.file_name}", anchor=tk.CENTER
|
|
|
|
)
|
|
|
|
label.grid(sticky="ew", pady=PADY)
|
|
|
|
|
|
|
|
listbox_scroll = ListboxScroll(self.top)
|
|
|
|
listbox_scroll.grid(sticky="nsew", pady=PADY)
|
|
|
|
self.listbox = listbox_scroll.listbox
|
|
|
|
for canvas_node in self.app.canvas.nodes.values():
|
|
|
|
file_configs = canvas_node.service_file_configs.get(self.service)
|
|
|
|
if not file_configs:
|
|
|
|
continue
|
|
|
|
data = file_configs.get(self.file_name)
|
|
|
|
if not data:
|
|
|
|
continue
|
|
|
|
name = canvas_node.core_node.name
|
|
|
|
self.nodes[name] = canvas_node.id
|
|
|
|
self.listbox.insert(tk.END, name)
|
2020-01-09 00:48:04 +00:00
|
|
|
|
|
|
|
frame = ttk.Frame(self.top)
|
2020-06-24 00:11:39 +01:00
|
|
|
frame.grid(sticky="ew")
|
2020-01-09 00:48:04 +00:00
|
|
|
for i in range(3):
|
|
|
|
frame.columnconfigure(i, weight=1)
|
|
|
|
button = ttk.Button(frame, text="Copy", command=self.click_copy)
|
|
|
|
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
|
|
|
button = ttk.Button(frame, text="View", command=self.click_view)
|
|
|
|
button.grid(row=0, column=1, sticky="ew", padx=PADX)
|
|
|
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
2020-06-24 00:11:39 +01:00
|
|
|
button.grid(row=0, column=2, sticky="ew")
|
2020-01-09 00:48:04 +00:00
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_copy(self) -> None:
|
2020-06-24 00:11:39 +01:00
|
|
|
selection = self.listbox.curselection()
|
|
|
|
if not selection:
|
|
|
|
return
|
|
|
|
name = self.listbox.get(selection)
|
|
|
|
canvas_node_id = self.nodes[name]
|
|
|
|
canvas_node = self.app.canvas.nodes[canvas_node_id]
|
|
|
|
data = canvas_node.service_file_configs[self.service][self.file_name]
|
|
|
|
self.dialog.temp_service_files[self.file_name] = data
|
|
|
|
self.dialog.modified_files.add(self.file_name)
|
|
|
|
self.dialog.service_file_data.text.delete(1.0, tk.END)
|
|
|
|
self.dialog.service_file_data.text.insert(tk.END, data)
|
2020-01-09 00:48:04 +00:00
|
|
|
self.destroy()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def click_view(self) -> None:
|
2020-06-24 00:11:39 +01:00
|
|
|
selection = self.listbox.curselection()
|
|
|
|
if not selection:
|
|
|
|
return
|
|
|
|
name = self.listbox.get(selection)
|
|
|
|
canvas_node_id = self.nodes[name]
|
|
|
|
canvas_node = self.app.canvas.nodes[canvas_node_id]
|
|
|
|
data = canvas_node.service_file_configs[self.service][self.file_name]
|
|
|
|
dialog = ViewConfigDialog(
|
|
|
|
self.app, self, name, self.service, self.file_name, data
|
|
|
|
)
|
|
|
|
dialog.show()
|
2020-01-09 00:48:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ViewConfigDialog(Dialog):
|
2020-01-14 22:08:41 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
app: "Application",
|
2020-06-24 00:11:39 +01:00
|
|
|
master: tk.BaseWidget,
|
|
|
|
name: str,
|
|
|
|
service: str,
|
|
|
|
file_name: str,
|
2020-01-14 22:30:08 +00:00
|
|
|
data: str,
|
2020-06-22 19:04:33 +01:00
|
|
|
) -> None:
|
2020-06-24 00:11:39 +01:00
|
|
|
title = f"{name} Service({service}) File({file_name})"
|
|
|
|
super().__init__(app, title, master=master)
|
2020-01-09 00:48:04 +00:00
|
|
|
self.data = data
|
|
|
|
self.service_data = None
|
|
|
|
self.draw()
|
|
|
|
|
2020-06-22 19:04:33 +01:00
|
|
|
def draw(self) -> None:
|
2020-01-09 00:48:04 +00:00
|
|
|
self.top.columnconfigure(0, weight=1)
|
2020-06-24 00:11:39 +01:00
|
|
|
self.top.rowconfigure(0, weight=1)
|
2020-01-09 00:48:04 +00:00
|
|
|
self.service_data = CodeText(self.top)
|
2020-06-24 00:11:39 +01:00
|
|
|
self.service_data.grid(sticky="nsew", pady=PADY)
|
|
|
|
self.service_data.text.insert(tk.END, self.data)
|
|
|
|
self.service_data.text.config(state=tk.DISABLED)
|
2020-01-09 00:48:04 +00:00
|
|
|
button = ttk.Button(self.top, text="Close", command=self.destroy)
|
2020-06-24 00:11:39 +01:00
|
|
|
button.grid(sticky="ew")
|