mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 13:44:37 +00:00
qt: save prefs on close more predictably
Ticket #379 reports crashes on quit due to `willSavePrefs` being called when result and details dialogs are already freed. I can't reproduce the crash, but it's still a bad idea to rely on the timing of `aboutToQuit()` to launch this process. This commits uses a more predictable place to emit `willSavePrefs` and I'm pretty sure it will fix the crash at #379.
This commit is contained in:
parent
28d2aa8197
commit
20dc2d63fd
14
qt/app.py
14
qt/app.py
@ -7,7 +7,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os.path as op
|
import os.path as op
|
||||||
|
|
||||||
from PyQt5.QtCore import QTimer, QObject, QCoreApplication, QUrl, pyqtSignal
|
from PyQt5.QtCore import QTimer, QObject, QUrl, pyqtSignal
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QFileDialog, QDialog, QMessageBox
|
||||||
|
|
||||||
@ -73,7 +73,6 @@ class DupeGuru(QObject):
|
|||||||
# In some circumstances, the nag is hidden by other window, which may make the user think
|
# In some circumstances, the nag is hidden by other window, which may make the user think
|
||||||
# that the application haven't launched.
|
# that the application haven't launched.
|
||||||
QTimer.singleShot(0, self.finishedLaunching)
|
QTimer.singleShot(0, self.finishedLaunching)
|
||||||
QCoreApplication.instance().aboutToQuit.connect(self.application_will_terminate)
|
|
||||||
|
|
||||||
def _setupActions(self):
|
def _setupActions(self):
|
||||||
# Setup actions that are common to both the directory dialog and the results window.
|
# Setup actions that are common to both the directory dialog and the results window.
|
||||||
@ -158,6 +157,12 @@ class DupeGuru(QObject):
|
|||||||
if self.resultWindow is not None:
|
if self.resultWindow is not None:
|
||||||
self.resultWindow.show()
|
self.resultWindow.show()
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
self.willSavePrefs.emit()
|
||||||
|
self.prefs.save()
|
||||||
|
self.model.save()
|
||||||
|
QApplication.quit()
|
||||||
|
|
||||||
#--- Signals
|
#--- Signals
|
||||||
willSavePrefs = pyqtSignal()
|
willSavePrefs = pyqtSignal()
|
||||||
|
|
||||||
@ -170,11 +175,6 @@ class DupeGuru(QObject):
|
|||||||
"you set your system locale properly."
|
"you set your system locale properly."
|
||||||
QMessageBox.warning(self.directories_dialog, "Wrong Locale", msg)
|
QMessageBox.warning(self.directories_dialog, "Wrong Locale", msg)
|
||||||
|
|
||||||
def application_will_terminate(self):
|
|
||||||
self.willSavePrefs.emit()
|
|
||||||
self.prefs.save()
|
|
||||||
self.model.save()
|
|
||||||
|
|
||||||
def clearPictureCacheTriggered(self):
|
def clearPictureCacheTriggered(self):
|
||||||
title = tr("Clear Picture Cache")
|
title = tr("Clear Picture Cache")
|
||||||
msg = tr("Do you really want to remove all your cached picture analysis?")
|
msg = tr("Do you really want to remove all your cached picture analysis?")
|
||||||
|
@ -8,7 +8,7 @@ from PyQt5.QtCore import QRect, Qt
|
|||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QWidget, QFileDialog, QHeaderView, QVBoxLayout, QHBoxLayout, QTreeView,
|
QWidget, QFileDialog, QHeaderView, QVBoxLayout, QHBoxLayout, QTreeView,
|
||||||
QAbstractItemView, QSpacerItem, QSizePolicy, QPushButton, QMainWindow, QMenuBar, QMenu, QLabel,
|
QAbstractItemView, QSpacerItem, QSizePolicy, QPushButton, QMainWindow, QMenuBar, QMenu, QLabel,
|
||||||
QApplication, QComboBox
|
QComboBox
|
||||||
)
|
)
|
||||||
from PyQt5.QtGui import QPixmap, QIcon
|
from PyQt5.QtGui import QPixmap, QIcon
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ class DirectoriesDialog(QMainWindow):
|
|||||||
if not self.app.confirm(title, msg):
|
if not self.app.confirm(title, msg):
|
||||||
event.ignore()
|
event.ignore()
|
||||||
if event.isAccepted():
|
if event.isAccepted():
|
||||||
QApplication.quit()
|
self.app.shutdown()
|
||||||
|
|
||||||
#--- Events
|
#--- Events
|
||||||
def addFolderTriggered(self):
|
def addFolderTriggered(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user