From 80bd2deb993faaadc5655b6fb0e0386cadf1989b Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 7 Dec 2023 11:58:09 -0500 Subject: [PATCH] Add docs/examples about how to use the Spin start/stop methods --- README.md | 15 +++++++++++---- docs/source/usage.rst | 38 ++++++++++++++++++++++++++------------ example.py | 15 ++++++++++++--- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f4e5bb7b..82a5ec05 100644 --- a/README.md +++ b/README.md @@ -160,9 +160,12 @@ drawn_image_button = QtWidgets.QPushButton(drawn_image_icon, ```python # Spining icons spin_button = QtWidgets.QPushButton(' Spinning icon') -spin_icon = qta.icon('fa5s.spinner', color='red', - animation=qta.Spin(spin_button)) +animation = qta.Spin(spin_button) +spin_icon = qta.icon('fa5s.spinner', color='red', animation=animation) spin_button.setIcon(spin_icon) + +# Stop the animation when needed +animation.stop() ``` - Display Icon as a widget @@ -170,13 +173,17 @@ spin_button.setIcon(spin_icon) ```python # Spining icon widget spin_widget = qta.IconWidget() -spin_icon = qta.icon('mdi.loading', color='red', - animation=qta.Spin(spin_widget)) +animation = qta.Spin(spin_widget, autostart=False) +spin_icon = qta.icon('mdi.loading', color='red', animation=animation) spin_widget.setIcon(spin_icon) # Simple icon widget simple_widget = qta.IconWidget('mdi.web', color='blue', size=QtCore.QSize(16, 16)) + +# Start and stop the animation when needed +animation.start() +animation.stop() ``` - Screenshot diff --git a/docs/source/usage.rst b/docs/source/usage.rst index b7e0f135..324a4113 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -172,28 +172,39 @@ Examples .. code:: python - # Spin icons + # -- Spin icons spin_button = QtWidgets.QPushButton(' Spinning icon') - spin_icon = qta.icon('fa5s.spinner', color='red', - animation=qta.Spin(spin_button)) + animation = qta.Spin(spin_button) + spin_icon = qta.icon('fa5s.spinner', color='red', animation=animation) spin_button.setIcon(spin_icon) - # Pulse icons + # Stop animation when needed + animation.stop() + + # -- Pulse icons pulse_button = QtWidgets.QPushButton(' Pulsing icon') - pulse_icon = qta.icon('fa5s.spinner', color='green', - animation=qta.Pulse(pulse_button)) + animation = qta.Pulse(pulse_button, autostart=False) + pulse_icon = qta.icon('fa5s.spinner', color='green', animation=animation) pulse_button.setIcon(pulse_icon) - # Stacked spin icons + # Start and stop the animation when needed + animation.start() + animation.stop() + + # -- Stacked spin icons stack_spin_button = QtWidgets.QPushButton('Stack spin') + animation = qta.Spin(stack_spin_button) options = [{'scale_factor': 0.4, - 'animation': qta.Spin(stack_spin_button)}, + 'animation': animation}, {'color': 'blue'}] stack_spin_icon = qta.icon('ei.asl', 'fa5.square', options=options) stack_spin_button.setIcon(stack_spin_icon) stack_spin_button.setIconSize(QtCore.QSize(32, 32)) + # Stop animation when needed + animation.stop() + - Apply font label rendering: .. code:: python @@ -206,13 +217,16 @@ Examples .. code:: python - # Spinning icon widget + # -- Spinning icon widget spin_widget = qta.IconWidget() - spin_icon = qta.icon('mdi.loading', color='red', - animation=qta.Spin(spin_widget)) + animation = qta.Spin(spin_widget) + spin_icon = qta.icon('mdi.loading', color='red', animation=animation) spin_widget.setIcon(spin_icon) - # simple widget + # Stop animation when needed + animation.stop() + + # -- Simple widget simple_widget = qta.IconWidget('mdi.web', color='blue', size=QtCore.QSize(16, 16)) diff --git a/example.py b/example.py index 9d4db7be..d3276720 100644 --- a/example.py +++ b/example.py @@ -122,16 +122,25 @@ def __init__(self): # Spin icons spin_button = QtWidgets.QPushButton(' Spinning icon') - spin_icon = qta.icon('fa5s.spinner', color='red', - animation=qta.Spin(spin_button)) + animation1 = qta.Spin(spin_button) + spin_icon = qta.icon('fa5s.spinner', color='red', animation=animation1) spin_button.setIcon(spin_icon) + timer1 = QtCore.QTimer() + timer1.singleShot(3000, animation1.stop) + # Pulse icons pulse_button = QtWidgets.QPushButton(' Pulsing icon') + animation2 = qta.Pulse(pulse_button, autostart=False) pulse_icon = qta.icon('fa5s.spinner', color='green', - animation=qta.Pulse(pulse_button)) + animation=animation2) pulse_button.setIcon(pulse_icon) + timer2 = QtCore.QTimer() + timer2.singleShot(1500, animation2.start) + timer3 = QtCore.QTimer() + timer3.singleShot(6000, animation2.stop) + # Stacked spin icons stack_spin_button = QtWidgets.QPushButton('Stack spin') options = [{'scale_factor': 0.4,