From 18a85c604a6b7df5793813b17a6014407da4f61e Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Fri, 26 May 2017 07:59:26 +0100 Subject: [PATCH] Remember window position and force-quit on holding SHIFT --- mindbender/tools/loader/app.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/mindbender/tools/loader/app.py b/mindbender/tools/loader/app.py index 07be4a7ab..dad5f893d 100644 --- a/mindbender/tools/loader/app.py +++ b/mindbender/tools/loader/app.py @@ -31,11 +31,10 @@ def __init__(self, parent=None): module.root, module.project)) self.setFocusPolicy(QtCore.Qt.StrongFocus) - self.setAttribute(QtCore.Qt.WA_DeleteOnClose) body = QtWidgets.QWidget() sidepanel = QtWidgets.QWidget() - sidepanel.setFixedWidth(200) + sidepanel.setFixedWidth(270) footer = QtWidgets.QWidget() footer.setFixedHeight(20) @@ -455,8 +454,9 @@ def _versionschanged(self): self.data["label"]["commentContainer"].show() comment = self.data["label"]["comment"] - comment.setText(version_document["data"].get( - "comment", "No comment")) + comment.setText( + version_document["data"].get("comment") or "No comment" + ) self.data["label"]["sourceContainer"].show() source = self.data["label"]["source"] @@ -566,6 +566,14 @@ def closeEvent(self, event): modifiers = QtWidgets.QApplication.queryKeyboardModifiers() shift_pressed = QtCore.Qt.ShiftModifier & modifiers + if shift_pressed: + print("Force quitted..") + self.setAttribute(QtCore.Qt.WA_DeleteOnClose) + + # Kill on holding SHIFT + modifiers = QtWidgets.QApplication.queryKeyboardModifiers() + shift_pressed = QtCore.Qt.ShiftModifier & modifiers + if shift_pressed: print("Force quitted..") self.setAttribute(QtCore.Qt.WA_DeleteOnClose) @@ -583,11 +591,16 @@ def show(root=None, debug=False, parent=None): """ - try: - module.window.close() - del module.window - except (RuntimeError, AttributeError): - pass + # Remember window + if module.window is not None: + try: + return module.window.show() + except RuntimeError as e: + if not e.message.rstrip().endswith("already deleted."): + raise + + # Garbage collected + module.window = None if debug: import traceback