hytos / DTI_PID / DTI_PID / QRecognitionDialog.py @ 34f2b549
이력 | 보기 | 이력해설 | 다운로드 (6.27 KB)
1 |
# coding: utf-8
|
---|---|
2 |
from PyQt5.QtCore import * |
3 |
from PyQt5.QtGui import * |
4 |
from PyQt5.QtWidgets import * |
5 |
import Recognition_UI |
6 |
import sys |
7 |
import os |
8 |
import cv2 |
9 |
from AppDocData import AppDocData |
10 |
from LineDetector import LineDetector |
11 |
from QEngineeringLineItem 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 |
@history 2018.05.25 Jeongwoo Add pyqtSignal(recognizeLine, loadRecognitionResult)
|
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 |
import timeit |
27 | |
28 |
'''
|
29 |
@history 2018.05.30 Jeongwoo Remove parameter on recognizeLine signal
|
30 |
'''
|
31 |
finished = pyqtSignal() |
32 |
intReady = pyqtSignal(int)
|
33 |
recognizeLine = pyqtSignal(QListWidget, QtImageViewer) |
34 |
loadRecognitionResult = pyqtSignal(list, list, list) |
35 | |
36 |
'''
|
37 |
@history 2018.05.25 Jeongwoo Add if-statements by isSymbolTextChecked and isLineChecked variable
|
38 |
2018.05.28 Jeongwoo Add Parameter 'xmlPath[0]'
|
39 |
2018.05.30 Jeongwoo Remove import recognizeLine and self.xmlPath and remove parameter on recognizeLine.emit() (xmlPath)
|
40 |
'''
|
41 |
#pyqtSlot()
|
42 |
def procCounter(self): # A slot takes no params |
43 |
from DTI_PID import executeRecognition |
44 |
import timeit |
45 | |
46 |
try:
|
47 |
start = timeit.default_timer() |
48 |
executeRecognition(self.loadRecognitionResult, self.path, self.listWidget, self.isSymbolTextChecked) |
49 |
if self.isLineChecked: |
50 |
self.recognizeLine.emit(self.listWidget, self.graphicsView) |
51 |
self.finished.emit()
|
52 |
except Exception as ex: |
53 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
54 |
finally:
|
55 |
stop = timeit.default_timer() |
56 |
seconds = stop - start |
57 |
self.listWidget.addItem("\nRunning Time : " + str(seconds / 60) + "min\n") |
58 | |
59 |
'''
|
60 |
@history 2018.05.25 Jeongwoo Add pyqtSignal(svgItemClicked, itemRemoved)
|
61 |
'''
|
62 |
class QRecognitionDialog(QDialog): |
63 |
svgItemClicked = pyqtSignal(SymbolSvgItem) |
64 |
itemRemoved = pyqtSignal(QGraphicsItem) |
65 | |
66 |
'''
|
67 |
@history 2018.05.25 Jeongwoo Add parameter and initialize / Connect recognizeButton signal and slot
|
68 |
2018.05.29 Jeongwoo Chnage parameter(graphicsView → parent) and Get graphicsView from parent
|
69 |
'''
|
70 |
def __init__(self, parent, path): #Parent is MainWindow |
71 |
QDialog.__init__(self, parent)
|
72 | |
73 |
self.parent = parent
|
74 |
self.graphicsView = parent.graphicsView
|
75 |
self.path = path
|
76 |
self.xmlPath = None |
77 |
self.ui = Recognition_UI.Ui_Recognition()
|
78 |
self.ui.setupUi(self) |
79 |
self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) ## connect to func rowInserted(self, item) |
80 |
self.ui.recognizeButton.clicked.connect(self.recognizeButtonClicked) |
81 |
self.isAccepted = False |
82 | |
83 |
'''
|
84 |
@brief QListWidget Row Inserted Listener
|
85 |
Whenever row inserted, scroll to bottom
|
86 |
@author Jeongwoo
|
87 |
@date 18.04.12
|
88 |
@history .
|
89 |
'''
|
90 |
def rowInserted(self, item): |
91 |
self.ui.listWidget.scrollToBottom()
|
92 | |
93 |
def accept(self): |
94 |
self.isAccepted = True |
95 |
QDialog.accept(self)
|
96 | |
97 |
def recognizeButtonClicked(self, event): |
98 |
if self.ui.symbolTextCheckBox.isChecked() or self.ui.lineCheckBox.isChecked(): |
99 |
self.startThread()
|
100 | |
101 |
'''
|
102 |
@brief start thread
|
103 |
@author humkyung
|
104 |
@date 2018.04.??
|
105 |
@history 2018.05.25 Jeongwoo Moved from MainWindow
|
106 |
2018.05.28 Jeongwoo Add connects (self.loadRecognitionResult, recognizeLine)
|
107 |
'''
|
108 |
def startThread(self): |
109 |
from DTI_PID import recognizeLine |
110 | |
111 |
self.ui.buttonBox.setDisabled(True) |
112 | |
113 |
# 1 - create Worker and Thread inside the Form
|
114 |
self.obj = Worker() # no parent! |
115 |
self.obj.path = self.path |
116 |
self.obj.listWidget = self.ui.listWidget |
117 |
self.obj.graphicsView = self.graphicsView |
118 |
self.obj.isSymbolTextChecked = self.ui.symbolTextCheckBox.isChecked() |
119 |
self.obj.isLineChecked = self.ui.lineCheckBox.isChecked() |
120 |
self.thread = QThread() # no parent! |
121 | |
122 |
# 2 - Connect Worker`s Signals to Form method slots to post data.
|
123 |
#self.obj.intReady.connect(self.onIntReady)
|
124 | |
125 |
# 3 - Move the Worker object to the Thread object
|
126 |
self.obj.moveToThread(self.thread) |
127 | |
128 |
# 4 - Connect Worker Signals to the Thread slots
|
129 |
self.obj.finished.connect(self.thread.quit) |
130 |
self.obj.loadRecognitionResult.connect(self.loadRecognitionResult) |
131 |
self.obj.recognizeLine.connect(recognizeLine)
|
132 | |
133 |
# 5 - Connect Thread started signal to Worker operational slot method
|
134 |
self.thread.started.connect(self.obj.procCounter) |
135 |
|
136 |
# * - Thread finished signal will close the app if you want!
|
137 |
self.thread.finished.connect(self.dlgExit) |
138 | |
139 |
# 6 - Start the thread
|
140 |
self.thread.start()
|
141 | |
142 |
'''
|
143 |
@brief set buttonbox's enabled flag
|
144 |
@history 2018.05.25 Jeongwoo Moved from MainWindow
|
145 |
2018.05.30 Jeongwoo Remove self.xmlPath variable and Add writeXmlOnScene
|
146 |
'''
|
147 |
def dlgExit(self): |
148 |
import XmlGenerator as xg |
149 |
try:
|
150 |
#self.xmlPath = self.obj.xmlPath
|
151 |
self.ui.buttonBox.setEnabled(True) |
152 |
docData = AppDocData.instance() |
153 |
xg.writeXmlOnScene(docData.imgName, docData.imgWidth, docData.imgHeight, self.graphicsView.scene)
|
154 |
except Exception as ex: |
155 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
156 | |
157 |
'''
|
158 |
@history 2018.05.29 Jeongwoo Call parent's method
|
159 |
'''
|
160 |
def loadRecognitionResult(self, symbolList, textInfoList, noteTextInfoList): |
161 |
self.parent.loadRecognitionResultByList(symbolList, textInfoList, noteTextInfoList)
|