From 2193d6a959484fb75bcfff9a962f6ba1153b8606 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Thu, 7 Jan 2021 15:19:50 -0800 Subject: [PATCH] pygui: start adding support to hide nodes, show them, and save metadata about them being hidden --- daemon/core/gui/graph/graph.py | 17 +++++++++++++++++ daemon/core/gui/graph/node.py | 6 ++++++ daemon/core/gui/graph/tags.py | 1 + daemon/core/gui/menubar.py | 5 +++++ 4 files changed, 29 insertions(+) diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index 9862d2c8..199a2006 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -536,6 +536,23 @@ class CanvasGraph(tk.Canvas): self.core.deleted_canvas_nodes(nodes) 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: edge.delete() del self.edges[edge.token] diff --git a/daemon/core/gui/graph/node.py b/daemon/core/gui/graph/node.py index 2ac4219e..b4ab3767 100644 --- a/daemon/core/gui/graph/node.py +++ b/daemon/core/gui/graph/node.py @@ -360,3 +360,9 @@ class CanvasNode: self.core_node.icon = icon_path self.image = Images.create(icon_path, nodeutils.ICON_SIZE) 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) diff --git a/daemon/core/gui/graph/tags.py b/daemon/core/gui/graph/tags.py index 3d3c3611..803b969e 100644 --- a/daemon/core/gui/graph/tags.py +++ b/daemon/core/gui/graph/tags.py @@ -14,6 +14,7 @@ NODE: str = "node" WALLPAPER: str = "wallpaper" SELECTION: str = "selectednodes" MARKER: str = "marker" +HIDDEN: str = "hidden" ORGANIZE_TAGS: List[str] = [ WALLPAPER, GRIDLINE, diff --git a/daemon/core/gui/menubar.py b/daemon/core/gui/menubar.py index fa7853ad..99a4e936 100644 --- a/daemon/core/gui/menubar.py +++ b/daemon/core/gui/menubar.py @@ -116,11 +116,13 @@ class Menubar(tk.Menu): menu.add_command( 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.app.master.bind_all("", self.click_cut) self.app.master.bind_all("", self.click_copy) self.app.master.bind_all("", self.click_paste) self.app.master.bind_all("", self.click_delete) + self.app.master.bind_all("", self.click_hide) self.edit_menu = menu def draw_canvas_menu(self) -> None: @@ -413,6 +415,9 @@ class Menubar(tk.Menu): self.canvas.copy() 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: logging.debug("Click options") dialog = SessionOptionsDialog(self.app)