개정판 0b04ae07
issue #627: export scene to svg and image file
Change-Id: I5e9ca0a513f3bbb5f2403f37958486f4602da927
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
217 | 217 |
# connect signals and slots |
218 | 218 |
self.actionClose.triggered.connect(self.close) |
219 | 219 |
self.actionOpen.triggered.connect(self.open_image_drawing) |
220 |
self.actionExportAsSVG.triggered.connect(self.export_as_svg) |
|
221 |
self.actionExportAsXML.triggered.connect(self.export_as_xml) |
|
222 |
self.actionExportAsImage.triggered.connect(self.export_as_image) |
|
220 | 223 |
self.actionLine.triggered.connect(self.onPlaceLine) |
221 | 224 |
self.actionRecognition.triggered.connect(self.recognize) |
222 | 225 |
self.pushButtonBatchRecognition.clicked.connect(self.recognizeBatch) |
... | ... | |
1417 | 1420 |
|
1418 | 1421 |
return self.path |
1419 | 1422 |
|
1423 |
def export_as_svg(self): |
|
1424 |
"""export scene to svg file""" |
|
1425 |
|
|
1426 |
options = QFileDialog.Options() |
|
1427 |
options |= QFileDialog.DontUseNativeDialog |
|
1428 |
file_path, _ = QFileDialog.getSaveFileName(self, "Export as svg", os.getcwd(), "svg file(*.svg)", |
|
1429 |
options=options) |
|
1430 |
if file_path: |
|
1431 |
try: |
|
1432 |
file_name, ext = os.path.splitext(file_path) |
|
1433 |
save_file_path = file_name + ext if ext.upper() == '.SVG' else file_name + '.svg' |
|
1434 |
|
|
1435 |
# hide image drawing |
|
1436 |
self.onViewImageDrawing(False) |
|
1437 |
|
|
1438 |
svg_gen = QSvgGenerator() |
|
1439 |
|
|
1440 |
svg_gen.setFileName(save_file_path) |
|
1441 |
rect = self.graphicsView.scene.sceneRect() |
|
1442 |
svg_gen.setSize(QSize(rect.width(), rect.height())) |
|
1443 |
svg_gen.setViewBox(QRect(0, 0, rect.width(), rect.height())) |
|
1444 |
svg_gen.setTitle(self.tr("SVG Generator for ID2")) |
|
1445 |
svg_gen.setDescription(self.tr("An SVG drawing created by the SVG Generator.")) |
|
1446 |
|
|
1447 |
painter = QPainter(svg_gen) |
|
1448 |
self.graphicsView.scene.render(painter) |
|
1449 |
painter.end() |
|
1450 |
|
|
1451 |
QMessageBox.information(None, self.tr('Information'), self.tr('Successfully export to svg file')) |
|
1452 |
finally: |
|
1453 |
if self.actionImage_Drawing.isChecked(): |
|
1454 |
self.onViewImageDrawing(True) |
|
1455 |
self.actionImage_Drawing.setChecked(True) |
|
1456 |
|
|
1457 |
def export_as_xml(self): |
|
1458 |
pass |
|
1459 |
|
|
1460 |
def export_as_image(self): |
|
1461 |
"""export scene to image file""" |
|
1462 |
|
|
1463 |
options = QFileDialog.Options() |
|
1464 |
options |= QFileDialog.DontUseNativeDialog |
|
1465 |
file_path, _ = QFileDialog.getSaveFileName(self, "Export as png", os.getcwd(), "png file(*.png)", |
|
1466 |
options=options) |
|
1467 |
if file_path: |
|
1468 |
try: |
|
1469 |
file_name, ext = os.path.splitext(file_path) |
|
1470 |
save_file_path = file_name + ext if ext.upper() == '.PNG' else file_name + '.png' |
|
1471 |
|
|
1472 |
# hide image drawing |
|
1473 |
self.onViewImageDrawing(False) |
|
1474 |
|
|
1475 |
rect = self.graphicsView.scene.sceneRect() |
|
1476 |
size = QSize(rect.width(), rect.height()) |
|
1477 |
image = QImage(size, QImage.Format_ARGB32_Premultiplied) |
|
1478 |
painter = QPainter(image) |
|
1479 |
|
|
1480 |
# render the scene |
|
1481 |
self.graphicsView.scene.render(painter) |
|
1482 |
painter.end() |
|
1483 |
|
|
1484 |
# save the image to a given file |
|
1485 |
image.save(save_file_path) |
|
1486 |
|
|
1487 |
QMessageBox.information(None, self.tr('Information'), self.tr('Successfully export to image file')) |
|
1488 |
finally: |
|
1489 |
if self.actionImage_Drawing.isChecked(): |
|
1490 |
self.onViewImageDrawing(True) |
|
1491 |
self.actionImage_Drawing.setChecked(True) |
|
1492 |
|
|
1420 | 1493 |
def show_Progress_bar(self): |
1421 | 1494 |
""" show progress bar """ |
1422 | 1495 |
self.progress = QProgressDialog(self.tr("Please wait for a while"), self.tr("Cancel"), 0, 100, |
... | ... | |
2147 | 2220 |
|
2148 | 2221 |
def createDetectedItems(self, symbolList, textInfoList, otherTextInfoList, titleBlockTextInfoList): |
2149 | 2222 |
try: |
2150 |
appDocData = AppDocData.instance() |
|
2151 |
|
|
2152 | 2223 |
QApplication.processEvents() |
2153 | 2224 |
self.createDetectedSymbolItem(symbolList) |
2154 | 2225 |
QApplication.processEvents() |
내보내기 Unified diff