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()
return
# Main window
main_window = MainWindow(common)
windows = []
doc_opened = False
def select_document(filename):
# Validate filename
filename = os.path.abspath(os.path.expanduser(filename))
try:
open(filename, "rb")
except FileNotFoundError:
print("File not found")
return False
except PermissionError:
print("Permission denied")
return False
common.set_document_filename(filename)
main_window.doc_selection_widget.document_selected.emit()
# Open a document in a window
def select_document(filename=None):
print(f"select_document, filename={filename}")
new_window = MainWindow(common)
if filename:
# Validate filename
filename = os.path.abspath(os.path.expanduser(filename))
try:
open(filename, "rb")
except FileNotFoundError:
print("File not found")
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
# 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):
return False

View file

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