프로젝트

일반

사용자정보

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

hytos / DTI_PID / DTI_PID / ConnectAttrDialog.py @ afa1358d

이력 | 보기 | 이력해설 | 다운로드 (5.71 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
from AppDocData import *
11
from LineDetector import LineDetector
12
from EngineeringLineItem import QEngineeringLineItem
13
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
14
from QEngineeringFlowArrowItem import QEngineeringFlowArrowItem
15
from SymbolSvgItem import SymbolSvgItem
16
from EngineeringTextItem import QEngineeringTextItem
17
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem
18

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

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

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

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

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

    
55
class QConnectAttrDialog(QDialog):
56
    """ This is connect attr dialog class """
57

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

    
61
        QDialog.__init__(self, parent)
62

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

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

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

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

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

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

    
125
        try:
126
            self.ui.buttonBox.setDisabled(True)
127

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

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

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

    
138
            # 4 - Start the thread
139
            self.obj.start()
140

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

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

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

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