コード例 #1
0
ファイル: page.py プロジェクト: frescobaldi/qpageview
    def svg(self, filename, rect=None, resolution=72.0, paperColor=None):
        """Create a SVG file for the selected rect or the whole page.

        The filename may be a string or a QIODevice object. The rectangle is
        relative to our top-left position. Normally vector graphics are
        rendered, but in cases where that is not possible, the resolution will
        be used to determine the DPI for the generated rendering.

        """
        # map to the original page
        source = self.pageRect() if rect is None else self.mapFromPage().rect(
            rect)
        # scale to target size
        w = source.width() * self.scaleX
        h = source.height() * self.scaleY
        if self.computedRotation & 1:
            w, h = h, w
        targetSize = QSizeF(w, h) * resolution / self.dpi

        svg = QSvgGenerator()
        if isinstance(filename, str):
            svg.setFileName(filename)
        else:
            svg.setOutputDevice(filename)
        svg.setResolution(int(resolution))
        svg.setSize(targetSize.toSize())
        svg.setViewBox(QRectF(0, 0, targetSize.width(), targetSize.height()))
        return self.output(svg, source, paperColor)
コード例 #2
0
ファイル: nexicoMain.py プロジェクト: gromoteur/gromoteur
 def on_actionSaveGraph_triggered(self):
     if self.selectedWord: filename = self.selectedWord + "-specificity.png"
     else: filename = "specificity.png"
     fileName = QFileDialog.getSaveFileName(
         self, "Save Graph as png, svg, or pdf", filename,
         "PNG Image (*.png);;PDF File(*.pdf);;SVG File(*.svg)")[0]
     if str(fileName).endswith(".png"):
         #pixMap=QPixmap.grabWidget( self.graphicsView)
         pixMap = self.graphicsView.grab()
         pixMap.save(fileName)
     elif str(fileName).endswith(".pdf"):
         pdfPrinter = QPrinter()
         pdfPrinter.setOutputFormat(QPrinter.PdfFormat)
         pdfPrinter.setPaperSize(
             QSizeF(self.graphicsView.width(), self.graphicsView.height()),
             QPrinter.Point)
         pdfPrinter.setFullPage(True)
         pdfPrinter.setOutputFileName(fileName)
         pdfPainter = QPainter()
         pdfPainter.begin(pdfPrinter)
         self.graphicsView.render(pdfPainter)
         pdfPainter.end()
     elif str(fileName).endswith(".svg"):
         svgGen = QSvgGenerator()
         svgGen.setFileName(fileName)
         svgGen.setSize(
             QSize(self.graphicsView.width(), self.graphicsView.height()))
         svgGen.setViewBox(
             QRect(0, 0, self.graphicsView.width(),
                   self.graphicsView.height()))
         svgGen.setTitle(filename)
         svgGen.setDescription("Specificity graph generated by Gromoteur")
         painter = QPainter(svgGen)
         self.graphicsView.render(painter)
         painter.end()
コード例 #3
0
    def ExportSVG(self):
        """
        action triggered when user exports current graphics as svg
        :return:
        """
        newPath = QFileDialog.getSaveFileName(self.centralwidget,
                                              "Export .svg", self.homeFolder,
                                              "SVG files (*.svg)")
        if not newPath[0]:
            return

        filename = newPath[0]
        if self.bitmapVisibility:
            self.ToggleBitmap()
        generator = QSvgGenerator()
        generator.setFileName(filename)
        sceneSize = self.scene.sceneRect().size()
        generator.setSize(sceneSize.toSize())
        generator.setViewBox(QRect(0, 0, sceneSize.width(),
                                   sceneSize.height()))
        generator.setDescription("generated by SVG generator")
        generator.setTitle(filename)
        painter = QPainter()
        painter.begin(generator)
        self.scene.render(painter)
        painter.end()
