프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / AppRibbon.py @ 30a35908

이력 | 보기 | 이력해설 | 다운로드 (17.2 KB)

1 ba7d75e6 humkyung
# coding: utf-8
2
""" This is license module """
3
4
import sys
5
import os
6
from functools import partial
7
8
from PyQt5.QtCore import *
9
from PyQt5.QtGui import *
10
from PyQt5.QtWidgets import *
11
from PyQt5.QtSvg import *
12
from PyQt5.QtCore import QTranslator
13
from PyQt5.QtCore import QLocale
14
15
# PyQtRibbon: import, and error msg if not installed
16
try:
17
    from PyQtRibbon.FileMenu import QFileMenu, QFileMenuPanel
18
    from PyQtRibbon.RecentFilesManager import QRecentFilesManager
19
    from PyQtRibbon.Ribbon import QRibbon, QRibbonTab, QRibbonSection
20
except (ImportError, NameError):
21
    errormsg = 'You haven\'t installed PyQtRibbon, or your installation of it is broken. Please download or fix it.'
22
    raise Exception(errormsg)
23
24
25
class AppRibbon(QRibbon):
26
    """ Class that represents App ribbon """
27
    def __init__(self):
28
        """ Creates and initializes the App Ribbon """
29 8770b470 humkyung
        from AppDocData import AppDocData
30
31 ba7d75e6 humkyung
        QRibbon.__init__(self)
32
33
        self._panes = {}
34 8770b470 humkyung
        self._advanced_mode = False
35
        app_doc_data = AppDocData.instance()
36
        configs = app_doc_data.getAppConfigs('app', 'mode')
37
        self._advanced_mode = True if configs and 1 == len(configs) and 'advanced' == configs[0].value else False
38 ba7d75e6 humkyung
39
        # Set up the file menu
40 8770b470 humkyung
        self.fileMenu = AppRibbonFileMenu(self._advanced_mode)
41 ba7d75e6 humkyung
        self.setFileMenu(self.fileMenu)
42
43
        # Add tabs
44
        self.add_home_tab()
45
        self.add_edit_tab()
46 8770b470 humkyung
        if self._advanced_mode:
47
            self.add_data_tab()
48 ba7d75e6 humkyung
        self.add_view_tab()
49 8770b470 humkyung
        if self._advanced_mode:
50
            self.add_tool_tab()
51 ba7d75e6 humkyung
        self.add_help_tab()
52
53 62fdafa4 esham21
        self.add_tab_shortcut()
54
55 8770b470 humkyung
    @property
56
    def advanced_mode(self) -> bool:
57
        return self._advanced_mode
58
59 62fdafa4 esham21
    def add_tab_shortcut(self):
60
        """ add shortcut to each tabs """
61
        pane = self._panes['Home File']
62
        self.connect_shortcut(pane)
63
64
        pane = self._panes['Edit']
65
        self.connect_shortcut(pane)
66
67
        pane = self._panes['Help']
68
        self.connect_shortcut(pane)
69
70
        pane = self._panes['View']
71
        self.connect_shortcut(pane)
72
73 ac2f33ba esham21
        if 'Data' in self._panes:
74
            pane = self._panes['Data']
75
            self.connect_shortcut(pane)
76 62fdafa4 esham21
77 ac2f33ba esham21
        if 'Tool' in self._panes:
78
            pane = self._panes['Tool']
79
            self.connect_shortcut(pane)
80 62fdafa4 esham21
81
    def connect_shortcut(self, parent):
82
        from App import App
83
84
        main_wnd = App.mainWnd()
85
86
        shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), parent)
87
        shortcut.activated.connect(main_wnd.actionSaveCliked)
88
89
        shortcut = QShortcut(QKeySequence(Qt.Key_F5), parent)
90
        shortcut.activated.connect(main_wnd.recognize)
91
        shortcut = QShortcut(QKeySequence(Qt.Key_L), parent)
92
        shortcut.activated.connect(main_wnd.onPlaceLine)
93
        shortcut = QShortcut(QKeySequence(Qt.Key_T), parent)
94
        shortcut.activated.connect(main_wnd.onAreaOcr)
95
        shortcut = QShortcut(QKeySequence(Qt.Key_V), parent)
