pygui: start adding support to hide nodes, show them, and save metadata about them being hidden

This commit is contained in:
Blake Harnden 2021-01-07 15:19:50 -08:00
parent a660b01e93
commit 2193d6a959
4 changed files with 29 additions and 0 deletions

View file

@ -536,6 +536,23 @@ class CanvasGraph(tk.Canvas):
self.core.deleted_canvas_nodes(nodes) self.core.deleted_canvas_nodes(nodes)
self.core.deleted_canvas_edges(edges) self.core.deleted_canvas_edges(edges)
def hide_selected_objects(self) -> None:
edges = set()
for object_id in self.selection:
# delete selection box
selection_id = self.selection[object_id]
self.delete(selection_id)
# hide node and related edges
if object_id in self.nodes:
canvas_node = self.nodes[object_id]
canvas_node.hide()
# hide related edges
for edge in canvas_node.edges:
if edge in edges:
continue
edges.add(edge)
def delete_edge(self, edge: CanvasEdge) -> None: def delete_edge(self, edge: CanvasEdge) -> None:
edge.delete() edge.delete()
del self.edges[edge.token] del self.edges[edge.token]

View file

@ -360,3 +360,9 @@ class CanvasNode:
self.core_node.icon = icon_path self.core_node.icon = icon_path
self.image = Images.create(icon_path, nodeutils.ICON_SIZE) self.image = Images.create(icon_path, nodeutils.ICON_SIZE)
self.canvas.itemconfig(self.id, image=self.image) self.canvas.itemconfig(self.id, image=self.image)
def hide(self) -> None:
self.canvas.addtag_withtag(tags.HIDDEN, self.id)
self.canvas.addtag_withtag(tags.HIDDEN, self.text_id)
self.canvas.itemconfig(self.id, state=tk.HIDDEN)
self.canvas.itemconfig(self.text_id, state=tk.HIDDEN)

View file

@ -14,6 +14,7 @@ NODE: str = "node"
WALLPAPER: str = "wallpaper" WALLPAPER: str = "wallpaper"
SELECTION: str = "selectednodes" SELECTION: str = "selectednodes"
MARKER: str = "marker" MARKER: str = "marker"
HIDDEN: str = "hidden"
ORGANIZE_TAGS: List[str] = [ ORGANIZE_TAGS: List[str] = [
WALLPAPER, WALLPAPER,
GRIDLINE, GRIDLINE,

View file

@ -116,11 +116,13 @@ class Menubar(tk.Menu):
menu.add_command( menu.add_command(
label="Delete", accelerator="Ctrl+D", command=self.click_delete label="Delete", accelerator="Ctrl+D", command=self.click_delete
) )
menu.add_command(label="Hide", accelerator="Ctrl+H", command=self.click_hide)
self.add_cascade(label="Edit", menu=menu) self.add_cascade(label="Edit", menu=menu)
self.app.master.bind_all("<Control-x>", self.click_cut) self.app.master.bind_all("<Control-x>", self.click_cut)
self.app.master.bind_all("<Control-c>", self.click_copy) self.app.master.bind_all("<Control-c>", self.click_copy)
self.app.master.bind_all("<Control-v>", self.click_paste) self.app.master.bind_all("<Control-v>", self.click_paste)
self.app.master.bind_all("<Control-d>", self.click_delete) self.app.master.bind_all("<Control-d>", self.click_delete)
self.app.master.bind_all("<Control-h>", self.click_hide)
self.edit_menu = menu self.edit_menu = menu
def draw_canvas_menu(self) -> None: def draw_canvas_menu(self) -> None:
@ -413,6 +415,9 @@ class Menubar(tk.Menu):
self.canvas.copy() self.canvas.copy()
self.canvas.delete_selected_objects() self.canvas.delete_selected_objects()
def click_hide(self, _event: tk.Event = None) -> None:
self.canvas.hide_selected_objects()
def click_session_options(self) -> None: def click_session_options(self) -> None:
logging.debug("Click options") logging.debug("Click options")
dialog = SessionOptionsDialog(self.app) dialog = SessionOptionsDialog(self.app)