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