fix Ctrl-S issue and node context menu issue
This commit is contained in:
parent
b8ded52a66
commit
88625ffad8
6 changed files with 32 additions and 9 deletions
0
Pipfile
Normal file
0
Pipfile
Normal file
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -133,7 +133,7 @@ class CanvasGraph(tk.Canvas):
|
|||
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))
|
||||
|
||||
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("<Leave>", 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):
|
||||
"""
|
||||
|
|
|
@ -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,))
|
||||
|
|
|
@ -52,11 +52,9 @@ class Menubar(tk.Menu):
|
|||
label="Open...", command=self.menuaction.file_open_xml, accelerator="Ctrl+O"
|
||||
)
|
||||
self.app.bind_all("<Control-o>", 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("<Control-s>", self.menuaction.file_save_as_xml)
|
||||
self.app.bind_all("<Control-s>", 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()
|
||||
|
|
Loading…
Reference in a new issue