개정판 66062705
fix pdf save
Change-Id: Ibebb728fac4894c04098ddf1c49ad1f0404f5675
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1497 | 1497 |
self.addMessage.emit(MessageType.Error, message) |
1498 | 1498 |
|
1499 | 1499 |
def on_export_PDF(self): |
1500 |
if not self.graphicsView.hasImage(): |
|
1501 |
self.showImageSelectionMessageBox() |
|
1502 |
return |
|
1500 |
# save alarm |
|
1501 |
self.save_alarm_enable(False) |
|
1502 |
|
|
1503 |
#if not self.graphicsView.hasImage(): |
|
1504 |
# self.showImageSelectionMessageBox() |
|
1505 |
# return |
|
1503 | 1506 |
|
1504 | 1507 |
try: |
1505 | 1508 |
app_doc_data = AppDocData.instance() |
1509 |
current_drawing = None |
|
1510 |
|
|
1511 |
if self.graphicsView.hasImage(): |
|
1512 |
current_drawing = app_doc_data.activeDrawing |
|
1513 |
|
|
1514 |
# get checked drawings |
|
1515 |
drawing_top = self.treeWidgetDrawingList.topLevelItem(0) |
|
1516 |
count = drawing_top.childCount() |
|
1517 |
checked_drawings = {} |
|
1518 |
for idx in range(count): |
|
1519 |
child = drawing_top.child(idx) |
|
1520 |
if child.checkState(0) == Qt.Checked and child.data(Qt.UserRole, 0): |
|
1521 |
checked_drawings[child.data(Qt.UserRole, 0)] = child |
|
1522 |
# up to here |
|
1523 |
|
|
1524 |
# if there is no checked drawing |
|
1525 |
if current_drawing and not checked_drawings: |
|
1526 |
for idx in range(count): |
|
1527 |
child = drawing_top.child(idx) |
|
1528 |
if child.data(Qt.UserRole, 0) is current_drawing: |
|
1529 |
checked_drawings[child.data(Qt.UserRole, 0)] = child |
|
1530 |
|
|
1531 |
if not checked_drawings: |
|
1532 |
self.showImageSelectionMessageBox() |
|
1533 |
return |
|
1534 |
|
|
1506 | 1535 |
project = app_doc_data.getCurrentProject() |
1507 |
name = os.path.join(project.getTempPath(), os.path.splitext(app_doc_data.activeDrawing.name)[0]) + '.png' |
|
1508 |
|
|
1509 |
options = QFileDialog.Options() |
|
1510 |
options |= QFileDialog.DontUseNativeDialog |
|
1511 |
file_name, _ = QFileDialog.getSaveFileName(self, "Export PDF", name, "pdf files(*.pdf)", options=options) |
|
1512 |
if file_name: |
|
1513 |
#pixMap = self.graphicsView.grab(QRect(QPoint(0, 0), QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())))) |
|
1514 |
#pixMap.save(name) |
|
1515 |
#return |
|
1516 |
|
|
1517 |
image = QImage(QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())), QImage.Format_ARGB32_Premultiplied) |
|
1518 |
painter = QPainter(image) |
|
1519 |
scene = self.graphicsView.scene() |
|
1520 |
canvasRect = scene.sceneRect() # or canvasRect = scene.border.boundingRect() |
|
1521 |
source = canvasRect |
|
1522 |
scene.render(painter, QRectF(image.rect()), source) |
|
1523 |
image.save(name) |
|
1524 |
image = Image.open(name) |
|
1525 |
image = image.convert('RGB') |
|
1526 |
image.save(name.replace('.png', '.pdf')) |
|
1527 |
os.remove(name.replace('.pdf', '.png')) |
|
1528 | 1536 |
|
1529 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully saved.')) |
|
1530 |
return |
|
1537 |
if current_drawing and len(checked_drawings) == 1: |
|
1538 |
name = os.path.join(project.getTempPath(), os.path.splitext(app_doc_data.activeDrawing.name)[0]) |
|
1539 |
|
|
1540 |
options = QFileDialog.Options() |
|
1541 |
options |= QFileDialog.DontUseNativeDialog |
|
1542 |
file_name, _ = QFileDialog.getSaveFileName(self, "Export PDF", name, "pdf files(*.pdf)", options=options) |
|
1543 |
name += '.png' |
|
1544 |
if file_name: |
|
1545 |
#pixMap = self.graphicsView.grab(QRect(QPoint(0, 0), QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())))) |
|
1546 |
#pixMap.save(name) |
|
1547 |
#return |
|
1548 |
|
|
1549 |
image = QImage(QSize(int(self.graphicsView.scene().sceneRect().width()), int(self.graphicsView.scene().sceneRect().height())), QImage.Format_ARGB32_Premultiplied) |
|
1550 |
painter = QPainter(image) |
|
1551 |
scene = self.graphicsView.scene() |
|
1552 |
canvasRect = scene.sceneRect() # or canvasRect = scene.border.boundingRect() |
|
1553 |
source = canvasRect |
|
1554 |
scene.render(painter, QRectF(image.rect()), source) |
|
1555 |
painter.end() |
|
1556 |
image.save(name) |
|
1557 |
image = Image.open(name) |
|
1558 |
image = image.convert('RGB') |
|
1559 |
image.save(name.replace('.png', '.pdf')) |
|
1560 |
os.remove(name) |
|
1561 |
painter.device() |
|
1562 |
|
|
1563 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully saved.')) |
|
1564 |
return |
|
1531 | 1565 |
|
1532 | 1566 |
''' |
1533 | 1567 |
#app_doc_data = AppDocData.instance() |
내보내기 Unified diff