hytos / HYTOS / HYTOS / App.py @ 50bad001
이력 | 보기 | 이력해설 | 다운로드 (3.72 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is application module """
|
3 |
import sys |
4 |
import os |
5 |
|
6 |
if hasattr(sys, 'frozen'): |
7 |
os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH'] |
8 |
|
9 |
from PyQt5.QtCore import * |
10 |
from PyQt5.QtGui import * |
11 |
from PyQt5.QtWidgets import * |
12 |
from PyQt5.QtXml import * |
13 |
from PyQt5.QtSvg import * |
14 |
from PyQt5 import QtWidgets |
15 |
|
16 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
17 |
|
18 |
class App(QApplication): |
19 |
""" This is App class inherits from QApplication """
|
20 |
|
21 |
NAME = 'HYTOS' ### program name |
22 |
|
23 |
def __init__(self, args): |
24 |
import locale |
25 |
from AppDocData import AppDocData |
26 |
|
27 |
super(App, self).__init__(args) |
28 |
app_doc_data = AppDocData.instance() |
29 |
app_style = app_doc_data.loadAppStyle() |
30 |
self.setStyle(app_style)
|
31 |
|
32 |
configs = app_doc_data.getAppConfigs('app', 'stylesheet') |
33 |
if configs and len(configs) == 1: |
34 |
self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\{}'.format(configs[0].value)) |
35 |
self.stylesheet_name = configs[0].value |
36 |
else:
|
37 |
self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\pagefold') |
38 |
self.stylesheet_name = 'pagefold' |
39 |
|
40 |
### load language file
|
41 |
self._translator = None |
42 |
configs = app_doc_data.getAppConfigs('app', 'language') |
43 |
if configs and len(configs) == 1: |
44 |
qm_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate' , '{0}.qm'.format(configs[0].value)) |
45 |
else:
|
46 |
locale = locale.getdefaultlocale() |
47 |
qm_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate' , '{0}.qm'.format(locale[0])) |
48 |
|
49 |
self.load_language(qm_file)
|
50 |
### up to here
|
51 |
|
52 |
self._mainWnd = None |
53 |
|
54 |
QtWidgets.qApp = self
|
55 |
|
56 |
'''
|
57 |
@brief load application style sheet
|
58 |
@author humkyung
|
59 |
@date 2018.04.07
|
60 |
'''
|
61 |
def loadStyleSheet(self, sheetName): |
62 |
try:
|
63 |
file = QFile('%s.qss' % sheetName.lower())
|
64 |
file.open(QFile.ReadOnly)
|
65 |
|
66 |
styleSheet = file.readAll()
|
67 |
styleSheet = str(styleSheet, encoding='utf8') |
68 |
|
69 |
self.setStyleSheet(styleSheet)
|
70 |
finally:
|
71 |
file.close()
|
72 |
|
73 |
def load_language(self, language_file): |
74 |
""" load translator with given language file """
|
75 |
try:
|
76 |
if self._translator is not None: |
77 |
self.removeTranslator(self._translator) |
78 |
|
79 |
self.language_name = 'en_us' |
80 |
if os.path.isfile(language_file):
|
81 |
self._translator = QTranslator() # I18N 관련 |
82 |
self._translator.load(language_file)
|
83 |
self.installTranslator(self._translator) |
84 |
self.language_name = os.path.splitext(os.path.basename(language_file))[0] |
85 |
finally:
|
86 |
pass
|
87 |
|
88 |
'''
|
89 |
@brief create hmb data from database record
|
90 |
@author humkyung
|
91 |
@date 2018.07.12
|
92 |
'''
|
93 |
@staticmethod
|
94 |
def mainWnd(): |
95 |
return QtWidgets.qApp._mainWnd
|
96 |
|
97 |
'''
|
98 |
@history 18.04.23 Jeongwoo Change method to execute ProjectDialog(dlg.exec_()→dlg.showDialog())
|
99 |
'''
|
100 |
if __name__ == '__main__': |
101 |
from AppDocData import AppDocData |
102 |
from ProjectDialog import Ui_Dialog |
103 |
from MainWindow import MainWindow |
104 |
from ExceptionHandler import QExceptionHandler |
105 |
|
106 |
app = App(sys.argv) |
107 |
|
108 |
""" log for unhandled exception """
|
109 |
exceptionHandler = QExceptionHandler() |
110 |
sys._excepthook = sys.excepthook |
111 |
sys.excepthook = exceptionHandler.handler |
112 |
|
113 |
if True: |
114 |
AppDocData.instance().ex = exceptionHandler |
115 |
app._mainWnd = MainWindow.instance() |
116 |
if len(sys.argv) == 2: app._mainWnd.open_drawing(sys.argv[1]) |
117 |
app._mainWnd.show() |
118 |
sys.exit(app.exec_()) |