Newer
Older
from PyQt5 import QtSvg
from PyQt5.QtCore import Qt, QByteArray
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QGridLayout, QWidget
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flatland.utils import svg
# Subclass QMainWindow to customise your application's main window
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("My Awesome App")
layout = QGridLayout()
layout.setSpacing(0)
wMain = QWidget(self)
wMain.setLayout(layout)
label = QLabel("This is a PyQt5 window!")
# The `Qt` namespace has a lot of attributes to customise
# widgets. See: http://doc.qt.io/qt-5/qt.html
label.setAlignment(Qt.AlignCenter)
layout.addWidget(label, 0, 0)
svgWidget = QtSvg.QSvgWidget("./svg/Gleis_vertikal.svg")
layout.addWidget(svgWidget, 1, 0)
if True:
track = svg.Track()
svgWidget = None
iRow = 0
iCol = 2
iArt = 0
nCols = 3
for binTrans in list(track.dSvg.keys())[:2]:
sSVG = track.dSvg[binTrans].to_string()
bySVG = bytearray(sSVG, encoding='utf-8')
# with open(sfPath, "r") as fIn:
# sSVG = fIn.read()
# bySVG = bytearray(sSVG, encoding='utf-8')
svgWidget = QtSvg.QSvgWidget()
oQB = QByteArray(bySVG)
bSuccess = svgWidget.renderer().load(oQB)
# print(x0, y0, x1, y1)
print(iRow, iCol, bSuccess)
print("\n\n\n", bySVG.decode("utf-8"))
# svgWidget.setGeometry(x0, y0, x1, y1)
layout.addWidget(svgWidget, iRow, iCol)
iArt += 1
iRow = int(iArt / nCols)
iCol = iArt % nCols
# Set the central widget of the Window. Widget will expand
# to take up all the space in the window by default.
self.setCentralWidget(wMain)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()