コード例 #4
0
    def export_to_svg(self):
        """
        Graph editor's scene rendering & saving to svg-file
        :return: None
        """

        filename = QFileDialog.getSaveFileName(None, 'Сохранить SVG-граф', "",
                                               "svg files (*.svg)")

        if len(filename[0]) > 4:

            svg = QSvgGenerator()
            svg.setFileName(filename[0])

            w = self.__graph_editor.get_diagram_scene().width()
            h = self.__graph_editor.get_diagram_scene().height()

            svg.setSize(QSize(w, h))
            svg.setViewBox(QRect(0, 0, w, h))
            svg.setTitle('Semantic Graph')
            svg.setDescription('File created by RTA')

            painter = QPainter()
            painter.begin(svg)
            self.__graph_editor.get_diagram_scene().render(painter)
            painter.end()
コード例 #5
0
    def export(self, file, format):
        bounds = self.__get_bounds()
        size = self.get_size(bounds)

        if format == 'svg':
            output = QSvgGenerator()
            output.setFileName(file)

            output.setSize(size)
            output.setViewBox(QRect(QPoint(0, 0), size))
            if isinstance(self.__diagram_or_selection, Diagram):
                output.setTitle(self.__diagram_or_selection.get_display_name()
                                or "")
        elif format == 'pdf':
            output = QPrinter()
            output.setOutputFormat(QPrinter.PdfFormat)
            output.setPaperSize(QSizeF(size), QPrinter.DevicePixel)
            output.setPageMargins(0, 0, 0, 0, QPrinter.DevicePixel)
            output.setOutputFileName(file)
        else:
            output = QPixmap(size)
            output.fill(Qt.transparent)

        self.__draw(bounds, output)

        if format not in ('svg', 'pdf'):
            output.save(file, format)
コード例 #6
0
    def save(self,
             path,
             filetype=None,
             title=None,
             description=None,
             svg_dpi=SVG_INKSCAPE):
        if path is None or not isinstance(path, str):
            logger.error('please provide a valide path to save the image "' +
                         str(path) + '"')
            return
        if filetype is None:
            if path.lower().endswith('.svg'):
                filetype = 'svg'
            else:
                filetype = 'raster'
        dpi = 72  # 300 # inkscape 96 ? check for illustrator --> check

        if filetype == 'svg':
            generator = QSvgGenerator()
            generator.setFileName(path)
            if svg_dpi == self.SVG_ILLUSTRATOR:
                generator.setSize(QSize(595, 842))
                generator.setViewBox(QRect(0, 0, 595, 842))
            else:
                generator.setSize(QSize(794, 1123))
                generator.setViewBox(QRect(0, 0, 794, 1123))

            if title is not None and isinstance(title, str):
                generator.setTitle(title)
            if description is not None and isinstance(description, str):
                generator.setDescription(description)
            generator.setResolution(
                svg_dpi
            )  # fixes issues in inkscape of pt size --> 72 pr illustrator and 96 pr inkscape but need change size

            painter = QPainter(generator)

            print(generator.title(), generator.heightMM(), generator.height(),
                  generator.widthMM(), generator.resolution(),
                  generator.description(), generator.logicalDpiX())
        else:
            scaling_factor_dpi = 1
            scaling_factor_dpi = self.scaling_factor_to_achieve_DPI(300)
            image = QtGui.QImage(
                QSize(
                    self.cm_to_inch(21) * dpi * scaling_factor_dpi,
                    self.cm_to_inch(29.7) * dpi * scaling_factor_dpi),
                QtGui.QImage.Format_RGB32)
            painter = QPainter(
                image)  # see what happens in case of rounding of pixels
            painter.scale(scaling_factor_dpi, scaling_factor_dpi)
        painter.setRenderHint(
            QPainter.HighQualityAntialiasing
        )  # to improve rendering #Antialiasing otherwise or nothing
        self.paint(painter)
        painter.end()
        if filetype != 'svg':
            image.save(path)
コード例 #7
0
ファイル: plants.py プロジェクト: xiaoxiae/Florodoro
    def save(self, path: str, width: int, height: int):
        """Save the drawable to the specified file, given its size."""
        generator = QSvgGenerator()
        generator.setFileName(path)
        generator.setSize(QSize(width, height))
        generator.setViewBox(QRect(0, 0, width, height))

        painter = QPainter(generator)
        self.draw(painter, width, height)
        painter.end()
