pyqt-loading-button


Namepyqt-loading-button JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/marcohenning/pyqt-loading-button
SummaryA QPushButton with built-in loading animations for PyQt and PySide
upload_time2024-09-11 22:00:47
maintainerNone
docs_urlNone
authorMarco Henning
requires_python>=3.7
licenseMIT
keywords python pyqt qt button animation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            
# PyQt Loading Button

[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqt-loading-button)
[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/marcohenning/pyqt-loading-button)
[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE)
[![Coverage](https://img.shields.io/badge/coverage-99%25-neon)](https://github.com/marcohenning/pyqt-loading-button)
[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/marcohenning/pyqt-loading-button)

A QPushButton with built-in loading animations for PyQt and PySide.

![Main](https://github.com/user-attachments/assets/e4142cd2-9618-498e-a4c1-a2000239b0c9)

## About

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.

## Installation

```
pip install pyqt-loading-button
```

## Example

```python
import time
from PyQt6.QtGui import QColor
from PyQt6.QtWidgets import QMainWindow
from pyqt_loading_button import LoadingButton, AnimationType


class Window(QMainWindow):

    def __init__(self):
        super().__init__(parent=None)

        # LoadingButton
        self.button_1 = LoadingButton(self)
        self.button_1.setText('Click me!')
        self.button_1.setAnimationType(AnimationType.Circle)
        self.button_1.setAnimationSpeed(2000)
        self.button_1.setAnimationColor(QColor(0, 0, 0))
        self.button_1.setAnimationWidth(15)
        self.button_1.setAnimationStrokeWidth(3)
        self.button_1.setAction(self.do_something)

    def do_something(self):
        time.sleep(5)  # Simulate long task
```

## Documentation

* **Setting the button text:**
```python
loading_button.setText('Click me!')
```

* **Setting the action connected to the clicked event:**
```python
def do_something():
    time.sleep(5)  # Simulate long task

loading_button.setAction(do_something)
```

* **Setting the animation type:**
```python
loading_button.setAnimationType(AnimationType.Circle)  # Circular animation
loading_button.setAnimationType(AnimationType.Dots)    # Dotted animation
```

* **Setting the animation speed:**
```python
# 2000 means each loop of the animation takes 2000 ms to complete
loading_button.setAnimationSpeed(2000)
```

* **Setting the animation width:**
```python
loading_button.setAnimationWidth(15)  # Total width of the animation is 15 px
```

* **Setting the animation stroke width:**
```python
loading_button.setAnimationStrokeWidth(3)  # Stroke width of the brush is 3 px
```

* **Setting the animation color:**
```python
loading_button.setAnimationColor(QColor(0, 0, 0))
```

* **Checking whether the action is currently being executed:**
```python
loading_button.isRunning()
```

**<br>All methods:**

| Method                                                  | Description                                                                              |
|---------------------------------------------------------|------------------------------------------------------------------------------------------|
| `text(self)`                                            | Get the current button text                                                              |
| `setText(self, text: str)`                              | Set the button text                                                                      |
| `setAction(self, action: callable)`                     | Set the action connected to the clicked event                                            |
| `isRunning(self)`                                       | Get whether the action is currently being executed                                       |
| `getAnimationType(self)`                                | Get the current animation type                                                           |
| `setAnimationType(self, animation_type: AnimationType)` | Set the animation type                                                                   |
| `getAnimationSpeed(self)`                               | Get the current animation speed (time it takes the animation to complete one loop in ms) |
| `setAnimationSpeed(self, speed: int)`                   | Set the animation speed (time it takes the animation to complete one loop in ms)         |
| `getAnimationWidth(self)`                               | Get the current width of the animation                                                   |
| `setAnimationWidth(self, width: int)`                   | Set the width of the animation                                                           |
| `getAnimationStrokeWidth(self)`                         | Get the current width of the brush stroke                                                |
| `setAnimationStrokeWidth(self, width: int)`             | Set the width of the brush stroke                                                        |
| `getAnimationColor(self)`                               | Get the current animation color                                                          |
| `setAnimationColor(self, color: QColor)`                | Set the animation color                                                                  |

## License

This software is licensed under the [MIT license](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/marcohenning/pyqt-loading-button",
    "name": "pyqt-loading-button",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "python, pyqt, qt, button, animation",
    "author": "Marco Henning",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5c/09/e79f4bbc0f40ee790a773dcbaf783cfafd2e6db16421993713112728cd89/pyqt-loading-button-1.0.0.tar.gz",
    "platform": null,
    "description": "\r\n# PyQt Loading Button\r\n\r\n[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqt-loading-button)\r\n[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/marcohenning/pyqt-loading-button)\r\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE)\r\n[![Coverage](https://img.shields.io/badge/coverage-99%25-neon)](https://github.com/marcohenning/pyqt-loading-button)\r\n[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/marcohenning/pyqt-loading-button)\r\n\r\nA QPushButton with built-in loading animations for PyQt and PySide.\r\n\r\n![Main](https://github.com/user-attachments/assets/e4142cd2-9618-498e-a4c1-a2000239b0c9)\r\n\r\n## About\r\n\r\nThe 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.\r\n\r\n## Installation\r\n\r\n```\r\npip install pyqt-loading-button\r\n```\r\n\r\n## Example\r\n\r\n```python\r\nimport time\r\nfrom PyQt6.QtGui import QColor\r\nfrom PyQt6.QtWidgets import QMainWindow\r\nfrom pyqt_loading_button import LoadingButton, AnimationType\r\n\r\n\r\nclass Window(QMainWindow):\r\n\r\n    def __init__(self):\r\n        super().__init__(parent=None)\r\n\r\n        # LoadingButton\r\n        self.button_1 = LoadingButton(self)\r\n        self.button_1.setText('Click me!')\r\n        self.button_1.setAnimationType(AnimationType.Circle)\r\n        self.button_1.setAnimationSpeed(2000)\r\n        self.button_1.setAnimationColor(QColor(0, 0, 0))\r\n        self.button_1.setAnimationWidth(15)\r\n        self.button_1.setAnimationStrokeWidth(3)\r\n        self.button_1.setAction(self.do_something)\r\n\r\n    def do_something(self):\r\n        time.sleep(5)  # Simulate long task\r\n```\r\n\r\n## Documentation\r\n\r\n* **Setting the button text:**\r\n```python\r\nloading_button.setText('Click me!')\r\n```\r\n\r\n* **Setting the action connected to the clicked event:**\r\n```python\r\ndef do_something():\r\n    time.sleep(5)  # Simulate long task\r\n\r\nloading_button.setAction(do_something)\r\n```\r\n\r\n* **Setting the animation type:**\r\n```python\r\nloading_button.setAnimationType(AnimationType.Circle)  # Circular animation\r\nloading_button.setAnimationType(AnimationType.Dots)    # Dotted animation\r\n```\r\n\r\n* **Setting the animation speed:**\r\n```python\r\n# 2000 means each loop of the animation takes 2000 ms to complete\r\nloading_button.setAnimationSpeed(2000)\r\n```\r\n\r\n* **Setting the animation width:**\r\n```python\r\nloading_button.setAnimationWidth(15)  # Total width of the animation is 15 px\r\n```\r\n\r\n* **Setting the animation stroke width:**\r\n```python\r\nloading_button.setAnimationStrokeWidth(3)  # Stroke width of the brush is 3 px\r\n```\r\n\r\n* **Setting the animation color:**\r\n```python\r\nloading_button.setAnimationColor(QColor(0, 0, 0))\r\n```\r\n\r\n* **Checking whether the action is currently being executed:**\r\n```python\r\nloading_button.isRunning()\r\n```\r\n\r\n**<br>All methods:**\r\n\r\n| Method                                                  | Description                                                                              |\r\n|---------------------------------------------------------|------------------------------------------------------------------------------------------|\r\n| `text(self)`                                            | Get the current button text                                                              |\r\n| `setText(self, text: str)`                              | Set the button text                                                                      |\r\n| `setAction(self, action: callable)`                     | Set the action connected to the clicked event                                            |\r\n| `isRunning(self)`                                       | Get whether the action is currently being executed                                       |\r\n| `getAnimationType(self)`                                | Get the current animation type                                                           |\r\n| `setAnimationType(self, animation_type: AnimationType)` | Set the animation type                                                                   |\r\n| `getAnimationSpeed(self)`                               | Get the current animation speed (time it takes the animation to complete one loop in ms) |\r\n| `setAnimationSpeed(self, speed: int)`                   | Set the animation speed (time it takes the animation to complete one loop in ms)         |\r\n| `getAnimationWidth(self)`                               | Get the current width of the animation                                                   |\r\n| `setAnimationWidth(self, width: int)`                   | Set the width of the animation                                                           |\r\n| `getAnimationStrokeWidth(self)`                         | Get the current width of the brush stroke                                                |\r\n| `setAnimationStrokeWidth(self, width: int)`             | Set the width of the brush stroke                                                        |\r\n| `getAnimationColor(self)`                               | Get the current animation color                                                          |\r\n| `setAnimationColor(self, color: QColor)`                | Set the animation color                                                                  |\r\n\r\n## License\r\n\r\nThis software is licensed under the [MIT license](https://github.com/marcohenning/pyqt-loading-button/blob/master/LICENSE).\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A QPushButton with built-in loading animations for PyQt and PySide",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/marcohenning/pyqt-loading-button"
    },
    "split_keywords": [
        "python",
        " pyqt",
        " qt",
        " button",
        " animation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4a09774de44140238399e4e39c573cf7322a8b8931e08ee949b60353a373baba",
                "md5": "23b4f889d8578b1bde4a5569a7b22f96",
                "sha256": "423abef5e286fa818d61f10298716a9559f0cc36dc38397e9eac85cc4bc33cb6"
            },
            "downloads": -1,
            "filename": "pyqt_loading_button-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23b4f889d8578b1bde4a5569a7b22f96",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7085,
            "upload_time": "2024-09-11T22:00:46",
            "upload_time_iso_8601": "2024-09-11T22:00:46.272693Z",
            "url": "https://files.pythonhosted.org/packages/4a/09/774de44140238399e4e39c573cf7322a8b8931e08ee949b60353a373baba/pyqt_loading_button-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c09e79f4bbc0f40ee790a773dcbaf783cfafd2e6db16421993713112728cd89",
                "md5": "b6ccc8a2493bc187453be6e1a10423a4",
                "sha256": "b9ab3428c482e65915c38369e9ed9028ea4dead4977ef729bb24402d01f79de9"
            },
            "downloads": -1,
            "filename": "pyqt-loading-button-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b6ccc8a2493bc187453be6e1a10423a4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7389,
            "upload_time": "2024-09-11T22:00:47",
            "upload_time_iso_8601": "2024-09-11T22:00:47.754207Z",
            "url": "https://files.pythonhosted.org/packages/5c/09/e79f4bbc0f40ee790a773dcbaf783cfafd2e6db16421993713112728cd89/pyqt-loading-button-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-11 22:00:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcohenning",
    "github_project": "pyqt-loading-button",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "lcname": "pyqt-loading-button"
}
        
Elapsed time: 0.36540s