initial classes to help support creating layers for toggling visibility on the canvas for associated items
This commit is contained in:
parent
5e2ca0f549
commit
f72d0d8a69
5 changed files with 176 additions and 0 deletions
60
daemon/core/gui/dialogs/layers.py
Normal file
60
daemon/core/gui/dialogs/layers.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import tkinter as tk
|
||||
from tkinter import messagebox, ttk
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.dialogs.simple import SimpleStringDialog
|
||||
from core.gui.themes import PADX, PADY
|
||||
from core.gui.widgets import ListboxScroll
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
||||
class LayersDialog(Dialog):
|
||||
def __init__(self, app: "Application") -> None:
|
||||
super().__init__(app, "Canvas Layers", modal=False)
|
||||
self.list: Optional[ListboxScroll] = None
|
||||
self.draw()
|
||||
|
||||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
self.list = ListboxScroll(self.top)
|
||||
self.list.grid(sticky=tk.EW, pady=PADY)
|
||||
for name in self.app.canvas.layers.names():
|
||||
self.list.listbox.insert(tk.END, name)
|
||||
frame = ttk.Frame(self.top)
|
||||
frame.grid(sticky=tk.EW)
|
||||
for i in range(3):
|
||||
frame.columnconfigure(i, weight=1)
|
||||
button = ttk.Button(frame, text="Add", command=self.click_add)
|
||||
button.grid(row=0, column=0, sticky=tk.EW, padx=PADX)
|
||||
button = ttk.Button(frame, text="Delete", command=self.click_delete)
|
||||
button.grid(row=0, column=1, sticky=tk.EW, padx=PADX)
|
||||
button = ttk.Button(frame, text="Toggle", command=self.click_toggle)
|
||||
button.grid(row=0, column=2, sticky=tk.EW)
|
||||
|
||||
def click_add(self):
|
||||
name = SimpleStringDialog(self, self.app, "Add Layer", "Layer Name").ask()
|
||||
if name:
|
||||
result = self.app.canvas.layers.add_layer(name)
|
||||
if result:
|
||||
self.list.listbox.insert(tk.END, name)
|
||||
else:
|
||||
messagebox.showerror(
|
||||
"Add Layer", f"Duplicate Layer: {name}", parent=self
|
||||
)
|
||||
|
||||
def click_delete(self):
|
||||
selection = self.list.listbox.curselection()
|
||||
if not selection:
|
||||
return
|
||||
name = self.list.listbox.get(selection)
|
||||
print(name)
|
||||
|
||||
def click_toggle(self):
|
||||
selection = self.list.listbox.curselection()
|
||||
if not selection:
|
||||
return
|
||||
name = self.list.listbox.get(selection)
|
||||
print(name)
|
48
daemon/core/gui/dialogs/simple.py
Normal file
48
daemon/core/gui/dialogs/simple.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from core.gui.dialogs.dialog import Dialog
|
||||
from core.gui.themes import PADX, PADY
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.gui.app import Application
|
||||
|
||||
|
||||
class SimpleStringDialog(Dialog):
|
||||
def __init__(
|
||||
self, master: tk.BaseWidget, app: "Application", title: str, prompt: str
|
||||
):
|
||||
super().__init__(app, title, master=master)
|
||||
self.prompt: str = prompt
|
||||
self.value = tk.StringVar()
|
||||
self.entry: Optional[ttk.Entry] = None
|
||||
self.canceled = False
|
||||
self.draw()
|
||||
|
||||
def draw(self) -> None:
|
||||
self.top.columnconfigure(0, weight=1)
|
||||
label = ttk.Label(self.top, text=self.prompt)
|
||||
label.grid(sticky=tk.EW, pady=PADY)
|
||||
entry = ttk.Entry(self.top, textvariable=self.value)
|
||||
entry.grid(stick=tk.EW, pady=PADY)
|
||||
entry.focus_set()
|
||||
frame = ttk.Frame(self.top)
|
||||
frame.grid(sticky=tk.EW)
|
||||
for i in range(2):
|
||||
frame.columnconfigure(i, weight=1)
|
||||
button = ttk.Button(frame, text="Submit", command=self.destroy)
|
||||
button.grid(row=0, column=0, sticky=tk.EW, padx=PADX)
|
||||
button = ttk.Button(frame, text="Cancel", command=self.click_cancel)
|
||||
button.grid(row=0, column=1, sticky=tk.EW)
|
||||
|
||||
def click_cancel(self):
|
||||
self.canceled = True
|
||||
self.destroy()
|
||||
|
||||
def ask(self) -> Optional[str]:
|
||||
self.show()
|
||||
if self.canceled:
|
||||
return None
|
||||
else:
|
||||
return self.value.get()
|
Loading…
Add table
Add a link
Reference in a new issue