Skip to content

Commit 9e02865

Browse files
committed
Start creating README.md
1 parent 52f2b15 commit 9e02865

File tree

1 file changed

+119
-2
lines changed

1 file changed

+119
-2
lines changed

README.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,119 @@
1-
# pyqt-loading-button
2-
A QPushButton with built-in loading animations for PyQt and PySide
1+
# PyQt Loading Button
2+
3+
[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqt-loading-button)
4+
[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/marcohenning/pyqt-loading-button)
5+
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE)
6+
[![Coverage](https://img.shields.io/badge/coverage-99%25-neon)](https://github.com/marcohenning/pyqt-loading-button)
7+
[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/marcohenning/pyqt-loading-button)
8+
9+
A QPushButton with built-in loading animations for PyQt and PySide.
10+
11+
gif
12+
13+
## About
14+
15+
The widget functions exactly like PyQt's regular QPushButton with the only exception being the way methods are connected to the clicked event. Normally you would connect a method to the `clicked` event by using the `connect()` method. On this button you use the `setAction()` method instead, passing a callable object as its parameter the same way you would do with the `connect()` method. The method will then get executed in a `QThread`, allowing the button to display a loading animation.
16+
17+
## Installation
18+
19+
```
20+
pip install pyqt-loading-button
21+
```
22+
23+
## Example
24+
25+
```python
26+
import time
27+
from PyQt6.QtGui import QColor
28+
from PyQt6.QtWidgets import QMainWindow
29+
from pyqt_loading_button import LoadingButton, AnimationType
30+
31+
32+
class Window(QMainWindow):
33+
34+
def __init__(self):
35+
super().__init__(parent=None)
36+
37+
# LoadingButton
38+
self.button_1 = LoadingButton(self)
39+
self.button_1.setText('Click me!')
40+
self.button_1.setAnimationType(AnimationType.Circle)
41+
self.button_1.setAnimationSpeed(2000)
42+
self.button_1.setAnimationColor(QColor(0, 0, 0))
43+
self.button_1.setAnimationWidth(15)
44+
self.button_1.setAnimationStrokeWidth(3)
45+
self.button_1.setAction(self.do_something)
46+
47+
def do_something(self):
48+
time.sleep(5) # Simulate long task
49+
```
50+
51+
## Documentation
52+
53+
* **Setting the button text:**
54+
```python
55+
loading_button.setText('Click me!')
56+
```
57+
58+
* **Setting the action connected to the clicked event:**
59+
```python
60+
def do_something():
61+
time.sleep(5) # Simulate long task
62+
63+
loading_button.setAction(do_something)
64+
```
65+
66+
* **Setting the animation type:**
67+
```python
68+
loading_button.setAnimationType(AnimationType.Circle) # Circular animation
69+
loading_button.setAnimationType(AnimationType.Dots) # Dotted animation
70+
```
71+
72+
* **Setting the animation speed:**
73+
```python
74+
# 2000 means each loop of the animation takes 2000 ms to complete
75+
loading_button.setAnimationSpeed(2000)
76+
```
77+
78+
* **Setting the animation width:**
79+
```python
80+
loading_button.setAnimationWidth(15) # Total width of the animation is 15 px
81+
```
82+
83+
* **Setting the animation stroke width:**
84+
```python
85+
loading_button.setAnimationStrokeWidth(3) # Stroke width of the brush is 3 px
86+
```
87+
88+
* **Setting the animation color:**
89+
```python
90+
loading_button.setAnimationColor(QColor(0, 0, 0))
91+
```
92+
93+
* **Checking whether the action is currently being executed:**
94+
```python
95+
loading_button.isRunning()
96+
```
97+
98+
**<br>All methods:**
99+
100+
| Method | Description |
101+
|---------------------------------------------------------|------------------------------------------------------------------------------------------|
102+
| `text(self)` | Get the current button text |
103+
| `setText(self, text: str)` | Set the button text |
104+
| `setAction(self, action: callable)` | Set the action connected to the clicked event |
105+
| `isRunning(self)` | Get whether the action is currently being executed |
106+
| `getAnimationType(self)` | Get the current animation type |
107+
| `setAnimationType(self, animation_type: AnimationType)` | Set the animation type |
108+
| `getAnimationSpeed(self)` | Get the current animation speed (time it takes the animation to complete one loop in ms) |
109+
| `setAnimationSpeed(self, speed: int)` | Set the animation speed (time it takes the animation to complete one loop in ms) |
110+
| `getAnimationWidth(self)` | Get the current width of the animation |
111+
| `setAnimationWidth(self, width: int)` | Set the width of the animation |
112+
| `getAnimationStrokeWidth(self)` | Get the current width of the brush stroke |
113+
| `setAnimationStrokeWidth(self, width: int)` | Set the width of the brush stroke |
114+
| `getAnimationColor(self)` | Get the current animation color |
115+
| `setAnimationColor(self, color: QColor)` | Set the animation color |
116+
117+
## License
118+
119+
This software is licensed under the [MIT license](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE).

0 commit comments

Comments
 (0)