diff options
Diffstat (limited to 'examples/declarative')
10 files changed, 40 insertions, 20 deletions
diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py index 9cbead9cc..db508d297 100644 --- a/examples/declarative/extending/chapter1-basics/basics.py +++ b/examples/declarative/extending/chapter1-basics/basics.py @@ -50,11 +50,12 @@ from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickPaintedItem, QQuickView + class PieChart (QQuickPaintedItem): nameChanged = Signal() - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._name = u'' self._color = QColor() @@ -63,7 +64,7 @@ class PieChart (QQuickPaintedItem): pen = QPen(self.color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16) + painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16) @Property(QColor) def color(self): diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index a37376ca8..c0fd0050a 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -50,12 +50,13 @@ from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickPaintedItem, QQuickView -class PieChart (QQuickPaintedItem): + +class PieChart(QQuickPaintedItem): chartCleared = Signal() nameChanged = Signal() - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._name = u'' self._color = QColor() @@ -64,7 +65,7 @@ class PieChart (QQuickPaintedItem): pen = QPen(self.color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16) + painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16) @Property(QColor) def color(self): @@ -82,12 +83,13 @@ class PieChart (QQuickPaintedItem): def name(self, value): self._name = value - @Slot() # This should be something like @Invokable + @Slot() # This should be something like @Invokable def clearChart(self): self.color = Qt.transparent self.update() self.chartCleared.emit() + if __name__ == '__main__': app = QGuiApplication(sys.argv) diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py index d19df7f24..3bb70dbab 100644 --- a/examples/declarative/extending/chapter3-bindings/bindings.py +++ b/examples/declarative/extending/chapter3-bindings/bindings.py @@ -50,13 +50,14 @@ from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickPaintedItem, QQuickView + class PieChart (QQuickPaintedItem): chartCleared = Signal() nameChanged = Signal() colorChanged = Signal() - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._name = u'' self._color = QColor() @@ -65,7 +66,7 @@ class PieChart (QQuickPaintedItem): pen = QPen(self._color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16) + painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16) @Property(QColor, notify=colorChanged) def color(self): @@ -86,12 +87,13 @@ class PieChart (QQuickPaintedItem): def name(self, value): self._name = value - @Slot() # This should be something like @Invokable + @Slot() # This should be something like @Invokable def clearChart(self): self.color = Qt.transparent self.update() self.chartCleared.emit() + if __name__ == '__main__': app = QGuiApplication(sys.argv) diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index 1bf9387f5..0cd8feb61 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -50,9 +50,10 @@ from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem + class PieSlice (QQuickPaintedItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._color = QColor() @@ -68,10 +69,11 @@ class PieSlice (QQuickPaintedItem): pen = QPen(self._color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16) + painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16) + class PieChart (QQuickItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickItem.__init__(self, parent) self._name = None self._pieSlice = None @@ -93,6 +95,7 @@ class PieChart (QQuickItem): self._pieSlice = value self._pieSlice.setParentItem(self) + if __name__ == '__main__': app = QGuiApplication(sys.argv) diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index 646a14458..4f24a3a87 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -50,8 +50,9 @@ from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType, ListProperty from PySide6.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem + class PieSlice (QQuickPaintedItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) self._color = QColor() self._fromAngle = 0 @@ -85,10 +86,11 @@ class PieSlice (QQuickPaintedItem): pen = QPen(self._color, 2) painter.setPen(pen) painter.setRenderHints(QPainter.Antialiasing, True) - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), self._fromAngle * 16, self._angleSpan * 16) + painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), self._fromAngle * 16, self._angleSpan * 16) + class PieChart (QQuickItem): - def __init__(self, parent = None): + def __init__(self, parent=None): QQuickItem.__init__(self, parent) self._name = u'' self._slices = [] @@ -107,6 +109,7 @@ class PieChart (QQuickItem): slices = ListProperty(PieSlice, appendSlice) + if __name__ == '__main__': app = QGuiApplication(sys.argv) diff --git a/examples/declarative/signals/qmltopy1/main.py b/examples/declarative/signals/qmltopy1/main.py index 69f9e2f80..3c0ebbeaa 100644 --- a/examples/declarative/signals/qmltopy1/main.py +++ b/examples/declarative/signals/qmltopy1/main.py @@ -46,6 +46,7 @@ from PySide6.QtCore import QObject, QUrl, Slot from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView + class Console(QObject): """Output stuff on the console.""" diff --git a/examples/declarative/signals/qmltopy2/main.py b/examples/declarative/signals/qmltopy2/main.py index 4df632292..d5cb260a0 100644 --- a/examples/declarative/signals/qmltopy2/main.py +++ b/examples/declarative/signals/qmltopy2/main.py @@ -46,6 +46,7 @@ from PySide6.QtCore import QObject, QUrl, Slot from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView + class RotateValue(QObject): def __init__(self): super().__init__() @@ -58,6 +59,7 @@ class RotateValue(QObject): self.r = self.r + 10 return self.r + if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() diff --git a/examples/declarative/signals/qmltopy3/main.py b/examples/declarative/signals/qmltopy3/main.py index d28121c8f..e1a4672a8 100644 --- a/examples/declarative/signals/qmltopy3/main.py +++ b/examples/declarative/signals/qmltopy3/main.py @@ -46,9 +46,11 @@ from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView + def sayThis(s): print(s) + if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() diff --git a/examples/declarative/signals/qmltopy4/main.py b/examples/declarative/signals/qmltopy4/main.py index 2cc6920d3..4e58350fb 100644 --- a/examples/declarative/signals/qmltopy4/main.py +++ b/examples/declarative/signals/qmltopy4/main.py @@ -46,9 +46,11 @@ from PySide6.QtCore import QObject, QUrl from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView + def sayThis(s): print(s) + if __name__ == '__main__': app = QGuiApplication(sys.argv) view = QQuickView() diff --git a/examples/declarative/usingmodel/usingmodel.py b/examples/declarative/usingmodel/usingmodel.py index 7c54cc49e..4dcb8279e 100644 --- a/examples/declarative/usingmodel/usingmodel.py +++ b/examples/declarative/usingmodel/usingmodel.py @@ -46,17 +46,18 @@ from PySide6.QtCore import QAbstractListModel, Qt, QUrl, QByteArray from PySide6.QtGui import QGuiApplication from PySide6.QtQuick import QQuickView + class PersonModel (QAbstractListModel): MyRole = Qt.UserRole + 1 - def __init__(self, parent = None): + def __init__(self, parent=None): QAbstractListModel.__init__(self, parent) self._data = [] def roleNames(self): roles = { - PersonModel.MyRole : QByteArray(b'modelData'), - Qt.DisplayRole : QByteArray(b'display') + PersonModel.MyRole: QByteArray(b'modelData'), + Qt.DisplayRole: QByteArray(b'display') } return roles @@ -75,8 +76,9 @@ class PersonModel (QAbstractListModel): return None def populate(self): - self._data.append({'name':'Qt', 'myrole':'role1'}) - self._data.append({'name':'PySide', 'myrole':'role2'}) + self._data.append({'name': 'Qt', 'myrole': 'role1'}) + self._data.append({'name': 'PySide', 'myrole': 'role2'}) + if __name__ == '__main__': app = QGuiApplication(sys.argv) |