Allow multiple windows to be open at once

This commit is contained in:
Micah Lee 2020-02-26 14:32:57 -08:00
parent 47064bd5b1
commit cb38473573
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 40 additions and 17 deletions

View file

@ -63,26 +63,50 @@ def main(filename):
docker_installer.start() docker_installer.start()
return return
# Main window windows = []
main_window = MainWindow(common) doc_opened = False
def select_document(filename): # Open a document in a window
# Validate filename def select_document(filename=None):
filename = os.path.abspath(os.path.expanduser(filename)) print(f"select_document, filename={filename}")
try: new_window = MainWindow(common)
open(filename, "rb")
except FileNotFoundError: if filename:
print("File not found") # Validate filename
return False filename = os.path.abspath(os.path.expanduser(filename))
except PermissionError: try:
print("Permission denied") open(filename, "rb")
return False except FileNotFoundError:
common.set_document_filename(filename) print("File not found")
main_window.doc_selection_widget.document_selected.emit() return False
except PermissionError:
print("Permission denied")
return False
common.set_document_filename(filename)
new_window.doc_selection_widget.document_selected.emit()
windows.append(new_window)
doc_opened = True
return True return True
# If filename is passed as an argument, open it # If filename is passed as an argument, open it
if filename is not None: if filename is None:
if platform.system() == "Darwin":
# Wait 0.5 seconds to see if we can an open document event, and if not open a new window without a document
def open_window_if_not_already_open():
if not doc_opened:
select_document()
timer = QtCore.QTimer()
timer.setSingleShot(True)
timer.setInterval(500)
timer.timeout.connect(open_window_if_not_already_open)
timer.start()
else:
# Open a new window without a document
select_document()
else:
# Try opening a window with the docoument selected
if not select_document(filename): if not select_document(filename):
return False return False

View file

@ -79,4 +79,3 @@ class MainWindow(QtWidgets.QMainWindow):
def closeEvent(self, e): def closeEvent(self, e):
e.accept() e.accept()
self.common.app.quit()