disable copy/paste/delete shortcuts as well as commands during runtime state

This commit is contained in:
Huy Pham 2020-02-24 12:51:47 -08:00
parent 1dca477e6d
commit 8a0257d130
4 changed files with 25 additions and 6 deletions

View file

@ -1064,6 +1064,3 @@ class CoreClient:
def service_been_modified(self, node_id: int) -> bool:
return node_id in self.modified_service_nodes
def is_runtime_state(self):
return self.state == core_pb2.SessionState.RUNTIME

View file

@ -656,11 +656,11 @@ class CanvasGraph(tk.Canvas):
delete selected nodes and any data that relates to it
"""
logging.debug("press delete key")
if not self.app.core.is_runtime_state():
if not self.app.core.is_runtime():
nodes = self.delete_selection_objects()
self.core.delete_graph_nodes(nodes)
else:
logging.debug("node deletion is disabled during runtime")
logging.info("node deletion is disabled during runtime state")
def double_click(self, event: tk.Event):
selected = self.get_selected(event)
@ -853,11 +853,17 @@ class CanvasGraph(tk.Canvas):
self.core.create_link(edge, source, dest)
def copy(self):
if self.selection and not self.app.core.is_runtime_state():
if self.app.core.is_runtime():
logging.info("copy is disabled during runtime state")
return
if self.selection:
logging.debug("to copy %s nodes", len(self.selection))
self.to_copy = self.selection.keys()
def paste(self):
if self.app.core.is_runtime():
logging.info("paste is disabled during runtime state")
return
# maps original node canvas id to copy node canvas id
copy_map = {}
# the edges that will be copy over

View file

@ -25,6 +25,7 @@ class Menubar(tk.Menu):
self.app = app
self.menuaction = action.MenuAction(app, master)
self.recent_menu = None
self.edit_menu = None
self.draw()
def draw(self):
@ -110,6 +111,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.edit_menu = menu
def draw_canvas_menu(self):
"""
@ -439,3 +441,15 @@ class Menubar(tk.Menu):
self.app.core.save_xml(xml_file)
else:
self.menuaction.file_save_as_xml()
def change_menubar_item_state(self, is_runtime: bool):
for i in range(self.edit_menu.index("end")):
try:
label_name = self.edit_menu.entrycget(i, "label")
if label_name in ["Copy", "Paste"]:
if is_runtime:
self.edit_menu.entryconfig(i, state="disabled")
else:
self.edit_menu.entryconfig(i, state="normal")
except tk.TclError:
logging.debug("Ignore separators")

View file

@ -280,6 +280,7 @@ class Toolbar(ttk.Frame):
server.
"""
self.app.canvas.hide_context()
self.app.menubar.change_menubar_item_state(is_runtime=True)
self.app.statusbar.progress_bar.start(5)
self.app.canvas.mode = GraphMode.SELECT
self.time = time.perf_counter()
@ -469,6 +470,7 @@ class Toolbar(ttk.Frame):
"""
logging.info("Click stop button")
self.app.canvas.hide_context()
self.app.menubar.change_menubar_item_state(is_runtime=False)
self.app.statusbar.progress_bar.start(5)
self.time = time.perf_counter()
task = BackgroundTask(self, self.app.core.stop_session, self.stop_callback)