Remove restart from systray and replace it with new window

This commit is contained in:
Micah Lee 2021-07-02 10:17:46 -07:00
parent 0b1d8f6a3e
commit fe63689320
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
3 changed files with 13 additions and 10 deletions

View file

@ -23,6 +23,7 @@ from ..global_common import GlobalCommon
# this is a class whose job is to hold a QApplication object and customize it # this is a class whose job is to hold a QApplication object and customize it
class ApplicationWrapper(QtCore.QObject): class ApplicationWrapper(QtCore.QObject):
document_selected = QtCore.Signal(str) document_selected = QtCore.Signal(str)
new_window = QtCore.Signal()
application_activated = QtCore.Signal() application_activated = QtCore.Signal()
def __init__(self): def __init__(self):
@ -112,7 +113,7 @@ def gui_main(custom_container, filename):
vm = None vm = None
# Create the system tray # Create the system tray
systray = SysTray(global_common, gui_common, app) systray = SysTray(global_common, gui_common, app, app_wrapper)
# Start the VM # Start the VM
if vm: if vm:
@ -169,6 +170,7 @@ def gui_main(custom_container, filename):
# If we get a file open event, open it # If we get a file open event, open it
app_wrapper.document_selected.connect(select_document) app_wrapper.document_selected.connect(select_document)
app_wrapper.new_window.connect(select_document)
# If the application is activated and all windows are closed, open a new one # If the application is activated and all windows are closed, open a new one
app_wrapper.application_activated.connect(application_activated) app_wrapper.application_activated.connect(application_activated)

View file

@ -51,7 +51,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.doc_selection_widget.document_selected.connect(self.document_selected) self.doc_selection_widget.document_selected.connect(self.document_selected)
# Only use the waiting widget if we have a VM # Only use the waiting widget if we have a VM
if self.global_common.vm: if self.global_common.vm and self.global_common.vm.state != self.global_common.vm.STATE_ON:
self.waiting_widget.show() self.waiting_widget.show()
self.doc_selection_widget.hide() self.doc_selection_widget.hide()
else: else:

View file

@ -3,11 +3,12 @@ from PySide2 import QtWidgets
class SysTray(QtWidgets.QSystemTrayIcon): class SysTray(QtWidgets.QSystemTrayIcon):
def __init__(self, global_common, gui_common, app): def __init__(self, global_common, gui_common, app, app_wrapper):
super(SysTray, self).__init__() super(SysTray, self).__init__()
self.global_common = global_common self.global_common = global_common
self.gui_common = gui_common self.gui_common = gui_common
self.app = app self.app = app
self.app_wrapper = app_wrapper
self.setIcon(self.gui_common.get_window_icon()) self.setIcon(self.gui_common.get_window_icon())
@ -17,8 +18,9 @@ class SysTray(QtWidgets.QSystemTrayIcon):
self.status_action = menu.addAction("...") self.status_action = menu.addAction("...")
self.status_action.setEnabled(False) self.status_action.setEnabled(False)
menu.addSeparator() menu.addSeparator()
self.restart_action = menu.addAction("Restart")
self.restart_action.triggered.connect(self.restart_clicked) self.new_action = menu.addAction("New window")
self.new_action.triggered.connect(self.new_window)
self.quit_action = menu.addAction("Quit") self.quit_action = menu.addAction("Quit")
self.quit_action.triggered.connect(self.quit_clicked) self.quit_action.triggered.connect(self.quit_clicked)
@ -32,16 +34,15 @@ class SysTray(QtWidgets.QSystemTrayIcon):
def vm_state_change(self, state): def vm_state_change(self, state):
if state == self.global_common.vm.STATE_OFF: if state == self.global_common.vm.STATE_OFF:
self.status_action.setText("Dangerzone VM is off") self.status_action.setText("Dangerzone VM is off")
self.restart_action.setEnabled(True)
elif state == self.global_common.vm.STATE_STARTING: elif state == self.global_common.vm.STATE_STARTING:
self.status_action.setText("Dangerzone VM is starting...") self.status_action.setText("Dangerzone VM is starting...")
self.restart_action.setEnabled(False)
elif state == self.global_common.vm.STATE_ON: elif state == self.global_common.vm.STATE_ON:
self.status_action.setText("Dangerzone VM is running") self.status_action.setText("Dangerzone VM is running")
self.restart_action.setEnabled(True) elif state == self.global_common.vm.STATE_FAIL:
self.status_action.setText("Dangerzone VM failed to start")
def restart_clicked(self): def new_window(self):
self.global_common.vm.restart() self.app_wrapper.new_window.emit()
def quit_clicked(self): def quit_clicked(self):
self.app.quit() self.app.quit()