개정판 92ae0bd6
issue #478: 이미지, 텍스트 아이템에서 텍스트를 인식하는 방법 통합
Change-Id: I43fea4029612322d0ce9c3fe262c239af13dda62
DTI_PID/DTI_PID/ConnectAttrDialog.py | ||
---|---|---|
34 | 34 |
displayMessage = pyqtSignal(str) |
35 | 35 |
updateProgress = pyqtSignal(int) |
36 | 36 |
|
37 |
def __init__(self, graphicsView, update_line_type, update_flow_mark, update_spec):
|
|
37 |
def __init__(self, scene, update_line_type, update_flow_mark, update_spec):
|
|
38 | 38 |
super(Worker, self).__init__() |
39 |
self.graphicsView = graphicsView
|
|
39 |
self.scene = scene
|
|
40 | 40 |
self._update_line_type = update_line_type |
41 | 41 |
self._update_flow_mark = update_flow_mark |
42 | 42 |
self._update_spec = update_spec |
... | ... | |
63 | 63 |
class QConnectAttrDialog(QDialog): |
64 | 64 |
""" This is connect attr dialog class """ |
65 | 65 |
|
66 |
def __init__(self, parent, graphicsView): # Parent is MainWindow
|
|
66 |
def __init__(self, parent, scene): # Parent is MainWindow
|
|
67 | 67 |
import ConnectAttr_UI |
68 | 68 |
|
69 | 69 |
QDialog.__init__(self, parent) |
70 | 70 |
|
71 | 71 |
self.parent = parent |
72 |
self.graphicsView = graphicsView
|
|
72 |
self.scene = scene
|
|
73 | 73 |
self.ui = ConnectAttr_UI.Ui_ConnectAttr() |
74 | 74 |
self.ui.setupUi(self) |
75 | 75 |
self.ui.pushButtonStart.setFocus() |
76 | 76 |
self.ui.buttonBox.setEnabled(True) |
77 |
self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) ## connect to func rowInserted(self, item)
|
|
77 |
self.ui.listWidget.model().rowsInserted.connect(self.rowInserted) # connect to func rowInserted(self, item) |
|
78 | 78 |
self.isRunned = False |
79 | 79 |
|
80 | 80 |
self.ui.pushButtonStart.clicked.connect(self.connStart) |
81 | 81 |
|
82 |
@property |
|
83 |
def validation_checked(self): |
|
84 |
"""return if validation is checked""" |
|
85 |
return self.ui.checkBoxValidation.isChecked() |
|
86 |
|
|
82 | 87 |
def connStart(self): |
83 | 88 |
"""start to connect attributes""" |
84 | 89 |
|
... | ... | |
134 | 139 |
self.ui.buttonBox.setDisabled(True) |
135 | 140 |
|
136 | 141 |
# 1 - create Worker and Thread inside the Form |
137 |
self.obj = Worker(self.graphicsView, self.ui.checkBoxUpdateLineType.isChecked(),
|
|
142 |
self.obj = Worker(self.scene, self.ui.checkBoxUpdateLineType.isChecked(),
|
|
138 | 143 |
self.ui.checkBoxUpdateFlowMark.isChecked(), self.ui.checkBoxUpdateSpec.isChecked()) |
139 | 144 |
self.thread = QThread() |
140 | 145 |
|
... | ... | |
176 | 181 |
import timeit |
177 | 182 |
|
178 | 183 |
try: |
184 |
if self.obj.need_update_texts: |
|
185 |
for text, _text in self.obj.need_update_texts: |
|
186 |
text.setPlainText(_text) |
|
187 |
|
|
179 | 188 |
self.ui.progressBar.setValue(self.ui.progressBar.maximum()) |
180 | 189 |
self.ui.buttonBox.setEnabled(True) |
181 | 190 |
except Exception as ex: |
DTI_PID/DTI_PID/ConnectAttr_UI.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
|
3 |
# Form implementation generated from reading ui file './UI/dlgConnectAttr.ui'
|
|
3 |
# Form implementation generated from reading ui file '.\UI\dlgConnectAttr.ui'
|
|
4 | 4 |
# |
5 |
# Created by: PyQt5 UI code generator 5.11.3
|
|
5 |
# Created by: PyQt5 UI code generator 5.13.0
|
|
6 | 6 |
# |
7 | 7 |
# WARNING! All changes made in this file will be lost! |
8 | 8 |
|
9 |
|
|
9 | 10 |
from PyQt5 import QtCore, QtGui, QtWidgets |
10 | 11 |
|
12 |
|
|
11 | 13 |
class Ui_ConnectAttr(object): |
12 | 14 |
def setupUi(self, ConnectAttr): |
13 | 15 |
ConnectAttr.setObjectName("ConnectAttr") |
... | ... | |
61 | 63 |
sizePolicy.setVerticalStretch(0) |
62 | 64 |
sizePolicy.setHeightForWidth(self.pushButtonStart.sizePolicy().hasHeightForWidth()) |
63 | 65 |
self.pushButtonStart.setSizePolicy(sizePolicy) |
66 |
self.pushButtonStart.setDefault(True) |
|
64 | 67 |
self.pushButtonStart.setObjectName("pushButtonStart") |
65 | 68 |
self.horizontalLayout_2.addWidget(self.pushButtonStart) |
66 | 69 |
self.gridLayout.addLayout(self.horizontalLayout_2, 2, 0, 1, 1) |
... | ... | |
68 | 71 |
self.retranslateUi(ConnectAttr) |
69 | 72 |
self.buttonBox.clicked['QAbstractButton*'].connect(ConnectAttr.accept) |
70 | 73 |
QtCore.QMetaObject.connectSlotsByName(ConnectAttr) |
71 |
ConnectAttr.setTabOrder(self.pushButtonStart, self.listWidget) |
|
74 |
ConnectAttr.setTabOrder(self.pushButtonStart, self.checkBoxUpdateFlowMark) |
|
75 |
ConnectAttr.setTabOrder(self.checkBoxUpdateFlowMark, self.checkBoxUpdateSpec) |
|
76 |
ConnectAttr.setTabOrder(self.checkBoxUpdateSpec, self.checkBoxUpdateLineType) |
|
77 |
ConnectAttr.setTabOrder(self.checkBoxUpdateLineType, self.checkBoxValidation) |
|
78 |
ConnectAttr.setTabOrder(self.checkBoxValidation, self.listWidget) |
|
72 | 79 |
|
73 | 80 |
def retranslateUi(self, ConnectAttr): |
74 | 81 |
_translate = QtCore.QCoreApplication.translate |
... | ... | |
78 | 85 |
self.checkBoxUpdateSpec.setText(_translate("ConnectAttr", "Update Segment Break")) |
79 | 86 |
self.checkBoxUpdateLineType.setText(_translate("ConnectAttr", "Update Line Type")) |
80 | 87 |
self.pushButtonStart.setText(_translate("ConnectAttr", "Start")) |
81 |
|
|
82 |
|
|
83 |
if __name__ == "__main__": |
|
84 |
import sys |
|
85 |
app = QtWidgets.QApplication(sys.argv) |
|
86 |
ConnectAttr = QtWidgets.QDialog() |
|
87 |
ui = Ui_ConnectAttr() |
|
88 |
ui.setupUi(ConnectAttr) |
|
89 |
ConnectAttr.show() |
|
90 |
sys.exit(app.exec_()) |
|
91 |
|
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
480 | 480 |
lineNos = [] |
481 | 481 |
spec_breaks = [] |
482 | 482 |
lineIndicator = [] |
483 |
vendor_packages = [item for item in worker.graphicsView.scene.items() if
|
|
483 |
vendor_packages = [item for item in worker.scene.items() if |
|
484 | 484 |
type(item) is QEngineeringVendorItem and item.pack_type == 'Vendor Package'] |
485 |
equip_packages = [item for item in worker.graphicsView.scene.items() if
|
|
485 |
equip_packages = [item for item in worker.scene.items() if |
|
486 | 486 |
type(item) is QEngineeringVendorItem and item.pack_type == 'Equipment Package'] |
487 | 487 |
end_breaks = [] |
488 | 488 |
notes = [] |
489 | 489 |
flow_marks = [] |
490 | 490 |
|
491 |
for error_item in [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringErrorItem]:
|
|
491 |
for error_item in [item for item in worker.scene.items() if type(item) is QEngineeringErrorItem]: |
|
492 | 492 |
error_item.transfer.onRemoved.emit(error_item) |
493 | 493 |
|
494 |
for end_break in [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringEndBreakItem]:
|
|
494 |
for end_break in [item for item in worker.scene.items() if type(item) is QEngineeringEndBreakItem]: |
|
495 | 495 |
if not end_break.prop('Freeze'): |
496 | 496 |
end_break.transfer.onRemoved.emit(end_break) |
497 | 497 |
else: |
498 | 498 |
end_breaks.append(end_break) |
499 | 499 |
|
500 | 500 |
''' |
501 |
for flow_mark in [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringFlowMarkItem]:
|
|
501 |
for flow_mark in [item for item in worker.scene.items() if type(item) is QEngineeringFlowMarkItem]: |
|
502 | 502 |
if not flow_mark.prop('Freeze'): |
503 | 503 |
flow_mark.transfer.onRemoved.emit(flow_mark) |
504 | 504 |
else: |
... | ... | |
507 | 507 |
|
508 | 508 |
configs = docdata.getConfigs('Supplied by Tag Rule', 'by Vendor') |
509 | 509 |
vendorTag = configs[0].value if configs else 'By Vendor' |
510 |
for item in worker.graphicsView.scene.items():
|
|
510 |
for item in worker.scene.items(): |
|
511 | 511 |
if type(item) is QEngineeringSpecBreakItem: |
512 | 512 |
spec_breaks.append(item) |
513 | 513 |
elif issubclass(type(item), SymbolSvgItem) and not (type(item) is QEngineeringErrorItem) and not ( |
... | ... | |
553 | 553 |
|
554 | 554 |
# connect attribute |
555 | 555 |
worker.displayMessage.emit('Connecting Attribute...') |
556 |
texts = [item for item in worker.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)]
|
|
556 |
texts = [item for item in worker.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
|
557 | 557 |
for symbol in symbols: |
558 | 558 |
try: |
559 | 559 |
symbol.connectAttribute(texts) |
... | ... | |
586 | 586 |
noteText.owner = note |
587 | 587 |
|
588 | 588 |
""" try to find text item's owner """ |
589 |
texts = [item for item in worker.graphicsView.scene.items() if type(item) is QEngineeringReservedWordTextItem]
|
|
589 |
texts = [item for item in worker.scene.items() if type(item) is QEngineeringReservedWordTextItem] |
|
590 | 590 |
for text in texts: |
591 | 591 |
text.findOwner(lines) |
592 | 592 |
|
593 | 593 |
# restore and save manual edited attr's text item |
594 |
texts = [item for item in worker.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)]
|
|
594 |
texts = [item for item in worker.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
|
595 | 595 |
targetText = [] |
596 | 596 |
for text in texts: |
597 | 597 |
found = False |
... | ... | |
709 | 709 |
type(end_break.prop('Connected Item')) is QEngineeringLineItem and ( |
710 | 710 |
end_break.prop('Connected Item').lineType == 'Secondary' or end_break.prop( |
711 | 711 |
'Connected Item').lineType == 'Primary'))): |
712 |
end_break.addSvgItemToScene(worker.graphicsView.scene)
|
|
712 |
end_break.addSvgItemToScene(worker.scene) |
|
713 | 713 |
|
714 | 714 |
""" update spec break """ |
715 | 715 |
if update_spec: |
... | ... | |
881 | 881 |
break |
882 | 882 |
|
883 | 883 |
if stream_res[0] and stream_res[1]: |
884 |
texts = [item for item in worker.graphicsView.scene.items() if
|
|
884 |
texts = [item for item in worker.scene.items() if |
|
885 | 885 |
type(item) is QEngineeringTextItem and item.owner is None] |
886 | 886 |
positioning = False |
887 | 887 |
|
... | ... | |
936 | 936 |
|
937 | 937 |
for spec_break_item in spec_break_items: |
938 | 938 |
spec_break_item.transfer.onRemoved.connect(App.mainWnd().itemRemoved) |
939 |
spec_break_item.addSvgItemToScene(worker.graphicsView.scene)
|
|
939 |
spec_break_item.addSvgItemToScene(worker.scene) |
|
940 | 940 |
|
941 | 941 |
spec_break_items.extend(freezed_spec_breaks) |
942 | 942 |
|
... | ... | |
944 | 944 |
|
945 | 945 |
# trace special item |
946 | 946 |
worker.displayMessage.emit('Find line for special item...') |
947 |
tracer = SpecialItemTracer([item for item in worker.graphicsView.scene.items() if (
|
|
947 |
tracer = SpecialItemTracer([item for item in worker.scene.items() if ( |
|
948 | 948 |
type(item) is SymbolSvgItem or type(item) is QEngineeringTextItem) and item.special_item_type], |
949 | 949 |
lines) |
950 | 950 |
tracer.execute(worker.displayMessage, worker.updateProgress) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1133 | 1133 |
|
1134 | 1134 |
image = self.graphicsView.image().copy(x, y, width, height) |
1135 | 1135 |
dialog = QOcrResultDialog(self.graphicsView, image, QRectF(x, y, width, height)) |
1136 |
(isAccept, textInfoList) = dialog.showDialog() |
|
1137 |
if isAccept: |
|
1138 |
if textInfoList: |
|
1139 |
for textInfo in textInfoList: |
|
1140 |
x = textInfo.getX() |
|
1141 |
y = textInfo.getY() |
|
1142 |
angle = textInfo.getAngle() |
|
1143 |
text = textInfo.getText() |
|
1144 |
width = textInfo.getW() |
|
1145 |
height = textInfo.getH() |
|
1146 |
item = TextItemFactory.instance().createTextItem(textInfo) |
|
1147 |
if item is not None: |
|
1148 |
item.loc = [x, y] |
|
1149 |
item.size = (width, height) |
|
1150 |
item.angle = angle |
|
1151 |
item.setDefaultTextColor(Qt.blue) |
|
1152 |
item.addTextItemToScene(self.graphicsView.scene) |
|
1153 |
item.transfer.onRemoved.connect(self.itemRemoved) |
|
1154 |
|
|
1155 |
area_list = app_doc_data.getAreaList() |
|
1156 |
title_area_list = app_doc_data.getTitleBlockProperties() |
|
1157 |
title_list = [] |
|
1158 |
for title_area in title_area_list: |
|
1159 |
area = Area(title_area[0]) |
|
1160 |
area.parse(title_area[2]) |
|
1161 |
title_list.append(area) |
|
1162 |
for area in area_list + title_list: |
|
1163 |
pt = [item.sceneBoundingRect().center().x(), item.sceneBoundingRect().center().y()] |
|
1164 |
if area.contains(pt): |
|
1165 |
item.area = area.name |
|
1166 |
break |
|
1167 |
else: |
|
1168 |
message = 'error occurred({}) in {}:{}'.format('텍스트 생성에 실패했습니다.', sys.exc_info()[ |
|
1169 |
-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
1170 |
self.addMessage.emit(MessageType.Normal, message) |
|
1171 |
else: |
|
1172 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), self.tr("Fail to recognize text")) |
|
1136 |
(res, textInfoList) = dialog.showDialog() |
|
1137 |
if QDialog.Accepted == res and textInfoList: |
|
1138 |
for textInfo in textInfoList: |
|
1139 |
item = QEngineeringTextItem.create_text_with(self.graphicsView.scene, textInfo) |
|
1140 |
if item: |
|
1141 |
item.setDefaultTextColor(Qt.blue) |
|
1142 |
item.transfer.onRemoved.connect(self.itemRemoved) |
|
1143 |
|
|
1144 |
area_list = app_doc_data.getAreaList() |
|
1145 |
title_area_list = app_doc_data.getTitleBlockProperties() |
|
1146 |
title_list = [] |
|
1147 |
for title_area in title_area_list: |
|
1148 |
area = Area(title_area[0]) |
|
1149 |
area.parse(title_area[2]) |
|
1150 |
title_list.append(area) |
|
1151 |
for area in area_list + title_list: |
|
1152 |
pt = [item.sceneBoundingRect().center().x(), item.sceneBoundingRect().center().y()] |
|
1153 |
if area.contains(pt): |
|
1154 |
item.area = area.name |
|
1155 |
break |
|
1156 |
else: |
|
1157 |
message = 'error occurred({}) in {}:{}'.format(self.tr('Fail to create text.'), |
|
1158 |
sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
1159 |
self.addMessage.emit(MessageType.Normal, message) |
|
1160 |
elif QDialog.Accepted == res and not textInfoList: |
|
1161 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), self.tr("Fail to recognize text")) |
|
1173 | 1162 |
except Exception as ex: |
1174 | 1163 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1175 | 1164 |
sys.exc_info()[-1].tb_lineno) |
... | ... | |
2154 | 2143 |
return |
2155 | 2144 |
|
2156 | 2145 |
try: |
2157 |
self.dlgConnectAttr = QConnectAttrDialog(self, self.graphicsView) |
|
2158 |
self.dlgConnectAttr.setWindowFlags( |
|
2159 |
self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) |
|
2160 |
self.dlgConnectAttr.exec_() |
|
2161 |
if self.dlgConnectAttr.isRunned: |
|
2146 |
dlg = QConnectAttrDialog(self, self.graphicsView) |
|
2147 |
dlg.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) |
|
2148 |
dlg.exec_() |
|
2149 |
if dlg.isRunned: |
|
2162 | 2150 |
self.itemTreeWidget.InitLineNoItems() |
2163 | 2151 |
|
2164 | 2152 |
# construct line no item |
... | ... | |
2171 | 2159 |
self.itemTreeWidget.addTreeItem(item, connectedItem) |
2172 | 2160 |
# up to here |
2173 | 2161 |
|
2174 |
if self.dlgConnectAttr.obj.need_update_texts: |
|
2175 |
for text, _text in self.dlgConnectAttr.obj.need_update_texts: |
|
2176 |
text.setPlainText(_text) |
|
2177 |
|
|
2178 |
self.tableWidgetInconsistency.clearContents() |
|
2179 |
if self.dlgConnectAttr.ui.checkBoxValidation.isChecked(): |
|
2162 |
if dlg.validation_checked: |
|
2180 | 2163 |
self.onValidation() |
2181 | 2164 |
|
2182 | 2165 |
self.graphicsView.invalidateScene() |
DTI_PID/DTI_PID/OcrResultDialog.py | ||
---|---|---|
230 | 230 |
else: |
231 | 231 |
self.textInfoList = self.getMergedTextInfo(text) |
232 | 232 |
|
233 |
''' |
|
234 |
minX, minY, maxX, maxY = sys.maxsize, sys.maxsize, 0, 0 |
|
235 |
for textInfo in self.textInfoList: |
|
236 |
x, y, w, h = textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH() |
|
237 |
minX = min(x, minX) |
|
238 |
minY = min(y, minY) |
|
239 |
maxX = max(x + w, maxX) |
|
240 |
maxY = max(y + h, maxY) |
|
241 |
|
|
242 |
self.textInfoList = [TextInfo(text, minX, minY, maxX - minX, maxY - minY, 0)] |
|
243 |
''' |
|
244 |
|
|
245 |
''' |
|
246 |
if self.textInfoList: |
|
247 |
if self._text_item: |
|
248 |
textInfo = self.textInfoList[0] |
|
249 |
# Transform rectangle for calculate start point |
|
250 |
imgTransform = QTransform() |
|
251 |
if self.angle == 90 or self.angle == 270: |
|
252 |
imgTransform.translate(self.image.height() * 0.5, self.image.width() * 0.5) |
|
253 |
elif self.angle == 0 or self.angle == 360: |
|
254 |
imgTransform.translate(self.image.width() * 0.5, self.image.height() * 0.5) |
|
255 |
imgTransform.rotate(-abs(self.angle)) |
|
256 |
imgTransform.translate(-self.image.width() * 0.5, -self.image.height() * 0.5) |
|
257 |
rect = QRect(textInfo.getX() - int(self.boundingBox.x()), |
|
258 |
textInfo.getY() - int(self.boundingBox.y()), textInfo.getW(), textInfo.getH()) |
|
259 |
rect = imgTransform.mapRect(rect) |
|
260 |
# up to here |
|
261 |
textInfo.setX(rect.x() + int(self.boundingBox.x())) |
|
262 |
textInfo.setY(rect.y() + int(self.boundingBox.y())) |
|
263 |
textInfo.setText(splitText[0]) |
|
264 |
radian = round(math.radians(abs(self.angle)), 2) |
|
265 |
textInfo.setAngle(radian) # 360 degree == 6.28319 radian |
|
266 |
if radian == 1.57 or radian == 4.71: |
|
267 |
width = textInfo.getW() |
|
268 |
height = textInfo.getH() |
|
269 |
textInfo.setW(height) # SWAP |
|
270 |
textInfo.setH(width) # SWAP |
|
271 |
|
|
272 |
self._text_item.setPlainText(splitText[0]) |
|
273 |
self._text_item.loc = [textInfo.getX(), textInfo.getY()] |
|
274 |
self._text_item.size = (textInfo.getW(), textInfo.getH()) |
|
275 |
self._text_item.angle = radian |
|
276 |
self._text_item.update_shape() |
|
277 |
|
|
278 |
self.textInfoList = self.textInfoList[1:] |
|
279 |
''' |
|
280 | 233 |
radian = round(math.radians(abs(self.angle)), 2) |
281 | 234 |
if radian == 1.57 or radian == 4.71: |
282 | 235 |
for text_info in self.textInfoList: |
... | ... | |
336 | 289 |
|
337 | 290 |
def showDialog(self): |
338 | 291 |
# self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) |
339 |
self.exec_() |
|
340 |
return (self.isAccepted, self.textInfoList) |
|
292 |
res = self.exec_() |
|
293 |
return res, self.textInfoList |
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
7 | 7 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QObject, QT_VERSION_STR, QRect |
8 | 8 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QBrush, QPen, QTransform, QFont, QColor, QFontMetricsF |
9 | 9 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \ |
10 |
QGraphicsTextItem |
|
10 |
QGraphicsTextItem, QDialog
|
|
11 | 11 |
except ImportError: |
12 | 12 |
try: |
13 | 13 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QRect, QObject, QT_VERSION_STR |
... | ... | |
283 | 283 |
rect.moveTo(self.loc[0], self.loc[1]) |
284 | 284 |
return rect |
285 | 285 |
|
286 |
@staticmethod |
|
287 |
def create_text_with(scene, text_info): |
|
288 |
"""create a text using text_info""" |
|
289 |
from TextItemFactory import TextItemFactory |
|
290 |
|
|
291 |
x = text_info.getX() |
|
292 |
y = text_info.getY() |
|
293 |
angle = text_info.getAngle() |
|
294 |
text = text_info.getText() |
|
295 |
width = text_info.getW() |
|
296 |
height = text_info.getH() |
|
297 |
item = TextItemFactory.instance().createTextItem(text_info) |
|
298 |
if item is not None: |
|
299 |
item.loc = [x, y] |
|
300 |
item.size = (width, height) |
|
301 |
item.angle = angle |
|
302 |
item.addTextItemToScene(scene) |
|
303 |
|
|
304 |
return item |
|
305 |
|
|
286 | 306 |
def edit_text(self): |
287 | 307 |
"""edit text by using ocr dialog""" |
288 | 308 |
from TextItemFactory import TextItemFactory |
... | ... | |
290 | 310 |
|
291 | 311 |
item = None |
292 | 312 |
try: |
293 |
dialog = QOcrResultDialog(None, self.scene().parent().image().copy(self.loc[0] - 3, self.loc[1] - 3,
|
|
294 |
self.size[0] + 6, self.size[1] + 6),
|
|
313 |
dialog = QOcrResultDialog(None, self.scene().parent().image().copy(self.loc[0], self.loc[1],
|
|
314 |
self.size[0], self.size[1]),
|
|
295 | 315 |
QRect(self.loc[0], self.loc[1], self.size[0], self.size[1]), text_item=self) |
296 |
(isAccept, textInfoList) = dialog.showDialog() |
|
297 |
|
|
298 |
if isAccept: |
|
299 |
scene = self.scene() |
|
316 |
(res, textInfoList) = dialog.showDialog() |
|
300 | 317 |
|
318 |
if QDialog.Accepted == res and textInfoList: |
|
301 | 319 |
# create new texts |
302 | 320 |
for text_info in textInfoList: |
303 |
x = text_info.getX() |
|
304 |
y = text_info.getY() |
|
305 |
angle = text_info.getAngle() |
|
306 |
text = text_info.getText() |
|
307 |
width = text_info.getW() |
|
308 |
height = text_info.getH() |
|
309 |
item = TextItemFactory.instance().createTextItem(text_info) |
|
310 |
if item is not None: |
|
311 |
item.loc = [x, y] |
|
312 |
item.size = (width, height) |
|
313 |
item.angle = angle |
|
321 |
item = QEngineeringTextItem.create_text_with(self.scene(), text_info) |
|
322 |
if item: |
|
314 | 323 |
item.area = self.area |
315 |
item.addTextItemToScene(scene) |
|
316 |
item.transfer.onRemoved.connect(scene.parent().parent().parent().itemRemoved) |
|
324 |
item.transfer.onRemoved.connect(self.transfer.onRemoved) |
|
317 | 325 |
|
318 | 326 |
self.transfer.onRemoved.emit(self) |
319 | 327 |
except Exception as ex: |
320 |
message = 'error occurred({}) in {}:{}'.format(self.tr('Fail to create text'), |
|
321 |
sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
322 |
sys.exc_info()[-1].tb_lineno) |
|
323 |
self.addMessage.emit(MessageType.Normal, message) |
|
328 |
from App import App |
|
329 |
from AppDocData import MessageType |
|
330 |
|
|
331 |
message = 'error occurred({}-{}) in {}:{}'.format(repr(ex), self.text(), |
|
332 |
sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
333 |
sys.exc_info()[-1].tb_lineno) |
|
334 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
324 | 335 |
|
325 | 336 |
return item |
326 | 337 |
|
DTI_PID/DTI_PID/UI/dlgConnectAttr.ui | ||
---|---|---|
109 | 109 |
<property name="text"> |
110 | 110 |
<string>Start</string> |
111 | 111 |
</property> |
112 |
<property name="default"> |
|
113 |
<bool>true</bool> |
|
114 |
</property> |
|
112 | 115 |
</widget> |
113 | 116 |
</item> |
114 | 117 |
</layout> |
... | ... | |
117 | 120 |
</widget> |
118 | 121 |
<tabstops> |
119 | 122 |
<tabstop>pushButtonStart</tabstop> |
123 |
<tabstop>checkBoxUpdateFlowMark</tabstop> |
|
124 |
<tabstop>checkBoxUpdateSpec</tabstop> |
|
125 |
<tabstop>checkBoxUpdateLineType</tabstop> |
|
126 |
<tabstop>checkBoxValidation</tabstop> |
|
120 | 127 |
<tabstop>listWidget</tabstop> |
121 | 128 |
</tabstops> |
122 | 129 |
<resources/> |
... | ... | |
128 | 135 |
<slot>accept()</slot> |
129 | 136 |
<hints> |
130 | 137 |
<hint type="sourcelabel"> |
131 |
<x>248</x>
|
|
132 |
<y>254</y>
|
|
138 |
<x>834</x>
|
|
139 |
<y>442</y>
|
|
133 | 140 |
</hint> |
134 | 141 |
<hint type="destinationlabel"> |
135 | 142 |
<x>157</x> |
내보내기 Unified diff