コード例 #8
0
    def ExportSVGPerLayer(self):
        """
        action triggered when user exports current graphics as one svg per layer
        :return:
        """
        newPath = QFileDialog.getSaveFileName(self.centralwidget,
                                              "Export .svg per layer",
                                              self.homeFolder,
                                              "SVG files (*.svg)")
        if not newPath[0]:
            return

        filename = newPath[0]

        if self.bitmapVisibility:
            self.ToggleBitmap()

        # make stuff invisible to avoid sending it to svg
        for layer_idx in range(self.layersModel.rowCount()):
            print("*** iteration {0}".format(layer_idx))
            layer_filename = "{0}_layer{1}.svg".format(
                os.path.splitext(filename)[0], layer_idx + 1)
            for item in self.scene.items():
                item.setVisible(True)
                forceAlwaysInvisible = item.__class__ == QGraphicsPixmapItem
                forceInvisibleInCurrentLayer = item.__class__ == QGraphicsItemGroup and \
                                               (item != self.layersModel.item(layer_idx).get_graphics_items_group() or \
                                                self.layersModel.item(layer_idx).checkState() != Qt.Checked)
                if forceAlwaysInvisible or forceInvisibleInCurrentLayer:  # ouch
                    print("setting idx to invisible for item {0}".format(item))
                    item.setVisible(False)
            if self.layersModel.item(layer_idx).checkState() == Qt.Checked:
                generator = QSvgGenerator()
                generator.setFileName(layer_filename)
                sceneSize = self.scene.sceneRect().size()
                generator.setSize(sceneSize.toSize())
                generator.setViewBox(
                    QRect(0, 0, sceneSize.width(), sceneSize.height()))
                generator.setDescription("generated by SVG generator")
                generator.setTitle(layer_filename)
                painter = QPainter()
                painter.begin(generator)
                self.scene.render(painter)
                painter.end()

        # restore visibility
        for layer_idx in range(self.layersModel.rowCount()):
            for item in self.scene.items():
                if item.__class__ == QGraphicsItemGroup and \
                        self.layersModel.item(layer_idx).checkState() == Qt.Checked:  # ouch
                    item.setVisible(True)
コード例 #9
0
def grab_svg(scene):
    """
    Return a SVG rendering of the scene contents.

    Parameters
    ----------
    scene : :class:`CanvasScene`

    """
    from PyQt5.QtSvg import QSvgGenerator
    svg_buffer = QBuffer()
    gen = QSvgGenerator()
    gen.setOutputDevice(svg_buffer)

    items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10)

    if items_rect.isNull():
        items_rect = QRectF(0, 0, 10, 10)

    width, height = items_rect.width(), items_rect.height()
    rect_ratio = float(width) / height

    # Keep a fixed aspect ratio.
    aspect_ratio = 1.618
    if rect_ratio > aspect_ratio:
        height = int(height * rect_ratio / aspect_ratio)
    else:
        width = int(width * aspect_ratio / rect_ratio)

    target_rect = QRectF(0, 0, width, height)
    source_rect = QRectF(0, 0, width, height)
    source_rect.moveCenter(items_rect.center())

    gen.setSize(target_rect.size().toSize())
    gen.setViewBox(target_rect)

    painter = QPainter(gen)

    # Draw background.
    painter.setBrush(QBrush(Qt.white))
    painter.drawRect(target_rect)

    # Render the scene
    scene.render(painter, target_rect, source_rect)
    painter.end()

    buffer_str = bytes(svg_buffer.buffer())
    return buffer_str.decode("utf-8")
コード例 #10
0
ファイル: image.py プロジェクト: caiofattori/PyPFSDesign
	def gravaSvg(scene, filename):
		if not hasSvg:
			return False
		aux = scene._paintGrid
		scene._paintGrid = False
		scene.clearSelection()
		svg = QSvgGenerator()
		svg.setFileName(filename)
		svg.setSize(QSize(scene.width(), scene.height()))
		svg.setViewBox(QRect(0, 0, scene.width(), scene.height()))
		painter = QPainter()
		painter.begin(svg)
		scene.render(painter)
		painter.end()
		scene._paintGrid = aux
		return True
