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