-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XASY: Add support for custom svg converter path.
- Loading branch information
Showing
2 changed files
with
39 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
import platform | ||
|
||
import PyQt5.QtGui as QtGui | ||
import PyQt5.QtWidgets as QtWidgets | ||
import io | ||
import subprocess | ||
import sys | ||
from xasygui import xasyOptions as xo | ||
|
||
class SvgObject(): | ||
|
||
class SvgObject: | ||
def __init__(self, file: str): | ||
self.file=file | ||
self.file = file | ||
|
||
def _create_call_arguments(self, dpi: int): | ||
settings = xo.BasicConfigs.defaultOpt | ||
return [ | ||
settings.get("svgConverterPath") or "rsvg-convert", | ||
f"--dpi-x={dpi}", | ||
f"--dpi-y={dpi}", | ||
"--format=png", | ||
self.file, | ||
] | ||
|
||
def render(self, dpi:int) -> QtGui.QImage: | ||
def render(self, dpi: int) -> QtGui.QImage: | ||
callArgs = self._create_call_arguments(dpi) | ||
try: | ||
rawDataProc = subprocess.Popen(['rsvg-convert', '--dpi-x', str(dpi), | ||
'--dpi-y', str(dpi), self.file], | ||
stdout=subprocess.PIPE) | ||
except: | ||
QtWidgets.QMessageBox.about(None,'rsvg-convert missing','Please install rsvg-convert version >= 2.40 in your path.') | ||
rawDataProc = subprocess.run( | ||
callArgs, | ||
stdout=subprocess.PIPE, | ||
) | ||
except OSError: | ||
QtWidgets.QMessageBox.about( | ||
None, | ||
"SVG Converter missing", | ||
"Please ensure svg converter is available.", | ||
) | ||
sys.exit(-1) | ||
|
||
return QtGui.QImage.fromData(rawDataProc.stdout.read(), 'PNG') | ||
return QtGui.QImage.fromData(rawDataProc.stdout, "PNG") |