コード例 #11
0
 def handleExportUpdate(self, fileName, fileType):
     """Handles the paint event after the export of the current view has been initiated."""
     print("test")
     if fileType == "PNG":
         if len(fileName) > 0:
             print("Saving current view to ", fileName)
             currentView = self.painter.grab()
             currentView.save(fileName)
     elif fileType == "SVG":
         if len(fileName) > 0:
             print("Saving current view to ", fileName)
             generator = QSvgGenerator()
             generator.setFileName(fileName)
             generator.setSize(self.painter.size())
             generator.setViewBox(self.painter.rect())
             self.painter.renderContact(generator)
     self.painter.rendered = False
     self.painter.repaint()
     self.painter.update()
コード例 #12
0
def export_graphics_to_svg(widget, filename):
    """Export graphics to svg

    Parameters
    ----------
    widget : instance of QGraphicsView
        traces or overview
    filename : str
        path to save svg
    """
    generator = QSvgGenerator()
    generator.setFileName(filename)
    generator.setSize(widget.size())
    generator.setViewBox(widget.rect())

    painter = QPainter()
    painter.begin(generator)
    widget.render(painter)
    painter.end()
コード例 #13
0
ファイル: spiral.py プロジェクト: ffeng271/spiraliser
    def saveSvg(self):
        path = "save.svg"
        self.status_update_signal.emit("exporting SVG to %s" % (path))
        generator = QSvgGenerator()
        generator.setFileName(path)
        w = self.pixmap.size().width()
        h = self.pixmap.size().height()
        generator.setSize(QSize(w, h))
        generator.setViewBox(QRect(0, 0, w, h))
        generator.setTitle("Spiraliser!")
        qp = QPainter(generator)

        showImage = self.showImage
        self.showImage = False
        self.paint(qp)
        self.showImage = showImage

        qp.end()

        self.saveHPGL()
コード例 #14
0
    def exportSvg(self):
        """
        For exporting a svg file (text is still too large)
        Returns
        -------

        """
        generator = QSvgGenerator()
        generator.setResolution(300)
        generator.setSize(
            QSize(self.diagramScene.width(), self.diagramScene.height()))
        # generator.setViewBox(QRect(0, 0, 800, 800))
        generator.setViewBox(self.diagramScene.sceneRect())
        generator.setFileName("VectorGraphicsExport.svg")

        painter = QPainter()
        painter.begin(generator)
        painter.setRenderHint(QPainter.Antialiasing)
        self.diagramScene.render(painter)
        painter.end()
コード例 #15
0
    def saveSVGDialogCallback(self, selected):
        if isinstance(selected, (list, tuple)):
            fname = selected[0]
        else:
            fname = selected
        print("da fname", fname)
        if fname is None or os.path.isdir(fname):
            return False
        if not fname.lower().endswith(".svg"):
            fname += ".svg"
        if self.svgsavedialog is not None:
            self.svgsavedialog.filesSelected.disconnect(
                self.saveSVGDialogCallback)
            del self.svgsavedialog  # prevents hang
            self.svgsavedialog = None

        generator = QSvgGenerator()
        generator.setFileName(fname)
        generator.setSize(QSize(200, 330))
        generator.setViewBox(QRect(0, 0, 2000, 2000))
        painter = QPainter()

        # Render through scene
        # painter.begin(generator)
        # self.win.pathscene.render(painter)
        # painter.end()

        # Render item-by-item
        painter = QPainter()
        style_option = QStyleOptionGraphicsItem()
        q = [self.win.pathroot]
        painter.begin(generator)
        while q:
            graphics_item = q.pop()
            transform = graphics_item.itemTransform(self.win.sliceroot)[0]
            painter.setTransform(transform)
            if graphics_item.isVisible():
                graphics_item.paint(painter, style_option, None)
                q.extend(graphics_item.childItems())
        painter.end()
