from functools import cmp_to_key
def compare(a, b):
""" здесь определяем функцию сравнения """
ves = {'абсолютно':3, 'нет':4, 'да':2, 'не знаю':1} # задаем произвольные веса
return ves[a] - ves[b]
l = ['не знаю', 'абсолютно', 'нет', 'абсолютно', 'не знаю', 'абсолютно', 'да',
'не знаю', 'абсолютно', 'да', 'не знаю', 'нет', 'абсолютно', 'нет', 'да']
print(sorted(l, key=cmp_to_key(compare)))
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGridLayout, QSlider, QWidget
from PyQt5.QtSvg import QSvgWidget
# потом <g transform="rotate({} 149 239)"> вместо {} подставляем поворот svg_str.format('угол')
svg_str = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
height="91.542259mm"
width="97.583565mm"
viewBox="0 0 345.76854 324.36233"
id="svg2"
version="1.1">
<title
id="title3261">Gauge</title>
<defs
id="defs8" />
<path
id="path3188"
d="m 1.5674094,1.5674094 0,321.2275206 342.6337206,0 0,-321.2275206 z"
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:3.13481879px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:#e6e6e6;fill-rule:evenodd;stroke:#000000;stroke-width:2.87002802px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 17.627149,15.603129 0,295.180101 312.538261,0 0,-295.180101 z"
id="path3144" />
<path
style="fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:1.06737363px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 32.917959,40.123219 0,250.703341 279.932621,0 0,-250.703341 z"
id="path3146" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 172.88427,90.860249 0,40.000001"
id="path3150" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 218.06065,97.541729 207.70789,136.17877"
id="path3152" />
<path
id="path3154"
d="m 129.70789,97.541729 10.35276,38.637041"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 84.884269,109.53974 20.000001,34.64102"
id="path3156" />
<path
id="path3158"
d="m 266.88427,109.53974 -20,34.64102"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
id="path3160"
d="m 35.563759,142.86025 34.64102,20"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 312.20478,142.86025 -34.64102,20"
id="path3162" />
<g transform="rotate({} 173.61934 247.5)">
<path
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 173.61934,116.6183 -12.54984,107.9375 11.8878,22.06081 12.11189,-21.93859 z"
id="path3164" />
</g>
<g
style="font-style:normal;font-weight:normal;font-size:30px;line-height:125%;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text3190">
<path
d="m 59.275742,96.637955 7.895507,0 0,2.402343 -7.895507,0 0,-2.402343 z"
style=""
id="path3185" />
<path
d="m 71.888046,84.186783 11.616211,0 0,2.490234 -8.90625,0 0,5.361328 q 0.644531,-0.219726 1.289063,-0.322265 0.644531,-0.117188 1.289062,-0.117188 3.66211,0 5.800781,2.006836 2.138672,2.006836 2.138672,5.43457 0,3.530272 -2.197265,5.493162 -2.197266,1.94824 -6.196289,1.94824 -1.376953,0 -2.8125,-0.23437 -1.420899,-0.23438 -2.944336,-0.70313 l 0,-2.97363 q 1.318359,0.71778 2.724609,1.06934 1.40625,0.35156 2.973633,0.35156 2.53418,0 4.013672,-1.33301 1.479492,-1.33301 1.479492,-3.618162 0,-2.285156 -1.479492,-3.618164 -1.479492,-1.333007 -4.013672,-1.333007 -1.186524,0 -2.373047,0.263671 -1.171875,0.263672 -2.402344,0.820313 l 0,-10.986328 z"
style=""
id="path3187" />
</g>
<g
style="font-style:normal;font-weight:normal;font-size:30px;line-height:125%;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text3194">
<path
d="m 260.4613,87.248306 0,8.15918 8.15918,0 0,2.490234 -8.15918,0 0,8.15918 -2.46093,0 0,-8.15918 -8.15918,0 0,-2.490234 8.15918,0 0,-8.15918 2.46093,0 z"
style=""
id="path3177" />
<path
d="m 275.0365,84.186783 11.61621,0 0,2.490234 -8.90625,0 0,5.361328 q 0.64453,-0.219726 1.28906,-0.322265 0.64453,-0.117188 1.28906,-0.117188 3.66211,0 5.80079,2.006836 2.13867,2.006836 2.13867,5.43457 0,3.530272 -2.19727,5.493162 -2.19726,1.94824 -6.19629,1.94824 -1.37695,0 -2.8125,-0.23437 -1.4209,-0.23438 -2.94433,-0.70313 l 0,-2.97363 q 1.31836,0.71778 2.72461,1.06934 1.40625,0.35156 2.97363,0.35156 2.53418,0 4.01367,-1.33301 1.47949,-1.33301 1.47949,-3.618162 0,-2.285156 -1.47949,-3.618164 -1.47949,-1.333007 -4.01367,-1.333007 -1.18652,0 -2.37305,0.263671 -1.17187,0.263672 -2.40234,0.820313 l 0,-10.986328 z"
style=""
id="path3179" />
</g>
<g
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:30px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text3198">
<path
d="m 120.47536,247.30896 5.66894,0 5.80078,16.14258 5.78614,-16.14258 5.66894,0 -8.10058,21.87012 -6.72364,0 -8.10058,-21.87012 z"
style=""
id="path3166" />
<path
d="m 155.74879,251.00037 q -2.57812,0 -3.99902,1.90429 -1.4209,1.9043 -1.4209,5.36133 0,3.44238 1.4209,5.34668 1.4209,1.9043 3.99902,1.9043 2.59278,0 4.01368,-1.9043 1.42089,-1.9043 1.42089,-5.34668 0,-3.45703 -1.42089,-5.36133 -1.4209,-1.90429 -4.01368,-1.90429 z m 0,-4.08692 q 5.27344,0 8.26172,3.01758 2.98828,3.01758 2.98828,8.33496 0,5.30274 -2.98828,8.32031 -2.98828,3.01758 -8.26172,3.01758 -5.25878,0 -8.26171,-3.01758 -2.98829,-3.01757 -2.98829,-8.32031 0,-5.31738 2.98829,-8.33496 3.00293,-3.01758 8.26171,-3.01758 z"
style=""
id="path3168" />
<path
d="m 171.24684,247.30896 5.63965,0 0,17.60742 9.90234,0 0,4.2627 -15.54199,0 0,-21.87012 z"
style=""
id="path3170" />
<path
d="m 182.76051,247.30896 20.15625,0 0,4.2627 -7.25097,0 0,17.60742 -5.63965,0 0,-17.60742 -7.26563,0 0,-4.2627 z"
style=""
id="path3172" />
<path
d="m 221.03688,247.99744 0,4.6289 q -1.80176,-0.80566 -3.51562,-1.21582 -1.71387,-0.41015 -3.23731,-0.41015 -2.02148,0 -2.98828,0.55664 -0.9668,0.55664 -0.9668,1.72851 0,0.87891 0.64453,1.37696 0.65918,0.48339 2.37305,0.83496 l 2.40234,0.48339 q 3.64747,0.73243 5.18555,2.22657 1.53809,1.49414 1.53809,4.24804 0,3.61817 -2.15332,5.39063 -2.13867,1.75781 -6.54785,1.75781 -2.08008,0 -4.17481,-0.39551 -2.09473,-0.3955 -4.18945,-1.17187 l 0,-4.76074 q 2.09472,1.11328 4.04297,1.68457 1.96289,0.55664 3.77929,0.55664 1.84571,0 2.82715,-0.61524 0.98145,-0.61523 0.98145,-1.75781 0,-1.02539 -0.67383,-1.58203 -0.65918,-0.55664 -2.65137,-0.99609 l -2.18262,-0.4834 q -3.28125,-0.70313 -4.80468,-2.24121 -1.50879,-1.53809 -1.50879,-4.14551 0,-3.2666 2.10937,-5.02442 2.10938,-1.75781 6.06446,-1.75781 1.80175,0 3.70605,0.27832 1.9043,0.26367 3.94043,0.80567 z"
style=""
id="path3174" />
</g>
<g
style="font-style:normal;font-weight:normal;font-size:45px;line-height:125%;font-family:sans-serif;text-align:center;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text3221">
<path
d="m 172.88426,51.693741 q -3.42773,0 -5.16357,3.383789 -1.71387,3.361816 -1.71387,10.129394 0,6.745606 1.71387,10.129395 1.73584,3.361816 5.16357,3.361816 3.44971,0 5.16358,-3.361816 1.73584,-3.383789 1.73584,-10.129395 0,-6.767578 -1.73584,-10.129394 -1.71387,-3.383789 -5.16358,-3.383789 z m 0,-3.515625 q 5.51514,0 8.41553,4.372558 2.92236,4.350586 2.92236,12.65625 0,8.283692 -2.92236,12.65625 -2.90039,4.350586 -8.41553,4.350586 -5.51513,0 -8.4375,-4.350586 -2.90039,-4.372558 -2.90039,-12.65625 0,-8.305664 2.90039,-12.65625 2.92237,-4.372558 8.4375,-4.372558 z"
style=""
id="path3182" />
</g>
</svg>
"""
app = QApplication(sys.argv)
layout = QGridLayout()
widget = QWidget()
widget.setLayout(layout)
svgWidget = QSvgWidget()
svg_bytes = bytearray(svg_str.format('0'), encoding='utf-8')
svgWidget.renderer().load(svg_bytes)
svgWidget.setGeometry(100,100,300,300)
layout.addWidget(svgWidget)
slider = QSlider(Qt.Horizontal)
slider.setRange(-50, 50)
def updateSVG(value):
""" Обновляет SVG при движении слайдера"""
svg_bytes = bytearray(svg_str.format(str(value)), encoding='utf-8')
svgWidget.renderer().load(svg_bytes)
slider.valueChanged.connect(updateSVG)
layout.addWidget(slider)
widget.show()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QGridLayout, QWidget
from PyQt5.QtSvg import QSvgWidget
svg_str = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="300" height="300" viewBox="0 0 300 300" id="smile" version="1.1">
<path
style="fill:#ffaaaa"
d="M 150,0 A 150,150 0 0 0 0,150 150,150 0 0 0 150,300 150,150 0 0 0
300,150 150,150 0 0 0 150,0 Z M 72,65 A 21,29.5 0 0 1 93,94.33
21,29.5 0 0 1 72,124 21,29.5 0 0 1 51,94.33 21,29.5 0 0 1 72,65 Z
m 156,0 a 21,29.5 0 0 1 21,29.5 21,29.5 0 0 1 -21,29.5 21,29.5 0 0 1
-21,-29.5 21,29.5 0 0 1 21,-29.5 z m -158.75,89.5 161.5,0 c 0,44.67
-36.125,80.75 -80.75,80.75 -44.67,0 -80.75,-36.125 -80.75,-80.75 z"
/>
</svg>
"""
svg_bytes = bytearray(svg_str, encoding='utf-8')
svg_str_2 = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="300" height="300" viewBox="0 0 300 300" id="smile" version="1.1">
<g transform="rotate(50 150 150)"><path
style="fill:#ffaaaa"
d="M 150,0 A 150,150 0 0 0 0,150 150,150 0 0 0 150,300 150,150 0 0 0
300,150 150,150 0 0 0 150,0 Z M 72,65 A 21,29.5 0 0 1 93,94.33
21,29.5 0 0 1 72,124 21,29.5 0 0 1 51,94.33 21,29.5 0 0 1 72,65 Z
m 156,0 a 21,29.5 0 0 1 21,29.5 21,29.5 0 0 1 -21,29.5 21,29.5 0 0 1
-21,-29.5 21,29.5 0 0 1 21,-29.5 z m -158.75,89.5 161.5,0 c 0,44.67
-36.125,80.75 -80.75,80.75 -44.67,0 -80.75,-36.125 -80.75,-80.75 z"
/></g>
</svg>
"""
svg_bytes_2 = bytearray(svg_str_2, encoding='utf-8')
app = QApplication(sys.argv)
layout = QGridLayout()
widget = QWidget()
widget.setLayout(layout)
svgWidget = QSvgWidget()
svgWidget.renderer().load(svg_bytes)
svgWidget.setGeometry(100,100,300,300)
layout.addWidget(svgWidget)
def Repaint():
print("Repaint!")
svgWidget.renderer().load(svg_bytes_2)
pushButton = QPushButton("Repaint")
pushButton.clicked.connect(Repaint)
layout.addWidget(pushButton)
widget.show()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSvg import QSvgWidget
svg_str = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="300" height="300" viewBox="0 0 300 300" id="smile" version="1.1">
<path
style="fill:#ffaaaa"
d="M 150,0 A 150,150 0 0 0 0,150 150,150 0 0 0 150,300 150,150 0 0 0
300,150 150,150 0 0 0 150,0 Z M 72,65 A 21,29.5 0 0 1 93,94.33
21,29.5 0 0 1 72,124 21,29.5 0 0 1 51,94.33 21,29.5 0 0 1 72,65 Z
m 156,0 a 21,29.5 0 0 1 21,29.5 21,29.5 0 0 1 -21,29.5 21,29.5 0 0 1
-21,-29.5 21,29.5 0 0 1 21,-29.5 z m -158.75,89.5 161.5,0 c 0,44.67
-36.125,80.75 -80.75,80.75 -44.67,0 -80.75,-36.125 -80.75,-80.75 z"
/>
</svg>
"""
svg_bytes = bytearray(svg_str, encoding='utf-8')
app = QApplication(sys.argv)
svgWidget = QSvgWidget()
svgWidget.renderer().load(svg_bytes)
svgWidget.setGeometry(100,100,300,300)
svgWidget.show()
sys.exit(app.exec_())