pyqtcountup


Namepyqtcountup JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/niklashenning/pyqtcountup
SummaryA simple numerical data animation library for PyQt and PySide labels
upload_time2024-06-06 20:51:02
maintainerNone
docs_urlNone
authorNiklas Henning
requires_python>=3.7
licenseMIT
keywords python pyqt qt label animation numerical data
VCS
bugtrack_url
requirements QtPy
Travis-CI No Travis.
coveralls test coverage
            
# PyQt CountUp

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

A simple numerical data animation library for PyQt and PySide labels inspired by [countUp.js](https://github.com/inorganik/CountUp.js)

![pyqtcountup](https://github.com/niklashenning/pyqtcountup/assets/58544929/0e6a2b8b-e4c6-493c-a007-86c5be3011d3)

## Features
* Customizable decimal places
* Customizable decimal separator and thousands separator
* Customizable prefix and suffix
* Supports 41 different easing curves
* Works with `PyQt5`, `PyQt6`, `PySide2`, and `PySide6`

## Installation
```
pip install pyqtcountup
```

## Usage
Import the `CountUp` class, instantiate it with a label, and start the animation by calling the `start()` method:

```python
from PyQt6.QtWidgets import QMainWindow, QLabel
from pyqtcountup import CountUp


class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)
        
        # Create label to show the animation on
        countup_label = QLabel(self)
        
        # Init and start animation with duration of 2.5 seconds
        countup = CountUp(countup_label)
        countup.setStartValue(1000)
        countup.setEndValue(7241)
        countup.setDuration(2500)
        countup.start()
```

Use the `update()` method to update the end value of a running animation (can also be used if the animation is already finished):
```python
# Start animation with 2500 as end value
countup.setEndValue(2500)
countup.start()

# Update end value of the animation to be 1500
countup.update(1500)
```

To pause and resume an animation, use the `pause()` and `resume()` methods:
```python
# Temporarily stop the animation with the option to resume it
countup.pause()

# Resume the animation at the point where it was stopped
countup.resume()
```

> **NOTE:** <br>Only paused animations can be resumed, so calling `resume()` after using the `stop()` method will not work.


If you want to stop an animation completely, you can use the `stop()` method:
```python
countup.stop()
```

If you want to stop the animation and also reset the label to the start value, you can use the `reset()` method:
```python
countup.reset()
```

To check if the animation is currently running or paused, use the `isRunning()` and `isPaused()` methods: 
```python
# True if the animation is currently running, otherwise False
is_running = countup.isRunning()

# True if the animation is currently paused and can be resumed, otherwise False
is_paused = countup.isPaused()
```

## Customization
* **Setting the start and end values of the animation:**
```python
countup.setStartValue(-1000)
countup.setEndValue(2500)

# Alternatively
countup.setStartEndValues(-1000, 2500)
```

* **Setting the duration of the animation:**
```python
countup.setDuration(2500)  # 2500 milliseconds = 2.5 seconds
```

* **Customizing the formatting of the number:**
```python
countup.setDecimalPlaces(2)  # Default: 0
countup.setDecimal(',')      # Default: '.'
countup.setSeparator('.')    # Default: ''
```
> **EXAMPLE:** <br>The value `1052` formatted with two decimal places, `,` as the decimal, and `.` as the separator would be `1.052,00`

* **Adding a prefix and a suffix:**
```python
countup.setPrefix('~')   # Default: ''
countup.setSuffix('€')  # Default: ''
```
> **EXAMPLE:** <br>The value `100` formatted with `~` as the prefix and `€` as the suffix would be shown as `~100€`

* **Making the prefix show between the minus and the number for negative values:**
```python
countup.setPrefixBeforeMinus(False)  # Default: True
```
> **EXAMPLE:** <br>The value `100` formatted with `$` as the prefix and `setPrefixBeforeMinus(False)` would be shown as `-$100` instead of `$-100`

* **Customizing the easing of the animation:**
```python
countup.setEasing(QEasingCurve.Type.OutCubic)  # Default: QEasingCurve.Type.OutExpo

# Using no easing (same as QEasingCurve.Type.Linear)
countup.setEasing(None)
```
> **AVAILABLE EASING CURVES:** <br> `Linear`, `InQuad`, `OutQuad`, `InOutQuad`, `OutInQuad`, `InCubic`, `OutCubic`,
> `InOutCubic`, `OutInCubic`, `InQuart`, `OutQuart`, `InOutQuart`, `OutInQuart`, `InQuint`, `OutQuint`, `InOutQuint`,
> `OutInQuint`, `InSine`, `OutSine`, `InOutSine`, `OutInSine`, `InExpo`, `OutExpo`, `InOutExpo`, `OutInExpo`,
> `InCirc`, `OutCirc`, `InOutCirc`, `OutInCirc`, `InElastic`, `OutElastic`, `InOutElastic`, `OutInElastic`,
> `InBack`, `OutBack`, `InOutBack`, `OutInBack`, `InBounce`, `OutBounce`, `InOutBounce`, `OutInBounce`
> <br>You can find visualizations of these easing curves in the [PyQt documentation](https://doc.qt.io/qtforpython-5/PySide2/QtCore/QEasingCurve.html).

Examples for PyQt5, PyQt6, and PySide6 can be found in the [demo](https://github.com/niklashenning/pyqtcountup/blob/master/demo) folder.

## Tests
Installing the required test dependencies [PyQt6](https://pypi.org/project/PyQt6/), [pytest](https://github.com/pytest-dev/pytest), and [coveragepy](https://github.com/nedbat/coveragepy):
```
pip install PyQt6 pytest coverage
```

To run the tests with coverage, clone this repository, go into the main directory and run:
```
coverage run -m pytest
coverage report --ignore-errors -m
```

## License
This software is licensed under the [MIT license](https://github.com/niklashenning/pyqtcountup/blob/master/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/niklashenning/pyqtcountup",
    "name": "pyqtcountup",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "python, pyqt, qt, label, animation, numerical data",
    "author": "Niklas Henning",
    "author_email": "business@niklashenning.com",
    "download_url": "https://files.pythonhosted.org/packages/b9/3d/fa88e21085b96292da6fef86309b8382d4acc5924a69e7d064ed60e54a8b/pyqtcountup-1.0.0.tar.gz",
    "platform": null,
    "description": "\r\n# PyQt CountUp\r\n\r\n[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqtcountup/)\r\n[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqtcountup)\r\n[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqtcountup)\r\n[![Coverage](https://img.shields.io/badge/coverage-100%25-green)](https://github.com/niklashenning/pyqtcountup)\r\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/niklashenning/pyqtcountup/blob/master/LICENSE)\r\n\r\nA simple numerical data animation library for PyQt and PySide labels inspired by [countUp.js](https://github.com/inorganik/CountUp.js)\r\n\r\n![pyqtcountup](https://github.com/niklashenning/pyqtcountup/assets/58544929/0e6a2b8b-e4c6-493c-a007-86c5be3011d3)\r\n\r\n## Features\r\n* Customizable decimal places\r\n* Customizable decimal separator and thousands separator\r\n* Customizable prefix and suffix\r\n* Supports 41 different easing curves\r\n* Works with `PyQt5`, `PyQt6`, `PySide2`, and `PySide6`\r\n\r\n## Installation\r\n```\r\npip install pyqtcountup\r\n```\r\n\r\n## Usage\r\nImport the `CountUp` class, instantiate it with a label, and start the animation by calling the `start()` method:\r\n\r\n```python\r\nfrom PyQt6.QtWidgets import QMainWindow, QLabel\r\nfrom pyqtcountup import CountUp\r\n\r\n\r\nclass Window(QMainWindow):\r\n    def __init__(self):\r\n        super().__init__(parent=None)\r\n        \r\n        # Create label to show the animation on\r\n        countup_label = QLabel(self)\r\n        \r\n        # Init and start animation with duration of 2.5 seconds\r\n        countup = CountUp(countup_label)\r\n        countup.setStartValue(1000)\r\n        countup.setEndValue(7241)\r\n        countup.setDuration(2500)\r\n        countup.start()\r\n```\r\n\r\nUse the `update()` method to update the end value of a running animation (can also be used if the animation is already finished):\r\n```python\r\n# Start animation with 2500 as end value\r\ncountup.setEndValue(2500)\r\ncountup.start()\r\n\r\n# Update end value of the animation to be 1500\r\ncountup.update(1500)\r\n```\r\n\r\nTo pause and resume an animation, use the `pause()` and `resume()` methods:\r\n```python\r\n# Temporarily stop the animation with the option to resume it\r\ncountup.pause()\r\n\r\n# Resume the animation at the point where it was stopped\r\ncountup.resume()\r\n```\r\n\r\n> **NOTE:** <br>Only paused animations can be resumed, so calling `resume()` after using the `stop()` method will not work.\r\n\r\n\r\nIf you want to stop an animation completely, you can use the `stop()` method:\r\n```python\r\ncountup.stop()\r\n```\r\n\r\nIf you want to stop the animation and also reset the label to the start value, you can use the `reset()` method:\r\n```python\r\ncountup.reset()\r\n```\r\n\r\nTo check if the animation is currently running or paused, use the `isRunning()` and `isPaused()` methods: \r\n```python\r\n# True if the animation is currently running, otherwise False\r\nis_running = countup.isRunning()\r\n\r\n# True if the animation is currently paused and can be resumed, otherwise False\r\nis_paused = countup.isPaused()\r\n```\r\n\r\n## Customization\r\n* **Setting the start and end values of the animation:**\r\n```python\r\ncountup.setStartValue(-1000)\r\ncountup.setEndValue(2500)\r\n\r\n# Alternatively\r\ncountup.setStartEndValues(-1000, 2500)\r\n```\r\n\r\n* **Setting the duration of the animation:**\r\n```python\r\ncountup.setDuration(2500)  # 2500 milliseconds = 2.5 seconds\r\n```\r\n\r\n* **Customizing the formatting of the number:**\r\n```python\r\ncountup.setDecimalPlaces(2)  # Default: 0\r\ncountup.setDecimal(',')      # Default: '.'\r\ncountup.setSeparator('.')    # Default: ''\r\n```\r\n> **EXAMPLE:** <br>The value `1052` formatted with two decimal places, `,` as the decimal, and `.` as the separator would be `1.052,00`\r\n\r\n* **Adding a prefix and a suffix:**\r\n```python\r\ncountup.setPrefix('~')   # Default: ''\r\ncountup.setSuffix('\u00e2\u201a\u00ac')  # Default: ''\r\n```\r\n> **EXAMPLE:** <br>The value `100` formatted with `~` as the prefix and `\u00e2\u201a\u00ac` as the suffix would be shown as `~100\u00e2\u201a\u00ac`\r\n\r\n* **Making the prefix show between the minus and the number for negative values:**\r\n```python\r\ncountup.setPrefixBeforeMinus(False)  # Default: True\r\n```\r\n> **EXAMPLE:** <br>The value `100` formatted with `$` as the prefix and `setPrefixBeforeMinus(False)` would be shown as `-$100` instead of `$-100`\r\n\r\n* **Customizing the easing of the animation:**\r\n```python\r\ncountup.setEasing(QEasingCurve.Type.OutCubic)  # Default: QEasingCurve.Type.OutExpo\r\n\r\n# Using no easing (same as QEasingCurve.Type.Linear)\r\ncountup.setEasing(None)\r\n```\r\n> **AVAILABLE EASING CURVES:** <br> `Linear`, `InQuad`, `OutQuad`, `InOutQuad`, `OutInQuad`, `InCubic`, `OutCubic`,\r\n> `InOutCubic`, `OutInCubic`, `InQuart`, `OutQuart`, `InOutQuart`, `OutInQuart`, `InQuint`, `OutQuint`, `InOutQuint`,\r\n> `OutInQuint`, `InSine`, `OutSine`, `InOutSine`, `OutInSine`, `InExpo`, `OutExpo`, `InOutExpo`, `OutInExpo`,\r\n> `InCirc`, `OutCirc`, `InOutCirc`, `OutInCirc`, `InElastic`, `OutElastic`, `InOutElastic`, `OutInElastic`,\r\n> `InBack`, `OutBack`, `InOutBack`, `OutInBack`, `InBounce`, `OutBounce`, `InOutBounce`, `OutInBounce`\r\n> <br>You can find visualizations of these easing curves in the [PyQt documentation](https://doc.qt.io/qtforpython-5/PySide2/QtCore/QEasingCurve.html).\r\n\r\nExamples for PyQt5, PyQt6, and PySide6 can be found in the [demo](https://github.com/niklashenning/pyqtcountup/blob/master/demo) folder.\r\n\r\n## Tests\r\nInstalling the required test dependencies [PyQt6](https://pypi.org/project/PyQt6/), [pytest](https://github.com/pytest-dev/pytest), and [coveragepy](https://github.com/nedbat/coveragepy):\r\n```\r\npip install PyQt6 pytest coverage\r\n```\r\n\r\nTo run the tests with coverage, clone this repository, go into the main directory and run:\r\n```\r\ncoverage run -m pytest\r\ncoverage report --ignore-errors -m\r\n```\r\n\r\n## License\r\nThis software is licensed under the [MIT license](https://github.com/niklashenning/pyqtcountup/blob/master/LICENSE).\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple numerical data animation library for PyQt and PySide labels",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/niklashenning/pyqtcountup"
    },
    "split_keywords": [
        "python",
        " pyqt",
        " qt",
        " label",
        " animation",
        " numerical data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b722d4fbf58c6e4e25e79dba90d4ef0eda448374384334135006bb76205cd479",
                "md5": "7b3451add2c0e0053ae1883908b32fcc",
                "sha256": "c442f817680774beb65553d55c760ba393e59e16e165a7d95fbf641b2ba06c8e"
            },
            "downloads": -1,
            "filename": "pyqtcountup-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b3451add2c0e0053ae1883908b32fcc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7188,
            "upload_time": "2024-06-06T20:50:52",
            "upload_time_iso_8601": "2024-06-06T20:50:52.525484Z",
            "url": "https://files.pythonhosted.org/packages/b7/22/d4fbf58c6e4e25e79dba90d4ef0eda448374384334135006bb76205cd479/pyqtcountup-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b93dfa88e21085b96292da6fef86309b8382d4acc5924a69e7d064ed60e54a8b",
                "md5": "7f3cccb00b080546b9fc0b47304a50c9",
                "sha256": "bf00cd8ad8e8c050a2f2c106bd2ee170167f48627658a6e6d6f901bf70c3ebf3"
            },
            "downloads": -1,
            "filename": "pyqtcountup-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7f3cccb00b080546b9fc0b47304a50c9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8586,
            "upload_time": "2024-06-06T20:51:02",
            "upload_time_iso_8601": "2024-06-06T20:51:02.027526Z",
            "url": "https://files.pythonhosted.org/packages/b9/3d/fa88e21085b96292da6fef86309b8382d4acc5924a69e7d064ed60e54a8b/pyqtcountup-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-06 20:51:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "niklashenning",
    "github_project": "pyqtcountup",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "QtPy",
            "specs": [
                [
                    ">=",
                    "2.4.1"
                ]
            ]
        }
    ],
    "lcname": "pyqtcountup"
}
        
Elapsed time: 3.64408s