コード例 #16
0
    def save_results(self) -> None:
        """
        Save results chart or table.

        :return: nothing
        :rtype: None
        """

        filename, self.last_path = get_filename(
            self, "save", self.tr("Save results ..."), self.last_path,
            FileTypes(["csv", "png", "svg"]))
        if filename is None:
            return

        logging.info(self.tr("Saving results to '{}'").format(filename))
        try:
            if filename.endswith("csv"):
                self.results.to_csv(filename, index=False)
            elif filename.endswith("png"):
                self.cvResults.grab().save(filename)
            elif filename.endswith("svg"):
                output_rect = QRectF(
                    self.cvResults.chart().scene().sceneRect())
                output_size = QSize(output_rect.size().toSize())
                svg_generator = QSvgGenerator()
                svg_generator.setFileName(filename)
                svg_generator.setSize(output_size)
                svg_generator.setViewBox(output_rect)
                painter = QPainter()
                painter.begin(svg_generator)
                self.cvResults.chart().scene().render(
                    painter,
                    source=output_rect,
                    target=output_rect,
                    mode=Qt.IgnoreAspectRatio)
                painter.end()
        except (OSError, ValueError) as e:
            logging.error(str(e))
            QMessageBox.critical(self, self.tr("Error"), str(e))
            return
コード例 #17
0
    def saveSVGDialogCallback(self, selected):
        if isinstance(selected, (list, tuple)):
            fname = selected[0]
        else:
            fname = selected
        print("da fname", fname)
        if fname is None or os.path.isdir(fname):
            return False
        if not fname.lower().endswith(".svg"):
            fname += ".svg"
        if self.svgsavedialog != None:
            self.svgsavedialog.filesSelected.disconnect(self.saveSVGDialogCallback)
            del self.svgsavedialog  # prevents hang
            self.svgsavedialog = None

        generator = QSvgGenerator()
        generator.setFileName(fname)
        generator.setSize(QSize(200, 200))
        generator.setViewBox(QRect(0, 0, 2000, 2000))
        painter = QPainter()

        # Render through scene
        # painter.begin(generator)
        # self.win.pathscene.render(painter)
        # painter.end()

        # Render item-by-item
        painter = QPainter()
        style_option = QStyleOptionGraphicsItem()
        q = [self.win.pathroot]
        painter.begin(generator)
        while q:
            graphics_item = q.pop()
            transform = graphics_item.itemTransform(self.win.sliceroot)[0]
            painter.setTransform(transform)
            if graphics_item.isVisible():
                graphics_item.paint(painter, style_option, None)
                q.extend(graphics_item.childItems())
        painter.end()
コード例 #18
0
ファイル: artwork.py プロジェクト: puddletag/puddletag
def create_svg(text, font, rect=None):
    if not rect:
        rect = QRect(0, 0, 200, 200)
    f = tempfile.NamedTemporaryFile()

    generator = QSvgGenerator()
    generator.setFileName(f.name)
    generator.setSize(rect.size())
    generator.setViewBox(rect)
    generator.setTitle("puddletag image")
    generator.setDescription("just to see")

    painter = QPainter()
    painter.begin(generator)
    painter.fillRect(rect, Qt.GlobalColor.black)
    painter.setFont(font)
    painter.setPen(Qt.GlobalColor.white)
    painter.setBrush(QBrush(Qt.GlobalColor.white))
    painter.drawText(rect, Qt.AlignmentFlag.AlignCenter, text)
    painter.end()

    svg = open(f.name).read()
    f.close()
    return svg
コード例 #19
0
except:
    try:
        from PyQt4.QtGui import QApplication, QPainter, QImage
        from PyQt4.QtCore import QPointF, QRectF, QRect
        from PyQt4.QtSvg import QSvgGenerator

    except:
        from PySide.QtGui import QApplication, QPainter, QImage
        from PySide.QtCore import QPointF, QRectF, QRect
        from PySide.QtSvg import QSvgGenerator

if __name__ == '__main__':
    app = QApplication(sys.argv)

    file_name = r'C:\Users\ipetrash\Desktop\explorer.png'

    im = QImage()
    im.load(file_name)
    w, h = im.size().width(), im.size().height()

    gen = QSvgGenerator()
    gen.setFileName(os.path.splitext(file_name)[0] + '.svg')
    gen.setSize(im.size())
    gen.setViewBox(QRect(0, 0, w, h))

    painter = QPainter()
    painter.begin(gen)
    painter.drawImage(QPointF(0, 0), im, QRectF(0, 0, w, h))
    painter.end()
