hytos / DTI_PID / DTI_PID / App.py @ d4f20853
이력 | 보기 | 이력해설 | 다운로드 (4.19 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 |
from PluginScope import PluginScope |
16 |
|
17 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
18 |
from AppDocData import AppDocData |
19 |
|
20 |
|
21 |
def plugin(name): |
22 |
"""return plugin module"""
|
23 |
plugin_scope = PluginScope.instance() |
24 |
return plugin_scope.get_module(name)
|
25 |
|
26 |
|
27 |
class App(QApplication): |
28 |
""" This is App class inherits from QApplication """
|
29 |
|
30 |
COMPANY = 'DOFTECH'
|
31 |
NAME = 'Digital P&ID'
|
32 |
THREAD_MAX_WORKER = os.cpu_count() |
33 |
|
34 |
def __init__(self, args): |
35 |
import locale |
36 |
|
37 |
super(App, self).__init__(args) |
38 |
app_doc_data = AppDocData.instance() |
39 |
app_style = app_doc_data.loadAppStyle() |
40 |
self.setStyle(app_style)
|
41 |
|
42 |
configs = app_doc_data.getAppConfigs('app', 'stylesheet') |
43 |
if configs and len(configs) == 1: |
44 |
self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\{}'.format(configs[0].value)) |
45 |
self.stylesheet_name = configs[0].value |
46 |
else:
|
47 |
self.loadStyleSheet(os.path.dirname(os.path.realpath(__file__)) + '\\coffee') |
48 |
self.stylesheet_name = 'coffee' |
49 |
|
50 |
# load language file
|
51 |
self._translator = None |
52 |
configs = app_doc_data.getAppConfigs('app', 'language') |
53 |
if configs and len(configs) == 1: |
54 |
qm_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate',
|
55 |
'{0}.qm'.format(configs[0].value)) |
56 |
else:
|
57 |
locale = locale.getdefaultlocale() |
58 |
qm_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'translate', '{0}.qm'.format(locale[0])) |
59 |
|
60 |
self.load_language(qm_file)
|
61 |
# up to here
|
62 |
|
63 |
self._mainWnd = None |
64 |
|
65 |
QtWidgets.qApp = self
|
66 |
|
67 |
'''
|
68 |
@brief load application style sheet
|
69 |
@author humkyung
|
70 |
@date 2018.04.07
|
71 |
'''
|
72 |
|
73 |
def loadStyleSheet(self, sheetName): |
74 |
try:
|
75 |
file = QFile('%s.qss' % sheetName.lower())
|
76 |
file.open(QFile.ReadOnly)
|
77 |
|
78 |
styleSheet = file.readAll()
|
79 |
styleSheet = str(styleSheet, encoding='utf8') |
80 |
|
81 |
self.setStyleSheet(styleSheet)
|
82 |
finally:
|
83 |
file.close()
|
84 |
|
85 |
def load_language(self, language_file): |
86 |
"""
|
87 |
load translator with given language file
|
88 |
"""
|
89 |
try:
|
90 |
if self._translator is not None: |
91 |
self.removeTranslator(self._translator) |
92 |
|
93 |
self.language_name = 'en_us' |
94 |
if os.path.isfile(language_file):
|
95 |
self._translator = QTranslator() # I18N 관련 |
96 |
self._translator.load(language_file)
|
97 |
self.installTranslator(self._translator) |
98 |
self.language_name = os.path.splitext(os.path.basename(language_file))[0] |
99 |
finally:
|
100 |
pass
|
101 |
|
102 |
@staticmethod
|
103 |
def mainWnd(): |
104 |
"""return main window"""
|
105 |
app = QApplication.instance() |
106 |
for widget in app.topLevelWidgets(): |
107 |
if isinstance(widget, QMainWindow): |
108 |
return widget
|
109 |
|
110 |
return None |
111 |
|
112 |
|
113 |
'''
|
114 |
@history 18.04.23 Jeongwoo Change method to execute ProjectDialog(dlg.exec_()→dlg.showDialog())
|
115 |
'''
|
116 |
if __name__ == '__main__': |
117 |
import cv2 |
118 |
from License import QLicenseDialog |
119 |
from ProjectDialog import Ui_Dialog |
120 |
from MainWindow import MainWindow |
121 |
from ExceptionHandler import QExceptionHandler |
122 |
|
123 |
app = App(sys.argv) |
124 |
|
125 |
""" log for unhandled exception """
|
126 |
app.exception_handler = QExceptionHandler() |
127 |
app._excepthook = sys.excepthook |
128 |
sys.excepthook = app.exception_handler.handler |
129 |
|
130 |
if QLicenseDialog.check_license_key():
|
131 |
dlg = Ui_Dialog() |
132 |
|
133 |
selectedProject = dlg.showDialog() |
134 |
if selectedProject is not None: |
135 |
AppDocData.instance().setCurrentProject(selectedProject) |
136 |
# AppDocData.instance().ex = exceptionHandler
|
137 |
app._mainWnd = MainWindow.instance() |
138 |
app._mainWnd.show() |
139 |
sys.exit(app.exec_()) |