2013-04-28 15:38:41 +00:00
|
|
|
#!/usr/bin/python3
|
2017-03-12 01:41:47 +00:00
|
|
|
# Copyright 2017 Virgil Dupras
|
2016-06-01 00:21:07 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2010-10-04 13:42:38 +00:00
|
|
|
|
|
|
|
import sys
|
2011-11-30 16:06:08 +00:00
|
|
|
import os.path as op
|
2014-04-18 14:55:01 +00:00
|
|
|
import gc
|
2010-10-05 08:22:02 +00:00
|
|
|
|
2022-07-08 02:26:45 +00:00
|
|
|
from PyQt6.QtCore import QCoreApplication
|
|
|
|
from PyQt6.QtGui import QIcon, QPixmap
|
|
|
|
from PyQt6.QtWidgets import QApplication
|
2010-10-05 08:22:02 +00:00
|
|
|
|
2011-11-03 14:25:15 +00:00
|
|
|
from hscommon.trans import install_gettext_trans_under_qt
|
2022-05-09 00:22:08 +00:00
|
|
|
from qt.error_report_dialog import install_excepthook
|
2022-05-09 01:33:31 +00:00
|
|
|
from qt.util import setup_qt_logging, create_qsettings
|
2020-06-27 06:08:12 +00:00
|
|
|
from qt import dg_rc # noqa: F401
|
2016-06-01 01:59:31 +00:00
|
|
|
from qt.platform import BASE_PATH
|
|
|
|
from core import __version__, __appname__
|
2010-10-05 08:22:02 +00:00
|
|
|
|
2017-08-28 23:27:17 +00:00
|
|
|
# SIGQUIT is not defined on Windows
|
2020-01-01 02:16:27 +00:00
|
|
|
if sys.platform == "win32":
|
2017-08-28 23:27:17 +00:00
|
|
|
from signal import signal, SIGINT, SIGTERM
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2017-08-28 23:27:17 +00:00
|
|
|
SIGQUIT = SIGTERM
|
|
|
|
else:
|
|
|
|
from signal import signal, SIGINT, SIGTERM, SIGQUIT
|
2017-06-20 16:04:38 +00:00
|
|
|
|
|
|
|
global dgapp
|
|
|
|
dgapp = None
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2021-08-24 05:12:23 +00:00
|
|
|
def signal_handler(sig, frame):
|
2017-06-20 16:04:38 +00:00
|
|
|
global dgapp
|
|
|
|
if dgapp is None:
|
|
|
|
return
|
|
|
|
if sig in (SIGINT, SIGTERM, SIGQUIT):
|
|
|
|
dgapp.SIGTERM.emit()
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2021-08-24 05:12:23 +00:00
|
|
|
def setup_signals():
|
|
|
|
signal(SIGINT, signal_handler)
|
|
|
|
signal(SIGTERM, signal_handler)
|
|
|
|
signal(SIGQUIT, signal_handler)
|
2017-06-20 16:04:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2013-10-20 19:38:24 +00:00
|
|
|
def main():
|
2010-10-05 08:22:02 +00:00
|
|
|
app = QApplication(sys.argv)
|
2020-01-01 02:16:27 +00:00
|
|
|
QCoreApplication.setOrganizationName("Hardcoded Software")
|
2011-01-21 12:57:54 +00:00
|
|
|
QCoreApplication.setApplicationName(__appname__)
|
|
|
|
QCoreApplication.setApplicationVersion(__version__)
|
2021-08-24 05:12:23 +00:00
|
|
|
setup_qt_logging()
|
2021-08-18 02:04:09 +00:00
|
|
|
settings = create_qsettings()
|
2020-01-01 02:16:27 +00:00
|
|
|
lang = settings.value("Language")
|
|
|
|
locale_folder = op.join(BASE_PATH, "locale")
|
2011-11-30 16:06:08 +00:00
|
|
|
install_gettext_trans_under_qt(locale_folder, lang)
|
2017-06-20 16:04:38 +00:00
|
|
|
# Handle OS signals
|
2021-08-24 05:12:23 +00:00
|
|
|
setup_signals()
|
2017-06-20 16:04:38 +00:00
|
|
|
# Let the Python interpreter runs every 500ms to handle signals. This is
|
|
|
|
# required because Python cannot handle signals while the Qt event loop is
|
|
|
|
# running.
|
2022-07-08 02:26:45 +00:00
|
|
|
from PyQt6.QtCore import QTimer
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2017-06-20 16:04:38 +00:00
|
|
|
timer = QTimer()
|
|
|
|
timer.start(500)
|
|
|
|
timer.timeout.connect(lambda: None)
|
2011-01-19 08:47:00 +00:00
|
|
|
# Many strings are translated at import time, so this is why we only import after the translator
|
|
|
|
# has been installed
|
2016-06-01 01:59:31 +00:00
|
|
|
from qt.app import DupeGuru
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2022-04-28 01:53:12 +00:00
|
|
|
app.setWindowIcon(QIcon(QPixmap(f":/{DupeGuru.LOGO_NAME}")))
|
2017-06-20 16:04:38 +00:00
|
|
|
global dgapp
|
2010-10-05 08:22:02 +00:00
|
|
|
dgapp = DupeGuru()
|
2022-05-08 23:51:10 +00:00
|
|
|
install_excepthook("https://github.com/arsenetar/dupeguru/issues")
|
2014-04-18 14:55:01 +00:00
|
|
|
result = app.exec()
|
|
|
|
# I was getting weird crashes when quitting under Windows, and manually deleting main app
|
|
|
|
# references with gc.collect() in between seems to fix the problem.
|
|
|
|
del dgapp
|
|
|
|
gc.collect()
|
|
|
|
del app
|
|
|
|
gc.collect()
|
|
|
|
return result
|
2013-10-20 19:38:24 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2013-10-20 19:38:24 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|