96
        shortcut.activated.connect(main_wnd.onValidation)
97
98
        shortcut = QShortcut(QKeySequence(Qt.Key_Z), parent)
99
        shortcut.activated.connect(main_wnd.onAreaZoom)
100 05092b2a esham21
        shortcut = QShortcut(QKeySequence(Qt.Key_W), parent)
101
        shortcut.activated.connect(main_wnd.change_display_colors)
102 62fdafa4 esham21
103
        shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), parent)
104
        shortcut.activated.connect(main_wnd.findReplaceTextClicked)
105
106
        shortcut = QShortcut(QKeySequence(Qt.Key_F1), parent)
107
        shortcut.activated.connect(main_wnd.on_help)
108
109
        shortcut = QShortcut(QKeySequence(Qt.Key_1), parent)
110
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_1))
111
        shortcut = QShortcut(QKeySequence(Qt.Key_2), parent)
112
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_2))
113
        shortcut = QShortcut(QKeySequence(Qt.Key_3), parent)
114
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_3))
115
        shortcut = QShortcut(QKeySequence(Qt.Key_4), parent)
116
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_4))
117
        shortcut = QShortcut(QKeySequence(Qt.Key_5), parent)
118
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_5))
119
        shortcut = QShortcut(QKeySequence(Qt.Key_6), parent)
120
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_6))
121
        shortcut = QShortcut(QKeySequence(Qt.Key_7), parent)
122
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, Qt.Key_7))
123
        shortcut = QShortcut(QKeySequence(96), parent)
124
        shortcut.activated.connect(partial(main_wnd.on_view_toggle, 96))
125
                
126
127 ba7d75e6 humkyung
    def get_pane(self, name: str) -> QWidget:
128
        return self._panes[name] if name in self._panes else None
129
130
    def add_home_tab(self) -> None:
131
        """ Adds the Home Tab """
132
        from App import App
133
        from AppDocData import AppDocData
134
        from AppRibbonPanes import QHomeFilePane, QHomePane, QHomeVisualizationPane
135
        from LineTypeConditions import LineTypeConditions
136
        from DisplayColors import DisplayColors
137
        from DisplayColors import DisplayOptions
138
139
        try:
140
            tab = self.addTab(self.tr('Home'))
141
            app_doc_data = AppDocData.instance()
142
            main_wnd = App.mainWnd()
143
144
            # File Section
145
            cSection = tab.addSection(self.tr('File'))
146
            pane = QHomeFilePane()
147
            self._panes['Home File'] = pane
148 6ee8daf3 esham21
            pane.ui.toolButtonFileOpen.setEnabled(False)
149
            #pane.ui.toolButtonFileOpen.clicked.connect(partial(main_wnd.open_image_drawing, None))
150
            #shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_O), pane.ui.toolButtonFileOpen)
151
            #shortcut.activated.connect(partial(main_wnd.open_image_drawing, None))
152 ba7d75e6 humkyung
            pane.ui.toolButtonFileSave.clicked.connect(main_wnd.actionSaveCliked)
153 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), pane.ui.toolButtonFileSave)
154
            #shortcut.activated.connect(main_wnd.actionSaveCliked)
155 ba7d75e6 humkyung
            cSection.addCustomWidget(pane)
156
157
            # Home Section
158
            cSection = tab.addSection(self.tr('Home'))
159
            pane = QHomePane()
160
            self._panes['Home'] = pane
161
            pane.ui.toolButtonRecognition.clicked.connect(main_wnd.recognize)
162 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_F5), pane.ui.toolButtonRecognition)
163
            #shortcut.activated.connect(main_wnd.recognize)
164 ba7d75e6 humkyung
            pane.ui.toolButtonStreamline.clicked.connect(main_wnd.on_streamline)
165
            pane.ui.toolButtonLinkAttribute.clicked.connect(main_wnd.connect_attributes)
166
            pane.ui.toolButtonInitialize.clicked.connect(main_wnd.on_initialize_scene)
167
            pane.ui.toolButtonUndo.clicked.connect(main_wnd._scene.undo_stack.undo)
168
            pane.ui.toolButtonRedo.clicked.connect(main_wnd._scene.undo_stack.redo)
169
            pane.ui.toolButtonLine.clicked.connect(main_wnd.onPlaceLine)
170 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_L), pane.ui.toolButtonLine)
171
            #shortcut.activated.connect(main_wnd.onPlaceLine)
172 ba7d75e6 humkyung
173
            """fill line type"""
174
            for condition in LineTypeConditions.items():
175
                pane.ui.comboBoxLineType.addItem(condition.name)
176
177
            configs = app_doc_data.getConfigs('Line', 'Default Type')
178
            value = configs[0].value if 1 == len(configs) else ''
179
            if value:
180
                at = pane.ui.comboBoxLineType.findText(value)
181
                pane.ui.comboBoxLineType.setCurrentIndex(at)
182
            else:
183
                at = pane.ui.comboBoxLineType.findText('Secondary')
184
                pane.ui.comboBoxLineType.setCurrentIndex(at)
185
            """up to here"""
186
187
            pane.ui.toolButtonOCR.clicked.connect(main_wnd.onAreaOcr)
188 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_T), pane.ui.toolButtonOCR)
189
            #shortcut.activated.connect(main_wnd.onAreaOcr)
190 ba7d75e6 humkyung
            pane.ui.toolButtonVendor.clicked.connect(main_wnd.onVendor)
191
            pane.ui.comboBoxPackage.addItems(['Equipment Package', 'Vendor Package'])
192
            pane.ui.toolButtonValidate.clicked.connect(main_wnd.onValidation)
193 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_V), pane.ui.toolButtonValidate)
194
            #shortcut.activated.connect(main_wnd.onValidation)
195 ba7d75e6 humkyung
            pane.ui.toolButtonRotateCW.clicked.connect(main_wnd.onRotate)
196
            cSection.addCustomWidget(pane)
197
198
            # Visualization Section
199
            cSection = tab.addSection(self.tr('Visualization'))
200
            pane = QHomeVisualizationPane()
201
            self._panes['Home Visualization'] = pane
202
            pane.ui.radioButtonByGroup.toggled.connect(main_wnd.display_colors)
203
            pane.ui.radioButtonByType.toggled.connect(main_wnd.display_colors)
204
            pane.ui.radioButtonByStreamNo.toggled.connect(main_wnd.display_colors)
205
            if DisplayColors.instance().option == DisplayOptions.DisplayByLineNo:
206
                pane.ui.radioButtonByGroup.setChecked(True)
207
            elif DisplayColors.instance().option == DisplayOptions.DisplayByLineType:
208
                pane.ui.radioButtonByType.setChecked(True)
209
            elif DisplayColors.instance().option == DisplayOptions.DisplayByStreamNo:
210
                pane.ui.radioButtonByStreamNo.setChecked(True)
211
212
            pane.ui.toolButtonZoom.clicked.connect(main_wnd.onAreaZoom)
213 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_Z), pane.ui.toolButtonZoom)
214
            #shortcut.activated.connect(main_wnd.onAreaZoom)
215 ba7d75e6 humkyung
            pane.ui.toolButtonFitWindow.clicked.connect(main_wnd.fitWindow)
216 07336d71 humkyung
            pane.ui.toolButtonLockAxis.clicked.connect(main_wnd.on_toggle_lock_axis)
217 ba7d75e6 humkyung
            cSection.addCustomWidget(pane)
218
        except Exception as ex:
219
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
220
                      f"{sys.exc_info()[-1].tb_lineno}"
221
222
    def add_edit_tab(self) -> None:
223
        """ Adds the Edit Tab """
224
        from App import App
225
        from AppRibbonPanes import QEditPane
226
227
        try:
228
            tab = self.addTab(self.tr('Edit'))  # "Edit"
229
            main_wnd = App.mainWnd()
230
231 6ee8daf3 esham21
            # Edit Section
232 ba7d75e6 humkyung
            cSection = tab.addSection(self.tr('Edit'))
233
            pane = QEditPane()
234 62fdafa4 esham21
            self._panes['Edit'] = pane
235 ba7d75e6 humkyung
            pane.ui.toolButtonFindReplaceText.clicked.connect(main_wnd.findReplaceTextClicked)
236 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), pane.ui.toolButtonFindReplaceText)
237
            #shortcut.activated.connect(main_wnd.findReplaceTextClicked)
