프로젝트

일반

사용자정보

개정판 0b04ae07

ID0b04ae07062cf7fee8a3cb80db49fb843f266e5b
상위 e2ae85c2
하위 87e58fad, 01b11115, f5b9097a

백흠경이(가) 약 5년 전에 추가함

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()
DTI_PID/DTI_PID/MainWindow_UI.py
2 2

  
3 3
# Form implementation generated from reading ui file '.\UI\MainWindow.ui'
4 4
#
5
# Created by: PyQt5 UI code generator 5.14.1
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

  
......
46 46
        self.menuTheme.setObjectName("menuTheme")
47 47
        self.menuLanguage = QtWidgets.QMenu(self.menu)
48 48
        self.menuLanguage.setObjectName("menuLanguage")
49
        self.menuExport = QtWidgets.QMenu(self.menu)
50
        self.menuExport.setObjectName("menuExport")
49 51
        self.menu_2 = QtWidgets.QMenu(self.menubar)
50 52
        self.menu_2.setObjectName("menu_2")
51 53
        self.menu_3 = QtWidgets.QMenu(self.menubar)
......
502 504
        self.actionCustom_Code_Table = QtWidgets.QAction(MainWindow)
503 505
        self.actionCustom_Code_Table.setIcon(icon15)
504 506
        self.actionCustom_Code_Table.setObjectName("actionCustom_Code_Table")
507
        self.actionExportAsSVG = QtWidgets.QAction(MainWindow)
508
        self.actionExportAsSVG.setObjectName("actionExportAsSVG")
509
        self.actionExportAsXML = QtWidgets.QAction(MainWindow)
510
        self.actionExportAsXML.setObjectName("actionExportAsXML")
511
        self.actionExportAsImage = QtWidgets.QAction(MainWindow)
512
        self.actionExportAsImage.setObjectName("actionExportAsImage")
513
        self.menuExport.addAction(self.actionExportAsSVG)
514
        self.menuExport.addAction(self.actionExportAsXML)
515
        self.menuExport.addAction(self.actionExportAsImage)
505 516
        self.menu.addAction(self.actionOpen)
506 517
        self.menu.addAction(self.actionArea)
507 518
        self.menu.addAction(self.actionConfiguration)
519
        self.menu.addAction(self.menuExport.menuAction())
508 520
        self.menu.addSeparator()
509 521
        self.menu.addAction(self.menuTheme.menuAction())
510 522
        self.menu.addAction(self.menuLanguage.menuAction())
......
576 588
        self.menu.setTitle(_translate("MainWindow", "File"))
577 589
        self.menuTheme.setTitle(_translate("MainWindow", "Theme"))
578 590
        self.menuLanguage.setTitle(_translate("MainWindow", "Language"))
591
        self.menuExport.setTitle(_translate("MainWindow", "Export"))
579 592
        self.menu_2.setTitle(_translate("MainWindow", "Data"))
580 593
        self.menu_3.setTitle(_translate("MainWindow", "View"))
581 594
        self.menu_4.setTitle(_translate("MainWindow", "Tool"))
......
673 686
        self.actionExportEqpDatasheet.setToolTip(_translate("MainWindow", "Export Equipment Datasheet"))
674 687
        self.actionSymbol_Training.setText(_translate("MainWindow", "Symbol Training"))
675 688
        self.actionCustom_Code_Table.setText(_translate("MainWindow", "Custom Code Table"))
689
        self.actionExportAsSVG.setText(_translate("MainWindow", "SVG"))
690
        self.actionExportAsXML.setText(_translate("MainWindow", "XML"))
691
        self.actionExportAsImage.setText(_translate("MainWindow", "Image"))
676 692
import MainWindow_rc
DTI_PID/DTI_PID/UI/MainWindow.ui
74 74
      <string>Language</string>
75 75
     </property>
76 76
    </widget>
77
    <widget class="QMenu" name="menuExport">
78
     <property name="title">
79
      <string>Export</string>
80
     </property>
81
     <addaction name="actionExportAsSVG"/>
82
     <addaction name="actionExportAsXML"/>
83
     <addaction name="actionExportAsImage"/>
84
    </widget>
77 85
    <addaction name="actionOpen"/>
78 86
    <addaction name="actionArea"/>
79 87
    <addaction name="actionConfiguration"/>
88
    <addaction name="menuExport"/>
80 89
    <addaction name="separator"/>
81 90
    <addaction name="menuTheme"/>
82 91
    <addaction name="menuLanguage"/>
......
1145 1154
    <string>Custom Code Table</string>
1146 1155
   </property>
1147 1156
  </action>
1157
  <action name="actionExportAsSVG">
1158
   <property name="text">
1159
    <string>SVG</string>
1160
   </property>
1161
  </action>
1162
  <action name="actionExportAsXML">
1163
   <property name="text">
1164
    <string>XML</string>
1165
   </property>
1166
  </action>
1167
  <action name="actionExportAsImage">
1168
   <property name="text">
1169
    <string>Image</string>
1170
   </property>
1171
  </action>
1148 1172
 </widget>
1149 1173
 <resources>
1150 1174
  <include location="../res/MainWindow.qrc"/>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)