summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/GUI/xasySvg.py
blob: a5325f9bdd6fdc62c62fb2aa74e91b289d9b77df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3

import PyQt5.QtGui as Qg
import PyQt5.QtWidgets as Qw
import io
import subprocess
import sys

class SvgObject():
    def __init__(self, file: str):
        self.file=file

    def render(self, dpi:int) -> Qg.QImage:
        try:
            rawDataProc = subprocess.Popen(['rsvg-convert', '--dpi-x', str(dpi),
                                            '--dpi-y', str(dpi), self.file],
                                           stdout=subprocess.PIPE)
        except:
            Qw.QMessageBox.about(None,'rsvg-convert missing','Please install rsvg-convert version >= 2.40 in your path.')
            sys.exit(-1)

        return Qg.QImage.fromData(rawDataProc.stdout.read(), 'PNG')