コード例 #20
0
    def save(self, path, filetype=None, title=None, description=None, svg_dpi=SVG_INKSCAPE):
        if path is None or not isinstance(path, str):
            logger.error('please provide a valide path to save the image "' + str(path) + '"')
            return
        if filetype is None:
            if path.lower().endswith('.svg'):
                filetype = 'svg'
            else:
                filetype = os.path.splitext(path)[1]
        dpi = 72  # 300 # inkscape 96 ? check for illustrator --> check

        if filetype == 'svg':
            generator = QSvgGenerator()
            generator.setFileName(path)
            if svg_dpi == self.SVG_ILLUSTRATOR:
                generator.setSize(QSize(595, 842))
                generator.setViewBox(QRect(0, 0, 595, 842))
            else:
                generator.setSize(QSize(794, 1123))
                generator.setViewBox(QRect(0, 0, 794, 1123))

            if title is not None and isinstance(title, str):
                generator.setTitle(title)
            if description is not None and isinstance(description, str):
                generator.setDescription(description)
            generator.setResolution(
                svg_dpi)  # fixes issues in inkscape of pt size --> 72 pr illustrator and 96 pr inkscape but need change size

            painter = QPainter(generator)

            # print(generator.title(), generator.heightMM(), generator.height(), generator.widthMM(),
            #       generator.resolution(), generator.description(), generator.logicalDpiX())
        else:
            scaling_factor_dpi = 1
            scaling_factor_dpi = self.scaling_factor_to_achieve_DPI(300)

            # in fact take actual page size ??? multiplied by factor
            # just take real image size instead


            # image = QtGui.QImage(QSize(self.cm_to_inch(21) * dpi * scaling_factor_dpi, self.cm_to_inch(29.7) * dpi * scaling_factor_dpi), QtGui.QImage.Format_RGBA8888) # minor change to support alpha # QtGui.QImage.Format_RGB32)

            # NB THE FOLLOWING LINES CREATE A WEIRD ERROR WITH WEIRD PIXELS DRAWN some sort of lines NO CLUE WHY
            img_bounds = self.getBounds()
            image = QtGui.QImage(QSize(img_bounds.width() * scaling_factor_dpi, img_bounds.height()* scaling_factor_dpi),  QtGui.QImage.Format_RGBA8888)  # minor change to support alpha # QtGui.QImage.Format_RGB32)
            # print('size at dpi',QSize(img_bounds.width() * scaling_factor_dpi, img_bounds.height()* scaling_factor_dpi))
            # QSize(self.cm_to_inch(0.02646 * img_bounds.width())
            # self.cm_to_inch(0.02646 * img_bounds.height())
            # need convert pixels to inches
            # is there a rounding error

            # force white bg for non jpg
            try:
                # print(filetype.lower())
                # the tif and png file formats support alpha
                if not filetype.lower() == '.png' and not filetype.lower() == '.tif' and not filetype.lower() == '.tiff':
                    image.fill(QColor.fromRgbF(1,1,1))
                else:
                    # image.fill(QColor.fromRgbF(1, 1, 1, alpha=1))
                    # image.fill(QColor.fromRgbF(1, 1, 1, alpha=1))
                    # TODO KEEP in fact image need BE FILLED WITH TRANSPARENT OTHERWISE GETS WEIRD DRAWING ERRORS
                    # TODO KEEP SEE https://stackoverflow.com/questions/13464627/qt-empty-transparent-qimage-has-noise
                    # image.fill(qRgba(0, 0, 0, 0))
                    image.fill(QColor.fromRgbF(0,0,0,0))
            except:
                pass
            painter = QPainter(image)  # see what happens in case of rounding of pixels
            # painter.begin()
            painter.scale(scaling_factor_dpi, scaling_factor_dpi)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)  # to improve rendering quality
        self.paint(painter)
        painter.end()
        if filetype != 'svg':
            image.save(path)
