pygui: added layer menu to nodes, simple toggle support for nodes alone
This commit is contained in:
parent
f72d0d8a69
commit
1f55432ba2
4 changed files with 77 additions and 22 deletions
|
@ -15,6 +15,10 @@ class LayersDialog(Dialog):
|
|||
def __init__(self, app: "Application") -> None:
|
||||
super().__init__(app, "Canvas Layers", modal=False)
|
||||
self.list: Optional[ListboxScroll] = None
|
||||
self.selection: Optional[str] = None
|
||||
self.selection_index: Optional[int] = None
|
||||
self.delete_button: Optional[ttk.Button] = None
|
||||
self.toggle_button: Optional[ttk.Button] = None
|
||||
self.draw()
|
||||
|
||||
def draw(self) -> None:
|
||||
|
@ -23,18 +27,23 @@ class LayersDialog(Dialog):
|
|||
self.list.grid(sticky=tk.EW, pady=PADY)
|
||||
for name in self.app.canvas.layers.names():
|
||||
self.list.listbox.insert(tk.END, name)
|
||||
self.list.listbox.bind("<<ListboxSelect>>", self.list_select)
|
||||
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)
|
||||
self.delete_button = ttk.Button(
|
||||
frame, text="Delete", command=self.click_delete, state=tk.DISABLED
|
||||
)
|
||||
self.delete_button.grid(row=0, column=1, sticky=tk.EW, padx=PADX)
|
||||
self.toggle_button = ttk.Button(
|
||||
frame, text="Toggle", command=self.click_toggle, state=tk.DISABLED
|
||||
)
|
||||
self.toggle_button.grid(row=0, column=2, sticky=tk.EW)
|
||||
|
||||
def click_add(self):
|
||||
def click_add(self) -> None:
|
||||
name = SimpleStringDialog(self, self.app, "Add Layer", "Layer Name").ask()
|
||||
if name:
|
||||
result = self.app.canvas.layers.add_layer(name)
|
||||
|
@ -45,16 +54,21 @@ class LayersDialog(Dialog):
|
|||
"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 list_select(self, event: tk.Event) -> None:
|
||||
self.selection_index = self.list.listbox.curselection()
|
||||
if not self.selection_index:
|
||||
self.selection = None
|
||||
state = tk.DISABLED
|
||||
else:
|
||||
self.selection = self.list.listbox.get(self.selection_index)
|
||||
state = tk.NORMAL
|
||||
self.toggle_button.config(state=state)
|
||||
self.delete_button.config(state=state)
|
||||
|
||||
def click_toggle(self):
|
||||
selection = self.list.listbox.curselection()
|
||||
if not selection:
|
||||
return
|
||||
name = self.list.listbox.get(selection)
|
||||
print(name)
|
||||
def click_delete(self) -> None:
|
||||
self.app.canvas.layers.delete_layer(self.selection)
|
||||
self.list.listbox.delete(self.selection_index)
|
||||
self.list.listbox.event_generate("<<ListboxSelect>>")
|
||||
|
||||
def click_toggle(self) -> None:
|
||||
self.app.canvas.layers.toggle_layer(self.selection)
|
||||
|
|
|
@ -14,6 +14,7 @@ class SimpleStringDialog(Dialog):
|
|||
self, master: tk.BaseWidget, app: "Application", title: str, prompt: str
|
||||
):
|
||||
super().__init__(app, title, master=master)
|
||||
self.bind("<Return>", lambda e: self.destroy())
|
||||
self.prompt: str = prompt
|
||||
self.value = tk.StringVar()
|
||||
self.entry: Optional[ttk.Entry] = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue