프로젝트

일반

사용자정보

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

hytos / DTI_PID / DTI_PID / ConnectAttrDialog.py @ 85f3f93b

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

1
# coding: utf-8
2

    
3
from PyQt5.QtCore import *
4
from PyQt5.QtGui import *
5
from PyQt5.QtWidgets import *
6
import ConnectAttr_UI
7
import sys
8
import os
9
import cv2
10
import numpy as np
11
from AppDocData import *
12
from LineDetector import LineDetector
13
from EngineeringLineItem import QEngineeringLineItem
14
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
15
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem
16
from SymbolSvgItem import SymbolSvgItem
17
from EngineeringTextItem import QEngineeringTextItem
18
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
19

    
20
'''
21
'''
22
class Worker(QThread):
23
    """ This is Worker class """
24
    from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QGridLayout, QListWidget
25
    from QtImageViewer import QtImageViewer
26
    import sys
27

    
28
    '''
29
    '''
30
    finished = pyqtSignal()
31
    intReady = pyqtSignal(int)
32
    displayMessage = pyqtSignal(str)
33
    updateProgress = pyqtSignal(int)
34

    
35
    def __init__(self, graphicsView, update_line_type, update_flow_mark, update_spec):
36
        QThread.__init__(self)
37
        self.graphicsView = graphicsView
38
        self._update_line_type = update_line_type
39
        self._update_flow_mark = update_flow_mark
40
        self._update_spec = update_spec
41

    
42
    '''
43
        @brief  execute connecting attributes
44
        @author humkyung
45
        @date   2018.06.17
46
    '''
47
    def run(self): # A slot takes no params
48
        from LineNoTracer import connectAttrImpl
49

    
50
        try:
51
            connectAttrImpl(self, self._update_line_type, self._update_flow_mark, self._update_spec)
52
        except Exception as ex:
53
            from App import App 
54
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
55
            App.mainWnd().addMessage.emit(MessageType.Error, message)
56

    
57
class QConnectAttrDialog(QDialog):
58
    """ This is connect attr dialog class """
59

    
60
    def __init__(self, parent, graphicsView): #Parent is MainWindow
61
        import ConnectAttr_UI
62

    
63
        QDialog.__init__(self, parent)
64

    
65
        self.parent = parent
66
        self.graphicsView = graphicsView
67
        self.ui = ConnectAttr_UI.Ui_ConnectAttr()
68
        self.ui.setupUi(self)
69
        self.ui.pushButtonStart.setFocus()
70
        self.ui.buttonBox.setEnabled(True)
71
        self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) ## connect to func rowInserted(self, item)
72
        self.isRunned = False
73
        
74
        self.ui.pushButtonStart.clicked.connect(self.connStart)
75

    
76
    def connStart(self):
77
        '''
78
            @brief  connection start
79
            @author euisung
80
            @date   2019.02.25
81
        ''' 
82
        self.ui.buttonBox.setEnabled(False)
83
        self.ui.pushButtonStart.setEnabled(False)
84
        self.ui.progressBar.setValue(0)
85
        self.startThread()
86
        self.isRunned = True
87

    
88
    '''
89
        @brief      QListWidget Row Inserted Listener
90
                    Whenever row inserted, scroll to bottom
91
        @author     Jeongwoo
92
        @date       18.04.12
93
    '''
94
    def rowInserted(self, item):
95
        self.ui.listWidget.scrollToBottom()
96

    
97
    '''
98
        @brief  add item to list widget
99
        @author humkyung
100
        @date   2018.06.17
101
    '''
102
    def addListItem(self, msg):
103
        self.ui.listWidget.addItem(msg)
104

    
105
    '''
106
        @brief      update progressbar with given value
107
        @author     humkyung
108
        @date       2018.06.17
109
        @history    humkyung 2018.06.27 reset value if maxValue is -1
110
    '''
111
    def updateProgress(self, maxValue):
112
        if maxValue != -1:
113
            self.ui.progressBar.setMaximum(maxValue)
114
            self.ui.progressBar.setValue(self.ui.progressBar.value() + 1)
115
        else:
116
            self.ui.progressBar.setValue(0)
117

    
118
    '''
119
        @brief  start thread
120
        @author humkyung
121
        @date   2018.06.17
122
    '''
123
    def startThread(self):
124
        import timeit
125
        from LineNoTracer import connectAttrImpl
126

    
127
        try:
128
            self.ui.buttonBox.setDisabled(True)
129

    
130
            # 1 - create Worker and Thread inside the Form
131
            self.obj = Worker(self.graphicsView, self.ui.checkBoxUpdateLineType.isChecked(), self.ui.checkBoxUpdateFlowMark.isChecked(), self.ui.checkBoxUpdateSpec.isChecked())
132

    
133
            # 2 - Connect Worker Signals to the Thread slots
134
            self.obj.displayMessage.connect(self.addListItem)
135
            self.obj.updateProgress.connect(self.updateProgress)
136

    
137
            # 3 - Thread finished signal will close the app if you want!
138
            self.obj.finished.connect(self.dlgExit)
139

    
140
            # 4 - Start the thread
141
            self.obj.start()
142

    
143
            self.tmStart = timeit.default_timer()
144
        except Exception as ex:
145
            from App import App 
146
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
147
            App.mainWnd().addMessage.emit(MessageType.Error, message)
148
        finally:
149
            self.ui.buttonBox.setDisabled(False)
150

    
151
    '''
152
        @brief      set buttonbox's enabled flag
153
        @author     humkyung
154
        @date       2018.06.17
155
        @history    humkyung 2018.06.17 add flow mark for pipe run
156
                    humkyung 2018.08.16 don't update line type according to connected items
157
    '''
158
    def dlgExit(self):
159
        import timeit
160

    
161
        try:
162
            self.ui.progressBar.setValue(self.ui.progressBar.maximum())
163
            self.ui.buttonBox.setEnabled(True)
164
        except Exception as ex:
165
            from App import App
166

    
167
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
168
            App.mainWnd().addMessage.emit(MessageType.Error, message)
169
        finally:
170
            self.tmStop = timeit.default_timer()    
171
            seconds = self.tmStop - self.tmStart
172
            self.ui.listWidget.addItem("\nRunning Time : {} min".format(str(round(seconds/60, 1))) + "\n")
클립보드 이미지 추가 (최대 크기: 500 MB)