From 88625ffad8d48f7ef074f93698ebc2d9747dcbba Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Fri, 17 Jan 2020 15:59:12 -0800 Subject: [PATCH 1/3] fix Ctrl-S issue and node context menu issue --- Pipfile | 0 daemon/core/gui/coreclient.py | 3 +++ daemon/core/gui/dialogs/sessions.py | 2 ++ daemon/core/gui/graph/graph.py | 7 ++++--- daemon/core/gui/menuaction.py | 13 +++++++++++-- daemon/core/gui/menubar.py | 16 ++++++++++++---- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 Pipfile diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..e69de29b diff --git a/daemon/core/gui/coreclient.py b/daemon/core/gui/coreclient.py index 46009324..f4371715 100644 --- a/daemon/core/gui/coreclient.py +++ b/daemon/core/gui/coreclient.py @@ -93,6 +93,9 @@ class CoreClient: self.handling_throughputs = None self.handling_events = None + self.xml_dir = None + self.xml_file = None + def reset(self): # helpers self.interfaces_manager.reset() diff --git a/daemon/core/gui/dialogs/sessions.py b/daemon/core/gui/dialogs/sessions.py index f717462d..6efe598e 100644 --- a/daemon/core/gui/dialogs/sessions.py +++ b/daemon/core/gui/dialogs/sessions.py @@ -189,6 +189,8 @@ class SessionsDialog(Dialog): logging.error("querysessiondrawing.py invalid state") def join_session(self, session_id: int): + if self.app.core.xml_file: + self.app.core.xml_file = None self.app.statusbar.progress_bar.start(5) task = BackgroundTask(self.app, self.app.core.join_session, args=(session_id,)) task.start() diff --git a/daemon/core/gui/graph/graph.py b/daemon/core/gui/graph/graph.py index 2ae47b83..76dc427f 100644 --- a/daemon/core/gui/graph/graph.py +++ b/daemon/core/gui/graph/graph.py @@ -133,7 +133,7 @@ class CanvasGraph(tk.Canvas): self.bind("", lambda e: self.scan_mark(e.x, e.y)) self.bind("", lambda e: self.scan_dragto(e.x, e.y, gain=1)) - def hide_context(self): + def hide_context(self, event=None): if self.context: self.context.unpost() self.context = None @@ -642,9 +642,10 @@ class CanvasGraph(tk.Canvas): if canvas_node: logging.debug("node context: %s", selected) self.context = canvas_node.create_context() + self.context.bind("", 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): """ diff --git a/daemon/core/gui/menuaction.py b/daemon/core/gui/menuaction.py index 4edc4797..5767d4b1 100644 --- a/daemon/core/gui/menuaction.py +++ b/daemon/core/gui/menuaction.py @@ -3,6 +3,7 @@ The actions taken when each menubar option is clicked """ import logging +import os import tkinter as tk import webbrowser from tkinter import filedialog, messagebox @@ -61,8 +62,11 @@ class MenuAction: def file_save_as_xml(self, event: tk.Event = None): logging.info("menuaction.py file_save_as_xml()") + init_dir = self.app.core.xml_dir + if not init_dir: + init_dir = str(XMLS_PATH) file_path = filedialog.asksaveasfilename( - initialdir=str(XMLS_PATH), + initialdir=init_dir, title="Save As", filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")), defaultextension=".xml", @@ -71,14 +75,19 @@ class MenuAction: self.app.core.save_xml(file_path) def file_open_xml(self, event: tk.Event = None): + init_dir = self.app.core.xml_dir + if not init_dir: + init_dir = str(XMLS_PATH) logging.info("menuaction.py file_open_xml()") file_path = filedialog.askopenfilename( - initialdir=str(XMLS_PATH), + initialdir=init_dir, title="Open", filetypes=(("XML Files", "*.xml"), ("All Files", "*")), ) if file_path: logging.info("opening xml: %s", file_path) + self.app.core.xml_file = file_path + self.app.core.xml_dir = str(os.path.dirname(file_path)) self.prompt_save_running_session() self.app.statusbar.progress_bar.start(5) task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,)) diff --git a/daemon/core/gui/menubar.py b/daemon/core/gui/menubar.py index c8908333..2e830d42 100644 --- a/daemon/core/gui/menubar.py +++ b/daemon/core/gui/menubar.py @@ -52,11 +52,9 @@ class Menubar(tk.Menu): label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O" ) self.app.bind_all("", self.menuaction.file_open_xml) - menu.add_command( - label="Save", accelerator="Ctrl+S", command=self.menuaction.file_save_as_xml - ) + menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save) menu.add_command(label="Reload", underline=0, state=tk.DISABLED) - self.app.bind_all("", self.menuaction.file_save_as_xml) + self.app.bind_all("", self.save) menu.add_separator() menu.add_command(label="Export Python script...", state=tk.DISABLED) menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED) @@ -410,3 +408,13 @@ class Menubar(tk.Menu): ) menu.add_command(label="About", command=self.menuaction.show_about) self.add_cascade(label="Help", menu=menu) + + def save(self): + print("save") + xml_file = self.app.core.xml_file + print(xml_file is None) + if xml_file: + print("go here") + self.app.core.save_xml(xml_file) + else: + self.menuaction.file_save_as_xml() From 845198efc6843da685e7e391cc58f56ce776e981 Mon Sep 17 00:00:00 2001 From: Huy Pham <42948410+hpham@users.noreply.github.com> Date: Fri, 17 Jan 2020 16:05:34 -0800 Subject: [PATCH 2/3] remove print statements --- daemon/core/gui/menubar.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/daemon/core/gui/menubar.py b/daemon/core/gui/menubar.py index 2e830d42..afaf2b1a 100644 --- a/daemon/core/gui/menubar.py +++ b/daemon/core/gui/menubar.py @@ -410,11 +410,8 @@ class Menubar(tk.Menu): self.add_cascade(label="Help", menu=menu) def save(self): - print("save") xml_file = self.app.core.xml_file - print(xml_file is None) if xml_file: - print("go here") self.app.core.save_xml(xml_file) else: self.menuaction.file_save_as_xml() From 2ed56fbaa6c546da6f850886eef8b6e22aa24817 Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Fri, 17 Jan 2020 21:12:14 -0800 Subject: [PATCH 3/3] fixed doc formatting that was missed --- daemon/core/emulator/distributed.py | 2 +- daemon/core/emulator/session.py | 6 +++--- daemon/core/nodes/base.py | 6 +++--- daemon/core/nodes/client.py | 2 +- daemon/core/nodes/interface.py | 2 +- daemon/core/nodes/network.py | 2 +- daemon/core/nodes/physical.py | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/daemon/core/emulator/distributed.py b/daemon/core/emulator/distributed.py index 60b83b82..30becfb5 100644 --- a/daemon/core/emulator/distributed.py +++ b/daemon/core/emulator/distributed.py @@ -54,7 +54,7 @@ class DistributedServer: user's home directory :param wait: True to wait for status, False to background process :return: stdout when success -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ replace_env = env is not None diff --git a/daemon/core/emulator/session.py b/daemon/core/emulator/session.py index c3083e70..99c29f1e 100644 --- a/daemon/core/emulator/session.py +++ b/daemon/core/emulator/session.py @@ -181,7 +181,7 @@ class Session: :param _class: node class to get a node type for :return: node type -:raises CoreError: when node type does not exist + :raises CoreError: when node type does not exist """ node_type = NODES_TYPE.get(_class) if node_type is None: @@ -749,7 +749,7 @@ class Session: :param node_id: id of node to update :param options: data to update node with :return: True if node updated, False otherwise -:raises core.CoreError: when node to update does not exist + :raises core.CoreError: when node to update does not exist """ # get node to update node = self.get_node(node_id) @@ -1362,7 +1362,7 @@ class Session: :param _id: node id to retrieve :return: node for the given id -:raises core.CoreError: when node does not exist + :raises core.CoreError: when node does not exist """ if _id not in self.nodes: raise CoreError(f"unknown node id {_id}") diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index d31701b8..a475e672 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -108,7 +108,7 @@ class NodeBase: :param wait: True to wait for status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ if self.server is None: return utils.cmd(args, env, cwd, wait, shell) @@ -410,7 +410,7 @@ class CoreNodeBase(NodeBase): :param wait: True to wait for status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ raise NotImplementedError @@ -591,7 +591,7 @@ class CoreNode(CoreNodeBase): :param wait: True to wait for status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ if self.server is None: return self.client.check_cmd(args, wait=wait, shell=shell) diff --git a/daemon/core/nodes/client.py b/daemon/core/nodes/client.py index cd39eb37..d7642863 100644 --- a/daemon/core/nodes/client.py +++ b/daemon/core/nodes/client.py @@ -60,7 +60,7 @@ class VnodeClient: :param wait: True to wait for command status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises core.CoreCommandError: when there is a non-zero exit status + :raises core.CoreCommandError: when there is a non-zero exit status """ self._verify_connection() args = self.create_cmd(args) diff --git a/daemon/core/nodes/interface.py b/daemon/core/nodes/interface.py index fe15ba95..9ae01bfd 100644 --- a/daemon/core/nodes/interface.py +++ b/daemon/core/nodes/interface.py @@ -80,7 +80,7 @@ class CoreInterface: :param wait: True to wait for status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ if self.server is None: return utils.cmd(args, env, cwd, wait, shell) diff --git a/daemon/core/nodes/network.py b/daemon/core/nodes/network.py index 2d24b24f..6e198d48 100644 --- a/daemon/core/nodes/network.py +++ b/daemon/core/nodes/network.py @@ -309,7 +309,7 @@ class CoreNetwork(CoreNetworkBase): :param wait: True to wait for status, False otherwise :param shell: True to use shell, False otherwise :return: combined stdout and stderr -:raises CoreCommandError: when a non-zero exit status occurs + :raises CoreCommandError: when a non-zero exit status occurs """ logging.debug("network node(%s) cmd", self.name) output = utils.cmd(args, env, cwd, wait, shell) diff --git a/daemon/core/nodes/physical.py b/daemon/core/nodes/physical.py index fc3a7b00..d947c269 100644 --- a/daemon/core/nodes/physical.py +++ b/daemon/core/nodes/physical.py @@ -373,7 +373,7 @@ class Rj45Node(CoreNodeBase, CoreInterface): :param ifindex: interface index :param ifname: interface name :return: interface index -:raises ValueError: when an interface has already been created, one max + :raises ValueError: when an interface has already been created, one max """ with self.lock: if ifindex is None: