[main] properly exit app, store window geometry

This commit is contained in:
Jan Grewe 2021-03-06 10:59:44 +01:00
parent 16f670caf0
commit 580512582b
2 changed files with 20 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QSettings
from blipblop.ui.mainwindow import BlipBlop from blipblop.ui.mainwindow import BlipBlop
def main(): def main():
@ -8,11 +9,26 @@ def main():
app.setApplicationName("blipblop") app.setApplicationName("blipblop")
app.setApplicationVersion("0.1") app.setApplicationVersion("0.1")
app.setOrganizationDomain("neuroetho.uni-tuebingen.de") app.setOrganizationDomain("neuroetho.uni-tuebingen.de")
settings = QSettings()
width = settings.value("app/width", 1024)
height = settings.value("app/height", 768)
x = settings.value("app/pos_x", 100)
y = settings.value("app/pos_y", 100)
window = BlipBlop() window = BlipBlop()
window.setMinimumWidth(800) window.setMinimumWidth(800)
window.setMinimumHeight(600) window.setMinimumHeight(600)
window.resize(width, height)
window.move(x, y)
window.show() window.show()
sys.exit(app.exec_())
code = app.exec_()
pos = window.pos()
settings.setValue("app/width", window.width())
settings.setValue("app/height", window.height())
settings.setValue("app/pos_x", pos.x())
settings.setValue("app/pos_y", pos.y())
sys.exit(code)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,5 +1,5 @@
import sys import sys
from PyQt5.QtWidgets import QWidget, QFileDialog, QMainWindow, QMenuBar, QToolBar, QAction, QStatusBar, QSizePolicy from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QMenuBar, QToolBar, QAction, QStatusBar, QSizePolicy
from PyQt5.QtGui import QKeySequence from PyQt5.QtGui import QKeySequence
from PyQt5.QtCore import QSize, QSettings, Qt from PyQt5.QtCore import QSize, QSettings, Qt
@ -61,7 +61,7 @@ class BlipBlop(QMainWindow):
self._auditory_task_action = QAction(cnst.get_icon("auditory_task"), "auditory") self._auditory_task_action = QAction(cnst.get_icon("auditory_task"), "auditory")
self._auditory_task_action.setStatusTip("Start measuring auditory reaction times") self._auditory_task_action.setStatusTip("Start measuring auditory reaction times")
self._auditory_task_action.setShortcut(QKeySequence("Ctrl+2")) self._auditory_task_action.setShortcut(QKeySequence("Ctrl+2"))
self._auditory_task_action.setEnabled(False) self._auditory_task_action.setEnabled(True)
self._auditory_task_action.triggered.connect(self.on_auditory) self._auditory_task_action.triggered.connect(self.on_auditory)
self.create_toolbar() self.create_toolbar()
@ -105,7 +105,7 @@ class BlipBlop(QMainWindow):
self.setMenuBar(menu) self.setMenuBar(menu)
def on_quit(self, s): def on_quit(self, s):
sys.exit() self.close()
def on_new(self): def on_new(self):
self._cw.reset() self._cw.reset()