Пример #1
0
 def export_to_svg(self, filename: Path) -> bool:
     generator = QSvgGenerator()
     generator.setFileName(str(filename))
     generator.setSize(self.size())
     generator.setViewBox(self.rect())
     self.render(generator)
     return True
Пример #2
0
    def testRefCountOfTOutputDevice(self):
        generator = QSvgGenerator()
        iodevice1 = QBuffer()
        refcount1 = getrefcount(iodevice1)

        generator.setOutputDevice(iodevice1)

        self.assertEqual(generator.outputDevice(), iodevice1)
        self.assertEqual(getrefcount(generator.outputDevice()), refcount1 + 1)

        iodevice2 = QBuffer()
        refcount2 = getrefcount(iodevice2)

        generator.setOutputDevice(iodevice2)

        self.assertEqual(generator.outputDevice(), iodevice2)
        self.assertEqual(getrefcount(generator.outputDevice()), refcount2 + 1)
        self.assertEqual(getrefcount(iodevice1), refcount1)

        del generator

        self.assertEqual(getrefcount(iodevice2), refcount2)
Пример #3
0
    def testRefCountOfTOutputDevice(self):
        generator = QSvgGenerator()
        iodevice1 = QBuffer()
        refcount1 = getrefcount(iodevice1)

        generator.setOutputDevice(iodevice1)

        self.assertEqual(generator.outputDevice(), iodevice1)
        self.assertEqual(getrefcount(generator.outputDevice()), refcount1 + 1)

        iodevice2 = QBuffer()
        refcount2 = getrefcount(iodevice2)

        generator.setOutputDevice(iodevice2)

        self.assertEqual(generator.outputDevice(), iodevice2)
        self.assertEqual(getrefcount(generator.outputDevice()), refcount2 + 1)
        self.assertEqual(getrefcount(iodevice1), refcount1)

        del generator

        self.assertEqual(getrefcount(iodevice2), refcount2)
Пример #4
0
    def _init_font_interface(cls):
        '''
        static init interface, font family and font size have to be
        set first. This function does not have to be called.
        '''

        # should move to main
        # workaround
        if cls._app is None:
            try:
                cls._app = QApplication(sys.argv)
            except RuntimeError:
                cls._app = False

        if (cls.font_size is not None and cls.font_family is not None):
            cls.font = QFont(cls.font_family, cls.font_size)
            cls.font_metrics = QFontMetricsF(cls.font, QSvgGenerator())
 def from_scene(cls, scene):
     buffer = QBuffer()
     generator = QSvgGenerator()
     generator.setOutputDevice(buffer)
     scene_rect = scene.sceneRect()
     generator.setViewBox(scene_rect)
     painter = QPainter(generator)
     scene.render(painter, scene_rect, scene_rect)
     painter.end()
     buffer.open(QBuffer.ReadOnly)
     renderer = cls(buffer.readAll())
     buffer.close()
     renderer.scene = scene
     return renderer
Пример #6
0
    def export(self, filename, w=1920, h=1080):
        """
        Save the grid to a png file
        """

        name, extension = os.path.splitext(filename.lower())

        if extension == '.png':
            image = QImage(w, h, QImage.Format_ARGB32_Premultiplied)
            image.fill(Qt.transparent)
            painter = QPainter(image)
            painter.setRenderHint(QPainter.Antialiasing)
            self.diagramScene.render(painter)
            image.save(filename)
            painter.end()

        elif extension == '.svg':
            svg_gen = QSvgGenerator()
            svg_gen.setFileName(filename)
            svg_gen.setSize(QSize(w, h))
            svg_gen.setViewBox(QRect(0, 0, w, h))
            svg_gen.setTitle("Electrical grid schematic")
            svg_gen.setDescription("An SVG drawing created by GridCal")

            painter = QPainter(svg_gen)
            self.diagramScene.render(painter)
            painter.end()
        else:
            raise Exception('Extension ' + str(extension) + ' not supported :(')