diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 65d51fb0..63c20544 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -233,9 +233,7 @@ class CoreClient: canvas_node.update_icon(node.icon) elif event.message_type == MessageType.DELETE: canvas_node = self.canvas_nodes[node.id] - canvas_node.canvas.clear_selection() - canvas_node.canvas.select_object(canvas_node.id) - canvas_node.canvas.delete_selected_objects() + canvas_node.canvas_delete() elif event.message_type == MessageType.ADD: if node.id in self.session.nodes: logger.error("core node already exists: %s", node) diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index 93401f95..1362a2e0 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -103,10 +103,15 @@ class CanvasGraph(tk.Canvas): """ Bind any mouse events or hot keys to the matching action """ + self.bind("", self.copy_selected) + self.bind("", self.paste_selected) + self.bind("", self.cut_selected) + self.bind("", self.delete_selected) + self.bind("", self.hide_selected) self.bind("", self.click_press) self.bind("", self.click_release) self.bind("", self.click_motion) - self.bind("", self.press_delete) + self.bind("", self.delete_selected) self.bind("", self.ctrl_click) self.bind("", self.double_click) self.bind("", self.zoom) @@ -277,7 +282,7 @@ class CanvasGraph(tk.Canvas): if select_id is not None: self.move(select_id, x_offset, y_offset) - def delete_selected_objects(self) -> None: + def delete_selected_objects(self, _event: tk.Event = None) -> None: edges = set() nodes = [] for object_id in self.selection: @@ -307,7 +312,7 @@ class CanvasGraph(tk.Canvas): self.selection.clear() self.core.deleted_canvas_nodes(nodes) - def hide_selected_objects(self) -> None: + def hide_selected(self, _event: tk.Event = None) -> None: for object_id in self.selection: # delete selection box selection_id = self.selection[object_id] @@ -487,17 +492,6 @@ class CanvasGraph(tk.Canvas): if self.select_box and self.manager.mode == GraphMode.SELECT: self.select_box.shape_motion(x, y) - def press_delete(self, _event: tk.Event) -> None: - """ - delete selected nodes and any data that relates to it - """ - logger.debug("press delete key") - if not self.app.core.is_runtime(): - self.delete_selected_objects() - self.app.default_info() - else: - logger.debug("node deletion is disabled during runtime state") - def double_click(self, event: tk.Event) -> None: selected = self.get_selected(event) if selected is not None and selected in self.shapes: @@ -673,7 +667,7 @@ class CanvasGraph(tk.Canvas): edge.complete(dst) return edge - def copy(self) -> None: + def copy_selected(self, _event: tk.Event = None) -> None: if self.core.is_runtime(): logger.debug("copy is disabled during runtime state") return @@ -684,7 +678,25 @@ class CanvasGraph(tk.Canvas): canvas_node = self.nodes[node_id] self.to_copy.append(canvas_node) - def paste(self) -> None: + def cut_selected(self, _event: tk.Event = None) -> None: + if self.core.is_runtime(): + logger.debug("cut is disabled during runtime state") + return + self.copy_selected() + self.delete_selected() + + def delete_selected(self, _event: tk.Event = None) -> None: + """ + delete selected nodes and any data that relates to it + """ + logger.debug("press delete key") + if self.core.is_runtime(): + logger.debug("node deletion is disabled during runtime state") + return + self.delete_selected_objects() + self.app.default_info() + + def paste_selected(self, _event: tk.Event = None) -> None: if self.core.is_runtime(): logger.debug("paste is disabled during runtime state") return diff --git a/daemon/core/gui/graph/node.py b/daemon/core/gui/graph/node.py index 2bd4ae40..b0a78268 100644 --- a/daemon/core/gui/graph/node.py +++ b/daemon/core/gui/graph/node.py @@ -338,7 +338,7 @@ class CanvasNode: def canvas_copy(self) -> None: self.canvas.clear_selection() self.canvas.select_object(self.id) - self.canvas.copy() + self.canvas.copy_selected() def show_config(self) -> None: dialog = NodeConfigDialog(self.app, self) diff --git a/daemon/core/gui/menubar.py b/daemon/core/gui/menubar.py index 5b64ad78..ff0c298a 100644 --- a/daemon/core/gui/menubar.py +++ b/daemon/core/gui/menubar.py @@ -122,11 +122,6 @@ class Menubar(tk.Menu): ) 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: @@ -409,24 +404,24 @@ class Menubar(tk.Menu): def click_copy(self, _event: tk.Event = None) -> None: canvas = self.manager.current() - canvas.copy() + canvas.copy_selected() - def click_paste(self, _event: tk.Event = None) -> None: + def click_paste(self, event: tk.Event = None) -> None: canvas = self.manager.current() - canvas.paste() + canvas.paste_selected(event) - def click_delete(self, _event: tk.Event = None) -> None: + def click_delete(self, event: tk.Event = None) -> None: canvas = self.manager.current() - canvas.delete_selected_objects() + canvas.delete_selected(event) - def click_hide(self, _event: tk.Event = None) -> None: + def click_hide(self, event: tk.Event = None) -> None: canvas = self.manager.current() - canvas.hide_selected_objects() + canvas.hide_selected(event) - def click_cut(self, _event: tk.Event = None) -> None: + def click_cut(self, event: tk.Event = None) -> None: canvas = self.manager.current() - canvas.copy() - canvas.delete_selected_objects() + canvas.copy_selected(event) + canvas.delete_selected(event) def click_show_hidden(self, _event: tk.Event = None) -> None: for canvas in self.manager.all():