hytos / DTI_PID / DTI_PID / ConnectAttrDialog.py @ 4a4e7537
이력 | 보기 | 이력해설 | 다운로드 (6.04 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): |
35 |
QThread.__init__(self)
|
36 |
self.graphicsView = graphicsView
|
37 | |
38 |
'''
|
39 |
@brief execute connecting attributes
|
40 |
@author humkyung
|
41 |
@date 2018.06.17
|
42 |
'''
|
43 |
def run(self): # A slot takes no params |
44 |
from LineNoTracer import connectAttrImpl |
45 | |
46 |
try:
|
47 |
connectAttrImpl(self)
|
48 |
except Exception as ex: |
49 |
from App import App |
50 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
51 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
52 | |
53 |
class QConnectAttrDialog(QDialog): |
54 |
""" This is connect attr dialog class """
|
55 | |
56 |
def __init__(self, parent, graphicsView): #Parent is MainWindow |
57 |
import ConnectAttr_UI |
58 | |
59 |
QDialog.__init__(self, parent)
|
60 | |
61 |
self.parent = parent
|
62 |
self.graphicsView = graphicsView
|
63 |
self.ui = ConnectAttr_UI.Ui_ConnectAttr()
|
64 |
self.ui.setupUi(self) |
65 |
self.ui.pushButtonStart.setFocus()
|
66 |
self.ui.buttonBox.setEnabled(True) |
67 |
self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) ## connect to func rowInserted(self, item) |
68 |
self.isAccepted = False |
69 |
|
70 |
self.ui.pushButtonStart.clicked.connect(self.connStart) |
71 | |
72 |
def connStart(self): |
73 |
'''
|
74 |
@brief connection start
|
75 |
@author euisung
|
76 |
@date 2019.02.25
|
77 |
'''
|
78 |
self.ui.buttonBox.setEnabled(False) |
79 |
self.ui.pushButtonStart.setEnabled(False) |
80 |
self.ui.progressBar.setValue(0) |
81 |
self.startThread()
|
82 |
""" for DEBUG
|
83 |
from LineNoTracer import connectAttrImpl
|
84 |
connectAttrImpl(self)
|
85 |
"""
|
86 | |
87 |
'''
|
88 |
@brief QListWidget Row Inserted Listener
|
89 |
Whenever row inserted, scroll to bottom
|
90 |
@author Jeongwoo
|
91 |
@date 18.04.12
|
92 |
'''
|
93 |
def rowInserted(self, item): |
94 |
self.ui.listWidget.scrollToBottom()
|
95 | |
96 |
'''
|
97 |
@brief add item to list widget
|
98 |
@author humkyung
|
99 |
@date 2018.06.17
|
100 |
'''
|
101 |
def addListItem(self, msg): |
102 |
self.ui.listWidget.addItem(msg)
|
103 | |
104 |
def accept(self): |
105 |
self.isAccepted = True |
106 |
QDialog.accept(self)
|
107 | |
108 |
'''
|
109 |
@brief update progressbar with given value
|
110 |
@author humkyung
|
111 |
@date 2018.06.17
|
112 |
@history humkyung 2018.06.27 reset value if maxValue is -1
|
113 |
'''
|
114 |
def updateProgress(self, maxValue): |
115 |
if maxValue != -1: |
116 |
self.ui.progressBar.setMaximum(maxValue)
|
117 |
self.ui.progressBar.setValue(self.ui.progressBar.value() + 1) |
118 |
else:
|
119 |
self.ui.progressBar.setValue(0) |
120 | |
121 |
'''
|
122 |
@brief start thread
|
123 |
@author humkyung
|
124 |
@date 2018.06.17
|
125 |
'''
|
126 |
def startThread(self): |
127 |
import timeit |
128 |
from LineNoTracer import connectAttrImpl |
129 | |
130 |
try:
|
131 |
self.ui.buttonBox.setDisabled(True) |
132 | |
133 |
# 1 - create Worker and Thread inside the Form
|
134 |
self.obj = Worker(self.graphicsView) # no parent! |
135 |
#self.obj.graphicsView = self.graphicsView
|
136 |
#self.thread = QThread() # no parent!
|
137 | |
138 |
# 2 - Move the Worker object to the Thread object
|
139 |
#self.obj.moveToThread(self.thread)
|
140 | |
141 |
# 3 - Connect Worker Signals to the Thread slots
|
142 |
#self.obj.finished.connect(self.obj.quit)
|
143 |
self.obj.displayMessage.connect(self.addListItem) |
144 |
self.obj.updateProgress.connect(self.updateProgress) |
145 | |
146 |
# 4 - Connect Thread started signal to Worker operational slot method
|
147 |
#self.thread.started.connect(self.obj.procCounter)
|
148 |
|
149 |
# 5 - Thread finished signal will close the app if you want!
|
150 |
self.obj.finished.connect(self.dlgExit) |
151 | |
152 |
# 6 - Start the thread
|
153 |
self.obj.start()
|
154 | |
155 |
self.tmStart = timeit.default_timer()
|
156 |
except Exception as ex: |
157 |
from App import App |
158 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
159 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
160 |
finally:
|
161 |
self.ui.buttonBox.setDisabled(False) |
162 | |
163 |
'''
|
164 |
@brief set buttonbox's enabled flag
|
165 |
@author humkyung
|
166 |
@date 2018.06.17
|
167 |
@history humkyung 2018.06.17 add flow mark for pipe run
|
168 |
humkyung 2018.08.16 don't update line type according to connected items
|
169 |
'''
|
170 |
def dlgExit(self): |
171 |
import timeit |
172 | |
173 |
try:
|
174 |
self.ui.progressBar.setValue(self.ui.progressBar.maximum()) |
175 |
self.ui.buttonBox.setEnabled(True) |
176 |
except Exception as ex: |
177 |
from App import App |
178 | |
179 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
180 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
181 |
finally:
|
182 |
self.tmStop = timeit.default_timer()
|
183 |
seconds = self.tmStop - self.tmStart |
184 |
self.ui.listWidget.addItem("\nRunning Time : {} min".format(str(round(seconds/60, 1))) + "\n") |