-
Notifications
You must be signed in to change notification settings - Fork 41
/
run_template_qt.py
67 lines (61 loc) · 2.47 KB
/
run_template_qt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# Created By: Virgil Dupras
# Created On: 2009-10-31
# Copyright 2013 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
import sys
import gc
import logging
import os.path as op
from PyQt4.QtCore import QFile, QTextStream, QSettings
from PyQt4.QtGui import QApplication, QIcon, QPixmap
import hscommon.trans
from hscommon.plat import ISLINUX
from qtlib.error_report_dialog import install_excepthook
from qtlib.util import setupQtLogging
from qtlib.preferences import adjust_after_deserialization
import qt.mg_rc
from qt.plat import BASE_PATH
# We import this module below to force cx_freeze to include it because the currency plugins
# need it.
import urllib.request
def main(argv):
app = QApplication(sys.argv)
app.setWindowIcon(QIcon(QPixmap(":/logo_small")))
app.setOrganizationName('Hardcoded Software')
app.setApplicationName('moneyGuru')
settings = QSettings()
LOGGING_LEVEL = logging.DEBUG if adjust_after_deserialization(settings.value('DebugMode')) else logging.WARNING
setupQtLogging(level=LOGGING_LEVEL)
logging.debug('started in debug mode')
if ISLINUX:
stylesheetFile = QFile(':/stylesheet_lnx')
else:
stylesheetFile = QFile(':/stylesheet_win')
stylesheetFile.open(QFile.ReadOnly)
textStream = QTextStream(stylesheetFile)
style = textStream.readAll()
stylesheetFile.close()
app.setStyleSheet(style)
lang = settings.value('Language')
locale_folder = op.join(BASE_PATH, 'locale')
hscommon.trans.install_gettext_trans_under_qt(locale_folder, lang)
# Many strings are translated at import time, so this is why we only import after the translator
# has been installed
from qt.app import MoneyGuru
app.setApplicationVersion(MoneyGuru.VERSION)
mgapp = MoneyGuru()
install_excepthook()
exec_result = app.exec_()
del mgapp
# Since PyQt 4.7.2, I had crashes on exit, and from reading the mailing list, it seems to be
# caused by some weird crap about C++ instance being deleted with python instance still living.
# The worst part is that Phil seems to say this is expected behavior. So, whatever, this
# gc.collect() below is required to avoid a crash.
gc.collect()
return exec_result
if __name__ == "__main__":
sys.exit(main(sys.argv))