238 ba7d75e6 humkyung
            pane.ui.toolButtonTextDataList.clicked.connect(main_wnd.showTextDataList)
239
            pane.ui.toolButtonSymbolReplaceInsert.clicked.connect(main_wnd.replaceInsertSymbolClicked)
240
            pane.ui.toolButtonConnectLineToSymbol.clicked.connect(main_wnd.on_connect_line_to_symbol)
241 2c6bfc15 esham21
            pane.ui.toolButtonOCRUnknown.clicked.connect(main_wnd.on_ocr_unknown_items)
242 ba7d75e6 humkyung
            cSection.addCustomWidget(pane)
243
        except Exception as ex:
244
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
245
                      f"{sys.exc_info()[-1].tb_lineno}"
246
247
    def add_data_tab(self) -> None:
248
        """Adds the Data Tab"""
249
        from App import App
250
        from AppRibbonPanes import QDataPane
251
252
        try:
253
            tab = self.addTab(self.tr('Data'))  # "Data"
254
            main_wnd = App.mainWnd()
255
256
            # File Section
257
            cSection = tab.addSection(self.tr('Data'))
258
            pane = QDataPane()
259 d70707e7 esham21
            self._panes['Data'] = pane
260 ba7d75e6 humkyung
            pane.ui.toolButtonHMBData.clicked.connect(main_wnd.onHMBData)
261
            pane.ui.toolButtonEngInfoList.clicked.connect(main_wnd.showItemDataList)
262
            pane.ui.toolButtonSpecialItemTypes.clicked.connect(main_wnd.on_show_special_item_types)
263
            pane.ui.toolButtonOPCRelation.clicked.connect(main_wnd.on_show_opc_relation)
264
            pane.ui.toolButtonCodeTable.clicked.connect(main_wnd.onShowCodeTable)
265
            pane.ui.toolButtonCustomCodeTable.clicked.connect(main_wnd.onShowCustomCodeTable)
266
            pane.ui.toolButtonReplaceCodeTable.clicked.connect(main_wnd.onShowReplaceCodeTable)
267
            pane.ui.toolButtonGlobalValidation.clicked.connect(main_wnd.on_validation_global_clicked)
268
            pane.ui.toolButtonOCRTraining.clicked.connect(main_wnd.oCRTrainingClicked)
269
            pane.ui.toolButtonSymbolTraining.clicked.connect(main_wnd.symbolTrainingClicked)
270
            pane.ui.toolButtonMakeLabelData.clicked.connect(main_wnd.on_make_label_data)
271 41162b7d esham21
            pane.ui.toolButtonLineList.clicked.connect(main_wnd.on_line_list)
272 ba7d75e6 humkyung
            cSection.addCustomWidget(pane)
273
        except Exception as ex:
274
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
275
                      f"{sys.exc_info()[-1].tb_lineno}"
276
277
    def add_view_tab(self) -> None:
278
        """Adds the View Tab"""
279
        from App import App
280
        from AppRibbonPanes import QViewPane
281
282
        try:
283
            tab = self.addTab(self.tr('View'))
284
            main_wnd = App.mainWnd()
285
286
            # View Section
287
            cSection = tab.addSection(self.tr('View'))
288
            pane = QViewPane()
289
            self._panes['View'] = pane
290
            pane.ui.toolButtonViewImageDrawing.clicked.connect(main_wnd.onViewImageDrawing)
291
            pane.ui.toolButtonViewText.clicked.connect(main_wnd.onViewText)
292
            pane.ui.toolButtonViewSymbol.clicked.connect(main_wnd.onViewSymbol)
293
            pane.ui.toolButtonViewLine.clicked.connect(main_wnd.onViewLine)
294
            pane.ui.toolButtonViewUnknown.clicked.connect(main_wnd.onViewUnknown)
295
            pane.ui.toolButtonViewInconsistency.clicked.connect(main_wnd.onViewInconsistency)
296
            pane.ui.toolButtonViewVendorArea.clicked.connect(main_wnd.onViewVendorArea)
297
            pane.ui.toolButtonViewDrawingOnly.clicked.connect(main_wnd.onViewDrawingOnly)
298
            cSection.addCustomWidget(pane)
299
        except Exception as ex:
