pygui: updates to limit copy/paste to the graph widget itself and some small related cleanup to graph hot key functionalities
This commit is contained in:
parent
8e905b6a37
commit
ac5bbf5c6d
4 changed files with 40 additions and 35 deletions
|
@ -233,9 +233,7 @@ class CoreClient:
|
||||||
canvas_node.update_icon(node.icon)
|
canvas_node.update_icon(node.icon)
|
||||||
elif event.message_type == MessageType.DELETE:
|
elif event.message_type == MessageType.DELETE:
|
||||||
canvas_node = self.canvas_nodes[node.id]
|
canvas_node = self.canvas_nodes[node.id]
|
||||||
canvas_node.canvas.clear_selection()
|
canvas_node.canvas_delete()
|
||||||
canvas_node.canvas.select_object(canvas_node.id)
|
|
||||||
canvas_node.canvas.delete_selected_objects()
|
|
||||||
elif event.message_type == MessageType.ADD:
|
elif event.message_type == MessageType.ADD:
|
||||||
if node.id in self.session.nodes:
|
if node.id in self.session.nodes:
|
||||||
logger.error("core node already exists: %s", node)
|
logger.error("core node already exists: %s", node)
|
||||||
|
|
|
@ -103,10 +103,15 @@ class CanvasGraph(tk.Canvas):
|
||||||
"""
|
"""
|
||||||
Bind any mouse events or hot keys to the matching action
|
Bind any mouse events or hot keys to the matching action
|
||||||
"""
|
"""
|
||||||
|
self.bind("<Control-c>", self.copy_selected)
|
||||||
|
self.bind("<Control-v>", self.paste_selected)
|
||||||
|
self.bind("<Control-x>", self.cut_selected)
|
||||||
|
self.bind("<Control-d>", self.delete_selected)
|
||||||
|
self.bind("<Control-h>", self.hide_selected)
|
||||||
self.bind("<ButtonPress-1>", self.click_press)
|
self.bind("<ButtonPress-1>", self.click_press)
|
||||||
self.bind("<ButtonRelease-1>", self.click_release)
|
self.bind("<ButtonRelease-1>", self.click_release)
|
||||||
self.bind("<B1-Motion>", self.click_motion)
|
self.bind("<B1-Motion>", self.click_motion)
|
||||||
self.bind("<Delete>", self.press_delete)
|
self.bind("<Delete>", self.delete_selected)
|
||||||
self.bind("<Control-1>", self.ctrl_click)
|
self.bind("<Control-1>", self.ctrl_click)
|
||||||
self.bind("<Double-Button-1>", self.double_click)
|
self.bind("<Double-Button-1>", self.double_click)
|
||||||
self.bind("<MouseWheel>", self.zoom)
|
self.bind("<MouseWheel>", self.zoom)
|
||||||
|
@ -277,7 +282,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
if select_id is not None:
|
if select_id is not None:
|
||||||
self.move(select_id, x_offset, y_offset)
|
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()
|
edges = set()
|
||||||
nodes = []
|
nodes = []
|
||||||
for object_id in self.selection:
|
for object_id in self.selection:
|
||||||
|
@ -307,7 +312,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.selection.clear()
|
self.selection.clear()
|
||||||
self.core.deleted_canvas_nodes(nodes)
|
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:
|
for object_id in self.selection:
|
||||||
# delete selection box
|
# delete selection box
|
||||||
selection_id = self.selection[object_id]
|
selection_id = self.selection[object_id]
|
||||||
|
@ -487,17 +492,6 @@ class CanvasGraph(tk.Canvas):
|
||||||
if self.select_box and self.manager.mode == GraphMode.SELECT:
|
if self.select_box and self.manager.mode == GraphMode.SELECT:
|
||||||
self.select_box.shape_motion(x, y)
|
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:
|
def double_click(self, event: tk.Event) -> None:
|
||||||
selected = self.get_selected(event)
|
selected = self.get_selected(event)
|
||||||
if selected is not None and selected in self.shapes:
|
if selected is not None and selected in self.shapes:
|
||||||
|
@ -673,7 +667,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
edge.complete(dst)
|
edge.complete(dst)
|
||||||
return edge
|
return edge
|
||||||
|
|
||||||
def copy(self) -> None:
|
def copy_selected(self, _event: tk.Event = None) -> None:
|
||||||
if self.core.is_runtime():
|
if self.core.is_runtime():
|
||||||
logger.debug("copy is disabled during runtime state")
|
logger.debug("copy is disabled during runtime state")
|
||||||
return
|
return
|
||||||
|
@ -684,7 +678,25 @@ class CanvasGraph(tk.Canvas):
|
||||||
canvas_node = self.nodes[node_id]
|
canvas_node = self.nodes[node_id]
|
||||||
self.to_copy.append(canvas_node)
|
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():
|
if self.core.is_runtime():
|
||||||
logger.debug("paste is disabled during runtime state")
|
logger.debug("paste is disabled during runtime state")
|
||||||
return
|
return
|
||||||
|
|
|
@ -338,7 +338,7 @@ class CanvasNode:
|
||||||
def canvas_copy(self) -> None:
|
def canvas_copy(self) -> None:
|
||||||
self.canvas.clear_selection()
|
self.canvas.clear_selection()
|
||||||
self.canvas.select_object(self.id)
|
self.canvas.select_object(self.id)
|
||||||
self.canvas.copy()
|
self.canvas.copy_selected()
|
||||||
|
|
||||||
def show_config(self) -> None:
|
def show_config(self) -> None:
|
||||||
dialog = NodeConfigDialog(self.app, self)
|
dialog = NodeConfigDialog(self.app, self)
|
||||||
|
|
|
@ -122,11 +122,6 @@ class Menubar(tk.Menu):
|
||||||
)
|
)
|
||||||
menu.add_command(label="Hide", accelerator="Ctrl+H", command=self.click_hide)
|
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-c>", self.click_copy)
|
|
||||||
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-h>", self.click_hide)
|
|
||||||
self.edit_menu = menu
|
self.edit_menu = menu
|
||||||
|
|
||||||
def draw_canvas_menu(self) -> None:
|
def draw_canvas_menu(self) -> None:
|
||||||
|
@ -409,24 +404,24 @@ class Menubar(tk.Menu):
|
||||||
|
|
||||||
def click_copy(self, _event: tk.Event = None) -> None:
|
def click_copy(self, _event: tk.Event = None) -> None:
|
||||||
canvas = self.manager.current()
|
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 = 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 = 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 = 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 = self.manager.current()
|
||||||
canvas.copy()
|
canvas.copy_selected(event)
|
||||||
canvas.delete_selected_objects()
|
canvas.delete_selected(event)
|
||||||
|
|
||||||
def click_show_hidden(self, _event: tk.Event = None) -> None:
|
def click_show_hidden(self, _event: tk.Event = None) -> None:
|
||||||
for canvas in self.manager.all():
|
for canvas in self.manager.all():
|
||||||
|
|
Loading…
Reference in a new issue