aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/animation/easing/easing.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/animation/easing/easing.py')
-rw-r--r--examples/widgets/animation/easing/easing.py37
1 files changed, 14 insertions, 23 deletions
diff --git a/examples/widgets/animation/easing/easing.py b/examples/widgets/animation/easing/easing.py
index 58341c0cf..ba5032458 100644
--- a/examples/widgets/animation/easing/easing.py
+++ b/examples/widgets/animation/easing/easing.py
@@ -8,10 +8,10 @@ import sys
from PySide6.QtCore import (Property, QEasingCurve, QObject, QPropertyAnimation,
QPoint, QPointF, QRect, QRectF, QSize, Qt)
from PySide6.QtGui import (QBrush, QColor, QIcon, QLinearGradient, QPainter,
- QPainterPath, QPen, QPixmap)
+ QPainterPath, QPixmap)
from PySide6.QtWidgets import (QApplication, QGraphicsPixmapItem,
- QGraphicsItem, QGraphicsScene, QGraphicsView,
- QListWidget, QListWidgetItem, QWidget)
+ QGraphicsItem, QGraphicsScene,
+ QListWidgetItem, QWidget)
from ui_form import Ui_Form
@@ -110,7 +110,7 @@ class Window(QWidget):
self._anim = Animation(self._item, b'pos')
self._anim.setEasingCurve(QEasingCurve.OutBounce)
- self._ui.easingCurvePicker.setCurrentRow(int(QEasingCurve.OutBounce))
+ self._ui.easingCurvePicker.setCurrentRow(0)
self.start_animation()
@@ -123,15 +123,7 @@ class Window(QWidget):
brush = QBrush(gradient)
- # The original C++ code uses undocumented calls to get the names of the
- # different curve types. We do the Python equivalant (but without
- # cheating)
- curve_types = [(n, c) for n, c in QEasingCurve.__dict__.items()
- if (isinstance(c, QEasingCurve.Type)
- and c != QEasingCurve.Custom
- and c != QEasingCurve.NCurveTypes
- and c != QEasingCurve.TCBSpline)]
- curve_types.sort(key=lambda ct: ct[1])
+ curve_types = [(f"QEasingCurve.{e.name}", e) for e in QEasingCurve.Type if e.value <= 40]
with QPainter(pix) as painter:
@@ -151,14 +143,13 @@ class Window(QWidget):
# Start point.
painter.setBrush(Qt.red)
- start = QPoint(y_axis,
- x_axis - curve_scale * curve.valueForProgress(0))
+ start = QPoint(y_axis, x_axis - curve_scale * curve.valueForProgress(0))
painter.drawRect(start.x() - 1, start.y() - 1, 3, 3)
# End point.
painter.setBrush(Qt.blue)
end = QPoint(y_axis + curve_scale,
- x_axis - curve_scale * curve.valueForProgress(1))
+ x_axis - curve_scale * curve.valueForProgress(1))
painter.drawRect(end.x() - 1, end.y() - 1, 3, 3)
curve_path = QPainterPath()
@@ -166,7 +157,7 @@ class Window(QWidget):
t = 0.0
while t <= 1.0:
to = QPointF(y_axis + curve_scale * t,
- x_axis - curve_scale * curve.valueForProgress(t))
+ x_axis - curve_scale * curve.valueForProgress(t))
curve_path.lineTo(to)
t += 1.0 / curve_scale
@@ -191,15 +182,15 @@ class Window(QWidget):
self._anim.setEasingCurve(curve_type)
self._anim.setCurrentTime(0)
- is_elastic = (curve_type >= QEasingCurve.InElastic
- and curve_type <= QEasingCurve.OutInElastic)
- is_bounce = (curve_type >= QEasingCurve.InBounce
- and curve_type <= QEasingCurve.OutInBounce)
+ is_elastic = (curve_type.value >= QEasingCurve.InElastic.value
+ and curve_type.value <= QEasingCurve.OutInElastic.value)
+ is_bounce = (curve_type.value >= QEasingCurve.InBounce.value
+ and curve_type.value <= QEasingCurve.OutInBounce.value)
self._ui.periodSpinBox.setEnabled(is_elastic)
self._ui.amplitudeSpinBox.setEnabled(is_elastic or is_bounce)
- self._ui.overshootSpinBox.setEnabled(curve_type >= QEasingCurve.InBack
- and curve_type <= QEasingCurve.OutInBack)
+ self._ui.overshootSpinBox.setEnabled(curve_type.value >= QEasingCurve.InBack.value
+ and curve_type.value <= QEasingCurve.OutInBack.value)
def path_changed(self, index):
self._anim.set_path_type(index)