enabled node context delete/copy and edit menu delete in python gui

This commit is contained in:
Blake Harnden 2020-03-26 22:24:23 -07:00
parent e0ce29b25a
commit fc40c8d7bb
4 changed files with 39 additions and 24 deletions

View file

@ -1,6 +1,6 @@
import logging
import tkinter as tk
from typing import TYPE_CHECKING, List, Tuple
from typing import TYPE_CHECKING, Tuple
from PIL import Image, ImageTk
@ -440,7 +440,7 @@ class CanvasGraph(tk.Canvas):
if select_id is not None:
self.move(select_id, x_offset, y_offset)
def delete_selection_objects(self) -> List[CanvasNode]:
def delete_selected_objects(self) -> None:
edges = set()
nodes = []
for object_id in self.selection:
@ -484,7 +484,7 @@ class CanvasGraph(tk.Canvas):
shape.delete()
self.selection.clear()
return nodes
self.core.delete_graph_nodes(nodes)
def zoom(self, event: tk.Event, factor: float = None):
if not factor:
@ -640,16 +640,17 @@ class CanvasGraph(tk.Canvas):
self.select_box.shape_motion(x, y)
def click_context(self, event: tk.Event):
logging.info("context: %s", self.context)
if not self.context:
selected = self.get_selected(event)
canvas_node = self.nodes.get(selected)
if canvas_node:
logging.debug("node context: %s", selected)
self.context = canvas_node.create_context()
self.context.bind("<Leave>", self.hide_context)
self.context.bind("<Unmap>", self.hide_context)
self.context.post(event.x_root, event.y_root)
# else:
# self.hide_context()
else:
self.hide_context()
def press_delete(self, event: tk.Event):
"""
@ -657,8 +658,7 @@ class CanvasGraph(tk.Canvas):
"""
logging.debug("press delete key")
if not self.app.core.is_runtime():
nodes = self.delete_selection_objects()
self.core.delete_graph_nodes(nodes)
self.delete_selected_objects()
else:
logging.info("node deletion is disabled during runtime state")

View file

@ -233,17 +233,25 @@ class CanvasNode:
label="Link To Selected", command=self.wireless_link_selected
)
context.add_command(label="Select Members", state=tk.DISABLED)
context.add_command(label="Select Adjacent", state=tk.DISABLED)
context.add_command(label="Create Link To", state=tk.DISABLED)
context.add_command(label="Assign To", state=tk.DISABLED)
context.add_command(label="Move To", state=tk.DISABLED)
context.add_command(label="Cut", state=tk.DISABLED)
context.add_command(label="Copy", state=tk.DISABLED)
context.add_command(label="Paste", state=tk.DISABLED)
context.add_command(label="Delete", state=tk.DISABLED)
context.add_command(label="Hide", state=tk.DISABLED)
edit_menu = tk.Menu(context)
themes.style_menu(edit_menu)
edit_menu.add_command(label="Cut", state=tk.DISABLED)
edit_menu.add_command(label="Copy", command=self.canvas_copy)
edit_menu.add_command(label="Delete", command=self.canvas_delete)
edit_menu.add_command(label="Hide", state=tk.DISABLED)
context.add_cascade(label="Edit", menu=edit_menu)
return context
def canvas_delete(self) -> None:
self.canvas.clear_selection()
self.canvas.selection[self.id] = self
self.canvas.delete_selected_objects()
def canvas_copy(self) -> None:
self.canvas.clear_selection()
self.canvas.selection[self.id] = self
self.canvas.copy()
def show_config(self):
self.canvas.context = None
dialog = NodeConfigDialog(self.app, self.app, self)

View file

@ -152,31 +152,34 @@ class MenuAction:
dialog = ServersDialog(self.app, self.app)
dialog.show()
def edit_observer_widgets(self):
def edit_observer_widgets(self) -> None:
dialog = ObserverDialog(self.app, self.app)
dialog.show()
def show_about(self):
def show_about(self) -> None:
dialog = AboutDialog(self.app, self.app)
dialog.show()
def throughput(self):
def throughput(self) -> None:
if not self.app.core.handling_throughputs:
self.app.core.enable_throughputs()
else:
self.app.core.cancel_throughputs()
def copy(self, event: tk.Event = None):
def copy(self, event: tk.Event = None) -> None:
self.app.canvas.copy()
def paste(self, event: tk.Event = None):
def paste(self, event: tk.Event = None) -> None:
self.app.canvas.paste()
def config_throughput(self):
def delete(self, event: tk.Event = None) -> None:
self.app.canvas.delete_selected_objects()
def config_throughput(self) -> None:
dialog = ThroughputDialog(self.app, self.app)
dialog.show()
def add_recent_file_to_gui_config(self, file_path):
def add_recent_file_to_gui_config(self, file_path) -> None:
recent_files = self.app.guiconfig["recentfiles"]
num_files = len(recent_files)
if num_files == 0:

View file

@ -101,6 +101,9 @@ class Menubar(tk.Menu):
menu.add_command(
label="Paste", accelerator="Ctrl+V", command=self.menuaction.paste
)
menu.add_command(
label="Delete", accelerator="Ctrl+D", command=self.menuaction.delete
)
menu.add_separator()
menu.add_command(label="Select all", accelerator="Ctrl+A", state=tk.DISABLED)
menu.add_command(
@ -113,6 +116,7 @@ class Menubar(tk.Menu):
self.app.master.bind_all("<Control-c>", self.menuaction.copy)
self.app.master.bind_all("<Control-v>", self.menuaction.paste)
self.app.master.bind_all("<Control-d>", self.menuaction.delete)
self.edit_menu = menu
def draw_canvas_menu(self):