コード例 #21
0
    def __save(self):
        """If AerialWare has been used as a module, emits signal 'done'. Saves user results into SVG and makes report otherwise.
		"""
        # Variables for report
        self.pointsMeridian = ""
        self.pointsHorizontal = ""

        # Total lengths of paths. Used in report and methods.
        self.lenMeridian = 0
        self.lenMeridianWithTurns = 0
        self.lenHorizontal = 0
        self.lenHorizontalWithTurns = 0

        # Fields for methods
        self.pathMeridianPointsPx = []
        self.pathMeridianPointsDeg = []
        self.pathMeridianLinesPx = []
        self.pathMeridianLinesWithTurnsPx = []
        self.pathMeridianLinesDeg = []
        self.pathMeridianLinesWithTurnsDeg = []

        self.pathHorizontalPointsPx = []
        self.pathHorizontalPointsDeg = []
        self.pathHorizontalLinesPx = []
        self.pathHorizontalLinesWithTurnsPx = []
        self.pathHorizontalLinesDeg = []
        self.pathHorizontalLinesWithTurnsDeg = []

        # Process each line
        def processLines(lines, isMeridian=False):
            i = 2  # Counter for report
            isEven = False  # If current line is even we must swap it's points.
            for line in lines:
                linePx = line.line()
                p1 = linePx.p1()
                p2 = linePx.p2()
                p1Deg = self.pxToDeg(p1.x(), p1.y())
                p2Deg = self.pxToDeg(p2.x(), p2.y())
                lineDeg = QLineF(p1Deg, p2Deg)
                lineLength = self.__lenMeters(p1Deg, p2Deg)

                if isMeridian:
                    self.pathMeridianLinesWithTurnsPx.append(linePx)
                    self.pathMeridianLinesWithTurnsDeg.append(lineDeg)
                    self.lenMeridianWithTurns += lineLength
                else:
                    self.pathHorizontalLinesWithTurnsPx.append(linePx)
                    self.pathHorizontalLinesWithTurnsDeg.append(lineDeg)
                    self.lenHorizontalWithTurns += lineLength

                if line.pen().style(
                ) == Qt.SolidLine:  # Check if current line doesn't represent turn
                    if isEven:
                        p1, p2, p1Deg, p2Deg = p2, p1, p2Deg, p1Deg

                    point = f'"{i - 1}","{p1Deg.x()}","{p1Deg.y()}"\n' + f'"{i}","{p2Deg.x()}","{p2Deg.y()}"\n'
                    if isMeridian:
                        self.pointsMeridian += point
                        self.pathMeridianPointsPx.extend([p1, p2])
                        self.pathMeridianPointsDeg.extend([p1Deg, p2Deg])
                        self.pathMeridianLinesPx.append(linePx)
                        self.pathMeridianLinesDeg.append(lineDeg)
                        self.lenMeridian += lineLength
                    else:
                        self.pointsHorizontal += point
                        self.pathHorizontalPointsPx.extend([p1, p2])
                        self.pathHorizontalPointsDeg.extend([p1Deg, p2Deg])
                        self.pathHorizontalLinesPx.append(linePx)
                        self.pathHorizontalLinesDeg.append(lineDeg)
                        self.lenHorizontal += lineLength
                    isEven = not isEven
                    i += 2

        processLines(self.scene.getMeridianLines(), True)
        processLines(self.scene.getHorizontalLines())

        if self.getResultsAfterCompletion:
            self.done.emit()
            return

        self.__disableItems()

        # Make report
        pointHeader = f'"{self.lang.repPoint}","{self.lang.lblLatitude}","{self.lang.lblLongitude}"\n'

        if self.lenHorizontalWithTurns > self.lenMeridianWithTurns:
            directionWithTurns = self.lang.repFlyMeridians
        elif self.lenHorizontalWithTurns < self.lenMeridianWithTurns:
            directionWithTurns = self.lang.repFlyHorizontals
        else:
            directionWithTurns = self.lang.repFlyEqual

        if self.lenHorizontal > self.lenMeridian:
            directionWithoutTurns = self.lang.repFlyMeridians
        elif self.lenHorizontal < self.lenMeridian:
            directionWithoutTurns = self.lang.repFlyHorizontals
        else:
            directionWithoutTurns = self.lang.repFlyEqual

        report = (
            f'"{self.lang.repCornersDescription}"\n'
            f'"{self.lang.lblCorner}","{self.lang.lblLongitude}","{self.lang.lblLatitude}"\n'
            f'"{self.lang.lblTopLeft}","{self.xTL}","{self.yTL}"\n'
            f'"{self.lang.lblTopRight}","{self.xTR}","{self.yTR}"\n'
            f'"{self.lang.lblBottomLeft}","{self.xBL}","{self.yBL}"\n'
            f'"{self.lang.lblBottomRight}","{self.xBR}","{self.yBR}"\n'
            f'"{self.lang.lblDelimiters}","{self.xD}","{self.yD}"\n\n'
            f'"{self.lang.repTotalWithTurns}"\n'
            f'"{self.lang.repByMeridians}","{self.lenMeridianWithTurns}"\n'
            f'"{self.lang.repByHorizontals}","{self.lenHorizontalWithTurns}"\n'
            f'"{self.lang.repBetterFlyBy}","{directionWithTurns}"\n\n'
            f'"{self.lang.repTotalWithoutTurns}"\n'
            f'"{self.lang.repByMeridians}","{self.lenMeridian}"\n'
            f'"{self.lang.repByHorizontals}","{self.lenHorizontal}"\n'
            f'"{self.lang.repBetterFlyBy}","{directionWithoutTurns}"\n\n'
            f'"{self.lang.repAerialParams}"\n'
            f'"{self.lang.repArea}","{self.maxHorizontal}","x","{self.maxVertical}"\n'
            f'"{self.lang.lblDesiredRes}","{self.camRatio}"\n'
            f'"{self.lang.lblRes}","{self.camWidth}","x","{self.camHeight}"\n'
            f'"{self.lang.lblHeight}","{self.flightHeight}"\n'
            f'"{self.lang.lblFocal}","{self.focalLength}"\n\n'
            f'"{self.lang.repMeridianPoints}"\n' + pointHeader +
            self.pointsMeridian + f'\n"{self.lang.repHorizontalPoints}"\n' +
            pointHeader + self.pointsHorizontal)

        # Save image
        self.__disableItems()
        file = QFileDialog.getSaveFileName(self, self.lang.saveFile, "",
                                           self.lang.vectorImage +
                                           " (*.svg)")[0]
        if file == "":
            self.__enableItems()
            return

        # And choose where to save report
        reportName = ""
        while reportName == "":
            reportName = QFileDialog.getSaveFileName(
                self, self.lang.saveFile, "", self.lang.table + " (*.csv)")[0]
            if reportName == "":
                msg = QMessageBox()
                msg.setIcon(QMessageBox.Warning)
                msg.setText(self.lang.errSaveBoth)
                msg.exec_()

        rect = self.scene.sceneRect()
        gen = QSvgGenerator()
        gen.setFileName(file)
        gen.setSize(rect.size().toSize())
        gen.setViewBox(rect)
        gen.setTitle("Flight paths generated by AerialWare")
        gen.setDescription(gen.title())

        # Notice: painting will temporarily freeze application because QGraphicsScene::render is not thread safe.
        # Don't try putting this into python's threads and QThread, doesn't work, I've tried, trust me XD
        painter = QPainter(gen)
        self.scene.render(painter)
        painter.end()

        # Save report
        reportFile = open(reportName, "w")
        reportFile.write(report)
        reportFile.close()

        self.__enableItems()
コード例 #22
0
ファイル: jef2svg.py プロジェクト: lzh6710/view-jef
    stitches_only = "--stitches-only" in sys.argv
    if stitches_only:
        sys.argv.remove("--stitches-only")

    jef_file = sys.argv[1]
    svg_file = sys.argv[2]

    app = QApplication(sys.argv)
    svg = QSvgGenerator()
    svg.setFileName(svg_file)

    if QT_VERSION >= (4, 5, 0):
        svg.setDescription('Original JEF file "' + os.path.split(jef_file)[1] +
                           '" converted '
                           'to ' + os.path.split(svg_file)[1] +
                           ' by jef2svg.py.')

    convertor = Convertor(jef_file, stitches_only)
    rect = convertor.bounding_rect()
    if QT_VERSION >= (4, 5, 0):
        svg.setViewBox(rect)
    svg.setSize(rect.size())

    painter = QPainter()
    painter.begin(svg)
    convertor.show(painter)
    painter.end()

    sys.exit()
コード例 #23
0
def export_to_svg(self: Widget, filename: str):
    generator = QSvgGenerator()
    generator.setFileName(self.path)
    generator.setSize(QSize(*self.size))
    generator.setViewBox(self.rect())
    self.render(generator)