From dec5b616f6ef215d415686e8ac3c0eeca6550ad5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 5 Aug 2024 15:43:24 +0200 Subject: Python-QML integration tutorial: Streamline Python code In the emphasized lines, fix an offset introduced by 50061290756323ff339bd0473e67117c8191d130. Pick-to: 6.7 Task-number: PYSIDE-2833 Change-Id: I4ea1eb6b520179c0d425bdb74eaae7663ce89125 Reviewed-by: Shyamnath Premnadh --- .../pyside6/doc/tutorials/qmlintegration/main.py | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'sources/pyside6/doc/tutorials/qmlintegration/main.py') diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py index 6e7897acd..b6c35c562 100644 --- a/sources/pyside6/doc/tutorials/qmlintegration/main.py +++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py @@ -10,7 +10,7 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6.QtQuickControls2 import QQuickStyle -import style_rc +import style_rc # noqa F401 # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) @@ -25,41 +25,28 @@ class Bridge(QObject): def getColor(self, s): if s.lower() == "red": return "#ef9a9a" - elif s.lower() == "green": + if s.lower() == "green": return "#a5d6a7" - elif s.lower() == "blue": + if s.lower() == "blue": return "#90caf9" - else: - return "white" + return "white" @Slot(float, result=int) def getSize(self, s): size = int(s * 34) - if size <= 0: - return 1 - else: - return size + return max(1, size) @Slot(str, result=bool) def getItalic(self, s): - if s.lower() == "italic": - return True - else: - return False + return s.lower() == "italic" @Slot(str, result=bool) def getBold(self, s): - if s.lower() == "bold": - return True - else: - return False + return s.lower() == "bold" @Slot(str, result=bool) def getUnderline(self, s): - if s.lower() == "underline": - return True - else: - return False + return s.lower() == "underline" if __name__ == '__main__': @@ -75,4 +62,6 @@ if __name__ == '__main__': if not engine.rootObjects(): sys.exit(-1) - sys.exit(app.exec()) + ex = app.exec() + del engine + sys.exit(ex) -- cgit v1.2.3