python svg viewing

Solutions on MaxInterview for python svg viewing by the best coders in the world

showing results for - "python svg viewing"
Valentino
04 Jan 2019
1import sys
2
3from PySide2 import QtCore, QtGui, QtWidgets
4from PySide2.QtNetwork import QNetworkProxy, QNetworkProxyFactory
5from PySide2.QtWebEngineWidgets import QWebEngineView
6
7
8class DisplaySVG(QtWidgets.QWidget):
9    "A simple SVG display."
10    def __init__(self, url=None, parent=None):
11        super().__init__(parent)
12        self.resize(800,600)
13        self.verticalLayout = QtWidgets.QVBoxLayout(self)
14        self.webview = QWebEngineView(self)
15        self.verticalLayout.addWidget(self.webview)
16
17        self.setWindowTitle("Display SVG")
18        act = QtWidgets.QAction("Close", self)
19        act.setShortcuts([QtGui.QKeySequence(QtCore.Qt.Key_Escape)])
20        act.triggered.connect(self.close)
21        self.addAction(act)
22
23        svg = '''
24<?xml version="1.0" encoding="UTF-8" standalone="no"?>
25<!-- Created with Inkscape (http://www.inkscape.org/) -->
26
27<svg
28   xmlns:dc="http://purl.org/dc/elements/1.1/"
29   xmlns:cc="http://creativecommons.org/ns#"
30   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
31   xmlns:svg="http://www.w3.org/2000/svg"
32   xmlns="http://www.w3.org/2000/svg"
33   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
34   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
35   width="210mm"
36   height="297mm"
37   viewBox="0 0 210 297"
38   version="1.1"
39   id="svg8"
40   inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
41   sodipodi:docname="drawing.svg">
42  <defs
43     id="defs2">
44    <filter
45       style="color-interpolation-filters:sRGB;"
46       inkscape:label="Blur"
47       id="filter4530">
48      <feGaussianBlur
49         stdDeviation="3.48559 2"
50         result="fbSourceGraphic"
51         id="feGaussianBlur4528" />
52      <feColorMatrix
53         result="fbSourceGraphicAlpha"
54         in="fbSourceGraphic"
55         values="0 0 0 -1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 1 0"
56         id="feColorMatrix4532" />
57      <feGaussianBlur
58         id="feGaussianBlur4534"
59         stdDeviation="3.49 2"
60         result="blur"
61         in="fbSourceGraphic" />
62    </filter>
63  </defs>
64  <sodipodi:namedview
65     id="base"
66     pagecolor="#ffffff"
67     bordercolor="#666666"
68     borderopacity="1.0"
69     inkscape:pageopacity="0.0"
70     inkscape:pageshadow="2"
71     inkscape:zoom="0.7"
72     inkscape:cx="214.06823"
73     inkscape:cy="366.85869"
74     inkscape:document-units="mm"
75     inkscape:current-layer="layer1"
76     showgrid="false"
77     inkscape:window-width="1487"
78     inkscape:window-height="958"
79     inkscape:window-x="58"
80     inkscape:window-y="85"
81     inkscape:window-maximized="0" />
82  <metadata
83     id="metadata5">
84    <rdf:RDF>
85      <cc:Work
86         rdf:about="">
87        <dc:format>image/svg+xml</dc:format>
88        <dc:type
89           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
90        <dc:title></dc:title>
91      </cc:Work>
92    </rdf:RDF>
93  </metadata>
94  <g
95     inkscape:label="Layer 1"
96     inkscape:groupmode="layer"
97     id="layer1">
98    <circle
99       style="opacity:1;fill:#ff5555;fill-opacity:0.57480317;stroke:#2c2cff;stroke-width:1.882;stroke-miterlimit:4;stroke-dasharray:3.764, 1.88199999999999990;stroke-dashoffset:0;stroke-opacity:1;filter:url(#filter4530)"
100       id="path4518"
101       cx="66.523811"
102       cy="123.13095"
103       r="36.285713" />
104  </g>
105</svg>
106        '''
107
108        self.webview.setHtml(svg)
109
110qt_app = QtWidgets.QApplication(sys.argv)
111disp = DisplaySVG()
112disp.show()
113qt_app.exec_()
114
similar questions
queries leading to this page
python svg viewing