300
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
301
                      f"{sys.exc_info()[-1].tb_lineno}"
302
303
    def add_tool_tab(self) -> None:
304
        """Adds the Tool Tab"""
305
        from App import App
306
        from AppRibbonPanes import QToolPane
307
308
        try:
309
            tab = self.addTab(self.tr('Tool'))
310
            main_wnd = App.mainWnd()
311
312
            # Tool Section
313
            cSection = tab.addSection(self.tr('Tool'))
314
            pane = QToolPane()
315 55fa4e14 esham21
            self._panes['Tool'] = pane
316 ba7d75e6 humkyung
            pane.ui.toolButtonPDFToImage.clicked.connect(main_wnd.onConvertPDFToImage)
317
            pane.ui.toolButtonImportTextFromCAD.clicked.connect(main_wnd.on_import_text_from_cad)
318
            pane.ui.toolButtonImportTextFromCADforInstrument.clicked.connect(main_wnd.on_import_text_from_cad_for_instrument)
319
            pane.ui.toolButtonSymbolThicknessReinforcement.clicked.connect(main_wnd.onSymbolThickness)
320
            pane.ui.toolButtonDataTransfer.clicked.connect(main_wnd.on_show_data_transfer)
321
            pane.ui.toolButtonDataExport.clicked.connect(main_wnd.on_show_data_export)
322 988a520c humkyung
            pane.ui.toolButtonConnection.clicked.connect(main_wnd.on_ext_app_connection)
323
            pane.ui.toolButtonExtApps.clicked.connect(main_wnd.on_execute_ext_app)
324 ba7d75e6 humkyung
            cSection.addCustomWidget(pane)
325
        except Exception as ex:
326
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
327
                      f"{sys.exc_info()[-1].tb_lineno}"
328
329
    def add_help_tab(self) -> None:
330
        """ Adds the Help Tab """
331
        from App import App
332
        from AppRibbonPanes import QHelpPane
333
334
        try:
335
            tab = self.addTab('Help')
336
            main_wnd = App.mainWnd()
337
338
            # Help Section
339
            cSection = tab.addSection('Help')
340
            pane = QHelpPane()
341 62fdafa4 esham21
            self._panes['Help'] = pane
342 ba7d75e6 humkyung
            pane.ui.toolButtonHelp.clicked.connect(main_wnd.on_help)
343 62fdafa4 esham21
            #shortcut = QShortcut(QKeySequence(Qt.Key_F1), pane.ui.toolButtonHelp)
344
            #shortcut.activated.connect(main_wnd.on_help)
345 ba7d75e6 humkyung
            pane.ui.toolButtonReadme.clicked.connect(main_wnd.on_readme)
346
            cSection.addCustomWidget(pane)
347
        except Exception as ex:
348
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
349
                      f"{sys.exc_info()[-1].tb_lineno}"
350
351
352
class AppRibbonFileMenu(QFileMenu):
353
    """ Widget that represents the file menu for the ribbon """
354 8770b470 humkyung
    def __init__(self, advanced_mode: bool):
355 ba7d75e6 humkyung
        """ Creates and initializes the menu """
356
        from App import App
357
        from AppRibbonPanes import QConfigPane
358
359
        QFileMenu.__init__(self)
360
        self._panes = {}
361
        main_wnd = App.mainWnd()
362
363 8770b470 humkyung
        if advanced_mode:
364
            self.addButton(icon=':/newPrefix/setup_area.png', title=self.tr('Area Setup'), handler=main_wnd.areaConfiguration)
365
            self.addButton(icon=':/newPrefix/setting.png', title=self.tr('Configuration'), handler=main_wnd.configuration)
366
            self.addSeparator()
367 ba7d75e6 humkyung
        pane = QConfigPane()
368
        self._addBtn(pane)
369
        self._panes['Config'] = pane
370
        self.addSeparator()
371
        self.addButton(icon=':/newPrefix/Exit.svg', title=self.tr('Exit'), handler=main_wnd.close)
372
373
    def get_pane(self, name: str) -> QWidget:
374
        return self._panes[name] if name in self._panes else None
375
376
    def handleRecentFileClicked(self, path):
377
        """ Handles recent files being clicked """
378
        pass
클립보드 이미지 추가 (최대 크기: 500 MB)