2019-09-20 00:24:21 +01:00
|
|
|
"""
|
|
|
|
The actions taken when each menubar option is clicked
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
2019-11-26 19:30:25 +00:00
|
|
|
import threading
|
|
|
|
import time
|
2019-09-20 00:24:21 +01:00
|
|
|
import webbrowser
|
2019-10-19 00:42:00 +01:00
|
|
|
from tkinter import filedialog, messagebox
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-11-28 00:27:53 +00:00
|
|
|
import grpc
|
|
|
|
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.appconfig import XMLS_PATH
|
|
|
|
from core.gui.dialogs.about import AboutDialog
|
|
|
|
from core.gui.dialogs.canvassizeandscale import SizeAndScaleDialog
|
2019-12-19 17:50:58 +00:00
|
|
|
from core.gui.dialogs.canvaswallpaper import CanvasWallpaperDialog
|
2019-12-19 17:30:21 +00:00
|
|
|
from core.gui.dialogs.hooks import HooksDialog
|
|
|
|
from core.gui.dialogs.observers import ObserverDialog
|
|
|
|
from core.gui.dialogs.preferences import PreferencesDialog
|
|
|
|
from core.gui.dialogs.servers import ServersDialog
|
|
|
|
from core.gui.dialogs.sessionoptions import SessionOptionsDialog
|
|
|
|
from core.gui.dialogs.sessions import SessionsDialog
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-09-20 00:24:21 +01:00
|
|
|
|
2019-10-11 01:02:28 +01:00
|
|
|
class MenuAction:
|
|
|
|
"""
|
|
|
|
Actions performed when choosing menu items
|
|
|
|
"""
|
|
|
|
|
2019-11-01 20:42:49 +00:00
|
|
|
def __init__(self, app, master):
|
2019-10-11 01:02:28 +01:00
|
|
|
self.master = master
|
2019-11-01 20:42:49 +00:00
|
|
|
self.app = app
|
2019-12-20 00:15:29 +00:00
|
|
|
self.canvas = app.canvas
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-11-26 19:30:25 +00:00
|
|
|
def cleanup_old_session(self, quitapp=False):
|
2019-11-28 00:27:53 +00:00
|
|
|
logging.info("cleaning up old session")
|
2019-12-06 17:42:41 +00:00
|
|
|
start = time.perf_counter()
|
2019-11-26 19:30:25 +00:00
|
|
|
self.app.core.stop_session()
|
|
|
|
self.app.core.delete_session()
|
2019-12-06 17:42:41 +00:00
|
|
|
process_time = time.perf_counter() - start
|
2019-11-26 19:30:25 +00:00
|
|
|
self.app.statusbar.stop_session_callback(process_time)
|
|
|
|
if quitapp:
|
|
|
|
self.app.quit()
|
|
|
|
|
|
|
|
def prompt_save_running_session(self, quitapp=False):
|
2019-10-11 01:02:28 +01:00
|
|
|
"""
|
|
|
|
Prompt use to stop running session before application is closed
|
|
|
|
|
|
|
|
:return: nothing
|
|
|
|
"""
|
|
|
|
logging.info(
|
|
|
|
"menuaction.py: clean_nodes_links_and_set_configuration() Exiting the program"
|
|
|
|
)
|
2019-11-28 00:27:53 +00:00
|
|
|
try:
|
2019-12-10 06:50:26 +00:00
|
|
|
if not self.app.core.is_runtime():
|
2019-11-28 00:27:53 +00:00
|
|
|
self.app.core.delete_session()
|
|
|
|
if quitapp:
|
|
|
|
self.app.quit()
|
|
|
|
else:
|
|
|
|
result = messagebox.askyesnocancel("stop", "Stop the running session?")
|
|
|
|
if result:
|
2019-11-26 19:30:25 +00:00
|
|
|
self.app.statusbar.progress_bar.start(5)
|
|
|
|
thread = threading.Thread(
|
|
|
|
target=self.cleanup_old_session, args=([quitapp])
|
|
|
|
)
|
2019-11-28 00:27:53 +00:00
|
|
|
thread.daemon = True
|
2019-11-26 19:30:25 +00:00
|
|
|
thread.start()
|
2019-11-28 00:27:53 +00:00
|
|
|
elif quitapp:
|
|
|
|
self.app.quit()
|
|
|
|
except grpc.RpcError:
|
2019-12-10 06:50:26 +00:00
|
|
|
logging.exception("error deleting session")
|
2019-11-28 00:27:53 +00:00
|
|
|
if quitapp:
|
|
|
|
self.app.quit()
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-11-08 18:07:23 +00:00
|
|
|
def on_quit(self, event=None):
|
2019-10-11 01:02:28 +01:00
|
|
|
"""
|
|
|
|
Prompt user whether so save running session, and then close the application
|
|
|
|
|
|
|
|
:return: nothing
|
|
|
|
"""
|
2019-11-26 19:30:25 +00:00
|
|
|
self.prompt_save_running_session(quitapp=True)
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def file_save_as_xml(self, event=None):
|
2019-10-11 01:02:28 +01:00
|
|
|
logging.info("menuaction.py file_save_as_xml()")
|
2019-10-19 00:42:00 +01:00
|
|
|
file_path = filedialog.asksaveasfilename(
|
2019-12-12 19:06:52 +00:00
|
|
|
initialdir=str(XMLS_PATH),
|
2019-10-11 01:02:28 +01:00
|
|
|
title="Save As",
|
|
|
|
filetypes=(("EmulationScript XML files", "*.xml"), ("All files", "*")),
|
|
|
|
defaultextension=".xml",
|
|
|
|
)
|
2019-11-01 23:47:30 +00:00
|
|
|
if file_path:
|
|
|
|
self.app.core.save_xml(file_path)
|
2019-10-11 01:02:28 +01:00
|
|
|
|
2019-11-08 05:46:40 +00:00
|
|
|
def file_open_xml(self, event=None):
|
2019-10-11 01:02:28 +01:00
|
|
|
logging.info("menuaction.py file_open_xml()")
|
2019-10-19 00:42:00 +01:00
|
|
|
file_path = filedialog.askopenfilename(
|
2019-12-12 19:06:52 +00:00
|
|
|
initialdir=str(XMLS_PATH),
|
2019-10-11 01:02:28 +01:00
|
|
|
title="Open",
|
2019-11-26 19:32:48 +00:00
|
|
|
filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
|
2019-10-11 01:02:28 +01:00
|
|
|
)
|
2019-11-01 23:47:30 +00:00
|
|
|
if file_path:
|
|
|
|
logging.info("opening xml: %s", file_path)
|
|
|
|
self.prompt_save_running_session()
|
2019-11-26 19:30:25 +00:00
|
|
|
self.app.statusbar.progress_bar.start(5)
|
|
|
|
thread = threading.Thread(target=self.app.core.open_xml, args=([file_path]))
|
|
|
|
thread.start()
|
2019-10-19 00:42:00 +01:00
|
|
|
|
2019-11-11 23:35:48 +00:00
|
|
|
def gui_preferences(self):
|
|
|
|
dialog = PreferencesDialog(self.app, self.app)
|
|
|
|
dialog.show()
|
|
|
|
|
2019-10-22 21:17:47 +01:00
|
|
|
def canvas_size_and_scale(self):
|
2019-11-04 22:09:59 +00:00
|
|
|
dialog = SizeAndScaleDialog(self.app, self.app)
|
|
|
|
dialog.show()
|
2019-10-25 00:50:24 +01:00
|
|
|
|
|
|
|
def canvas_set_wallpaper(self):
|
2019-12-19 17:50:58 +00:00
|
|
|
dialog = CanvasWallpaperDialog(self.app, self.app)
|
2019-11-04 20:29:01 +00:00
|
|
|
dialog.show()
|
2019-10-22 21:17:47 +01:00
|
|
|
|
2019-10-11 01:02:28 +01:00
|
|
|
def help_core_github(self):
|
|
|
|
webbrowser.open_new("https://github.com/coreemu/core")
|
|
|
|
|
|
|
|
def help_core_documentation(self):
|
|
|
|
webbrowser.open_new("http://coreemu.github.io/core/")
|
2019-10-31 21:06:50 +00:00
|
|
|
|
|
|
|
def session_options(self):
|
|
|
|
logging.debug("Click session options")
|
2019-11-01 20:42:49 +00:00
|
|
|
dialog = SessionOptionsDialog(self.app, self.app)
|
2019-11-01 06:17:26 +00:00
|
|
|
dialog.show()
|
|
|
|
|
|
|
|
def session_change_sessions(self):
|
|
|
|
logging.debug("Click session change sessions")
|
2019-11-01 20:42:49 +00:00
|
|
|
dialog = SessionsDialog(self.app, self.app)
|
2019-10-31 21:06:50 +00:00
|
|
|
dialog.show()
|
2019-11-02 01:14:36 +00:00
|
|
|
|
|
|
|
def session_hooks(self):
|
|
|
|
logging.debug("Click session hooks")
|
|
|
|
dialog = HooksDialog(self.app, self.app)
|
|
|
|
dialog.show()
|
2019-11-05 20:37:47 +00:00
|
|
|
|
|
|
|
def session_servers(self):
|
|
|
|
logging.debug("Click session emulation servers")
|
|
|
|
dialog = ServersDialog(self.app, self.app)
|
|
|
|
dialog.show()
|
2019-11-06 01:32:48 +00:00
|
|
|
|
|
|
|
def edit_observer_widgets(self):
|
2019-11-11 22:04:50 +00:00
|
|
|
dialog = ObserverDialog(self.app, self.app)
|
2019-11-06 01:32:48 +00:00
|
|
|
dialog.show()
|
2019-12-06 19:13:43 +00:00
|
|
|
|
|
|
|
def show_about(self):
|
|
|
|
dialog = AboutDialog(self.app, self.app)
|
|
|
|
dialog.show()
|
2019-12-09 16:53:54 +00:00
|
|
|
|
|
|
|
def throughput(self):
|
2019-12-16 19:14:05 +00:00
|
|
|
if not self.app.core.handling_throughputs:
|
|
|
|
self.app.core.enable_throughputs()
|
2019-12-09 16:53:54 +00:00
|
|
|
else:
|
2019-12-16 19:14:05 +00:00
|
|
|
self.app.core.cancel_throughputs()
|
2019-12-20 00:15:29 +00:00
|
|
|
|
|
|
|
def copy(self, event=None):
|
|
|
|
logging.debug("copy")
|
|
|
|
self.app.canvas.copy()
|
|
|
|
|
|
|
|
def paste(self, event=None):
|
|
|
|
logging.debug("paste")
|
|
|
|
self.app.canvas.paste()
|