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
|
|
|
|
|
|
|
from core.api.grpc import core_pb2
|
2019-11-11 23:35:48 +00:00
|
|
|
from coretk.appconfig import XML_PATH
|
2019-11-04 20:29:01 +00:00
|
|
|
from coretk.dialogs.canvasbackground import CanvasBackgroundDialog
|
2019-11-04 22:09:59 +00:00
|
|
|
from coretk.dialogs.canvassizeandscale import SizeAndScaleDialog
|
2019-11-02 01:14:36 +00:00
|
|
|
from coretk.dialogs.hooks import HooksDialog
|
2019-11-11 22:04:50 +00:00
|
|
|
from coretk.dialogs.observers import ObserverDialog
|
2019-11-11 23:35:48 +00:00
|
|
|
from coretk.dialogs.preferences import PreferencesDialog
|
2019-11-05 20:37:47 +00:00
|
|
|
from coretk.dialogs.servers import ServersDialog
|
2019-10-31 21:06:50 +00:00
|
|
|
from coretk.dialogs.sessionoptions import SessionOptionsDialog
|
2019-11-01 06:17:26 +00:00
|
|
|
from coretk.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-10-11 01:02:28 +01:00
|
|
|
|
2019-11-26 19:30:25 +00:00
|
|
|
def cleanup_old_session(self, quitapp=False):
|
|
|
|
start = time.time()
|
|
|
|
self.app.core.stop_session()
|
|
|
|
self.app.core.delete_session()
|
|
|
|
process_time = time.time() - start
|
|
|
|
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-01 20:42:49 +00:00
|
|
|
state = self.app.core.get_session_state()
|
2019-10-11 01:02:28 +01:00
|
|
|
|
|
|
|
if (
|
|
|
|
state == core_pb2.SessionState.SHUTDOWN
|
|
|
|
or state == core_pb2.SessionState.DEFINITION
|
|
|
|
):
|
2019-11-01 20:42:49 +00:00
|
|
|
self.app.core.delete_session()
|
2019-11-26 19:30:25 +00:00
|
|
|
if quitapp:
|
|
|
|
self.app.quit()
|
2019-10-11 01:02:28 +01:00
|
|
|
else:
|
|
|
|
msgbox = messagebox.askyesnocancel("stop", "Stop the running session?")
|
|
|
|
if msgbox or msgbox is False:
|
|
|
|
if msgbox:
|
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])
|
|
|
|
)
|
|
|
|
thread.start()
|
|
|
|
|
|
|
|
# self.app.core.stop_session()
|
|
|
|
# self.app.core.delete_session()
|
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)
|
|
|
|
# self.app.quit()
|
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-11-01 23:47:30 +00:00
|
|
|
initialdir=str(XML_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-11-01 23:47:30 +00:00
|
|
|
initialdir=str(XML_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()
|
|
|
|
# self.app.core.open_xml(file_path)
|
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-11-04 20:29:01 +00:00
|
|
|
dialog = CanvasBackgroundDialog(self.app, self.app)
|
|
|
|
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()
|