mirror of
https://github.com/arsenetar/dupeguru.git
synced 2024-11-14 03:29:02 +00:00
Handle OS termination signals.
This commit is contained in:
parent
a82a19e074
commit
73dbacace1
@ -68,6 +68,8 @@ class DupeGuru(QObject):
|
||||
self.directories_dialog.show()
|
||||
self.model.load()
|
||||
|
||||
self.SIGTERM.connect(self.handleSIGTERM)
|
||||
|
||||
# The timer scheme is because if the nag is not shown before the application is
|
||||
# completely initialized, the nag will be shown before the app shows up in the task bar
|
||||
# In some circumstances, the nag is hidden by other window, which may make the user think
|
||||
@ -166,6 +168,7 @@ class DupeGuru(QObject):
|
||||
|
||||
#--- Signals
|
||||
willSavePrefs = pyqtSignal()
|
||||
SIGTERM = pyqtSignal()
|
||||
|
||||
#--- Events
|
||||
def finishedLaunching(self):
|
||||
@ -212,6 +215,9 @@ class DupeGuru(QObject):
|
||||
url = QUrl.fromLocalFile(op.abspath(op.join(base_path, 'index.html')))
|
||||
QDesktopServices.openUrl(url)
|
||||
|
||||
def handleSIGTERM(self):
|
||||
self.shutdown()
|
||||
|
||||
#--- model --> view
|
||||
def get_default(self, key):
|
||||
return self.prefs.get_value(key)
|
||||
|
25
run.py
25
run.py
@ -20,6 +20,23 @@ from qt import dg_rc
|
||||
from qt.platform import BASE_PATH
|
||||
from core import __version__, __appname__
|
||||
|
||||
from signal import signal, SIGINT, SIGTERM, SIGQUIT
|
||||
|
||||
global dgapp
|
||||
dgapp = None
|
||||
|
||||
def signalHandler(sig, frame):
|
||||
global dgapp
|
||||
if dgapp is None:
|
||||
return
|
||||
if sig in (SIGINT, SIGTERM, SIGQUIT):
|
||||
dgapp.SIGTERM.emit()
|
||||
|
||||
def setUpSignals():
|
||||
signal(SIGINT, signalHandler)
|
||||
signal(SIGTERM, signalHandler)
|
||||
signal(SIGQUIT, signalHandler)
|
||||
|
||||
def main():
|
||||
app = QApplication(sys.argv)
|
||||
QCoreApplication.setOrganizationName('Hardcoded Software')
|
||||
@ -30,10 +47,18 @@ def main():
|
||||
lang = settings.value('Language')
|
||||
locale_folder = op.join(BASE_PATH, 'locale')
|
||||
install_gettext_trans_under_qt(locale_folder, lang)
|
||||
# Handle OS signals
|
||||
setUpSignals()
|
||||
# Let the Python interpreter run every 500ms to handle signals.
|
||||
from PyQt5.QtCore import QTimer
|
||||
timer = QTimer()
|
||||
timer.start(500)
|
||||
timer.timeout.connect(lambda: None)
|
||||
# Many strings are translated at import time, so this is why we only import after the translator
|
||||
# has been installed
|
||||
from qt.app import DupeGuru
|
||||
app.setWindowIcon(QIcon(QPixmap(":/{0}".format(DupeGuru.LOGO_NAME))))
|
||||
global dgapp
|
||||
dgapp = DupeGuru()
|
||||
install_excepthook('https://github.com/hsoft/dupeguru/issues')
|
||||
result = app.exec()
|
||||
|
Loading…
Reference in New Issue
Block a user