fix Ctrl-S issue and node context menu issue

This commit is contained in:
Huy Pham 2020-01-17 15:59:12 -08:00
parent b8ded52a66
commit 88625ffad8
6 changed files with 32 additions and 9 deletions

0
Pipfile Normal file
View file

View file

@ -93,6 +93,9 @@ class CoreClient:
self.handling_throughputs = None self.handling_throughputs = None
self.handling_events = None self.handling_events = None
self.xml_dir = None
self.xml_file = None
def reset(self): def reset(self):
# helpers # helpers
self.interfaces_manager.reset() self.interfaces_manager.reset()

View file

@ -189,6 +189,8 @@ class SessionsDialog(Dialog):
logging.error("querysessiondrawing.py invalid state") logging.error("querysessiondrawing.py invalid state")
def join_session(self, session_id: int): 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) self.app.statusbar.progress_bar.start(5)
task = BackgroundTask(self.app, self.app.core.join_session, args=(session_id,)) task = BackgroundTask(self.app, self.app.core.join_session, args=(session_id,))
task.start() task.start()

View file

@ -133,7 +133,7 @@ class CanvasGraph(tk.Canvas):
self.bind("<ButtonPress-3>", lambda e: self.scan_mark(e.x, e.y)) self.bind("<ButtonPress-3>", lambda e: self.scan_mark(e.x, e.y))
self.bind("<B3-Motion>", lambda e: self.scan_dragto(e.x, e.y, gain=1)) self.bind("<B3-Motion>", lambda e: self.scan_dragto(e.x, e.y, gain=1))
def hide_context(self): def hide_context(self, event=None):
if self.context: if self.context:
self.context.unpost() self.context.unpost()
self.context = None self.context = None
@ -642,9 +642,10 @@ class CanvasGraph(tk.Canvas):
if canvas_node: if canvas_node:
logging.debug("node context: %s", selected) logging.debug("node context: %s", selected)
self.context = canvas_node.create_context() self.context = canvas_node.create_context()
self.context.bind("<Leave>", self.hide_context)
self.context.post(event.x_root, event.y_root) self.context.post(event.x_root, event.y_root)
else: # else:
self.hide_context() # self.hide_context()
def press_delete(self, event: tk.Event): def press_delete(self, event: tk.Event):
""" """

View file

@ -3,6 +3,7 @@ The actions taken when each menubar option is clicked
""" """
import logging import logging
import os
import tkinter as tk import tkinter as tk
import webbrowser import webbrowser
from tkinter import filedialog, messagebox from tkinter import filedialog, messagebox
@ -61,8 +62,11 @@ class MenuAction:
def file_save_as_xml(self, event: tk.Event = None): def file_save_as_xml(self, event: tk.Event = None):
logging.info("menuaction.py file_save_as_xml()") 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( file_path = filedialog.asksaveasfilename(
initialdir=str(XMLS_PATH), initialdir=init_dir,
title="Save As", title="Save As",
filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")), filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")),
defaultextension=".xml", defaultextension=".xml",
@ -71,14 +75,19 @@ class MenuAction:
self.app.core.save_xml(file_path) self.app.core.save_xml(file_path)
def file_open_xml(self, event: tk.Event = None): 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()") logging.info("menuaction.py file_open_xml()")
file_path = filedialog.askopenfilename( file_path = filedialog.askopenfilename(
initialdir=str(XMLS_PATH), initialdir=init_dir,
title="Open", title="Open",
filetypes=(("XML Files", "*.xml"), ("All Files", "*")), filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
) )
if file_path: if file_path:
logging.info("opening xml: %s", 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.prompt_save_running_session()
self.app.statusbar.progress_bar.start(5) self.app.statusbar.progress_bar.start(5)
task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,)) task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,))

View file

@ -52,11 +52,9 @@ class Menubar(tk.Menu):
label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O" label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O"
) )
self.app.bind_all("<Control-o>", self.menuaction.file_open_xml) self.app.bind_all("<Control-o>", self.menuaction.file_open_xml)
menu.add_command( menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
label="Save", accelerator="Ctrl+S", command=self.menuaction.file_save_as_xml
)
menu.add_command(label="Reload", underline=0, state=tk.DISABLED) menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
self.app.bind_all("<Control-s>", self.menuaction.file_save_as_xml) self.app.bind_all("<Control-s>", self.save)
menu.add_separator() menu.add_separator()
menu.add_command(label="Export Python script...", state=tk.DISABLED) menu.add_command(label="Export Python script...", state=tk.DISABLED)
menu.add_command(label="Execute XML or 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) menu.add_command(label="About", command=self.menuaction.show_about)
self.add_cascade(label="Help", menu=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()