pyqtcaptcha


Namepyqtcaptcha JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/marcohenning/pyqtcaptcha
SummaryA modern and fully customizable CAPTCHA library for PyQt and PySide
upload_time2024-10-21 22:16:03
maintainerNone
docs_urlNone
authorMarco Henning
requires_python>=3.7
licenseMIT
keywords python pyqt qt captcha
VCS
bugtrack_url
requirements QtPy pygame
Travis-CI No Travis.
coveralls test coverage
            
# PyQt CAPTCHA

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

A modern and fully customizable CAPTCHA library for PyQt and PySide.

![main](https://github.com/user-attachments/assets/14af04a6-c953-4038-8121-0c7c91b92f9f)

## About

This library was made to bring CAPTCHA support to PyQt desktop applications. While the measure is mostly used in web applications due to their ease of automation, desktop applications can also be automated using programs like AutoHotkey. This CAPTCHA widget is fully customizable from everything related to visuals to the difficulty of the tasks and helps protect your application from spam and abuse through automation.

> All images have been sourced from public domain video material and are not subject to copyright restrictions.

## Installation

```
pip install pyqtcaptcha
```

## Example

```python
from PyQt6.QtWidgets import QMainWindow
from pyqtcaptcha import Captcha, CaptchaDifficulty


class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)

        self.captcha = Captcha(self)
        self.captcha.setDifficulty(CaptchaDifficulty.HARD)
        self.captcha.setFixedSize(130, 40)
```

## Documentation

> **IMPORTANT:** <br>Styling of the widget must not be done by setting the stylesheet manually as the widget calculates the stylesheet itself and overrides it. Use the provided methods such as `setBackgroundColor()` instead.

* **Setting the difficulty:**
```python
captcha.setDifficulty(CaptchaDifficulty.HARD)
```

> On easy difficulty the user will have to complete image selection tasks (i.e. "Select all images containing cars"). On hard difficulty the user will have to select image squares (i.e. "Select all squares containing traffic lights"). Medium difficulty alternates between these two options randomly.

* **Checking the state:**
```python
captcha.isPassed()
```

* **Resetting the state:**
```python
captcha.reset()
```

* **Setting the button text:**
```python
captcha.setText('Text')
```

* **Setting the button foreground color:**
```python
captcha.setButtonForegroundColor(QColor(255, 0, 0))
```

* **Setting the button background color:**
```python
captcha.setButtonBackgroundColor(QColor(0, 255, 0))
```

* **Setting the button border color:**
```python
captcha.setButtonBorderColor(QColor(0, 0, 255))
```

* **Setting the button border width:**
```python
captcha.setButtonBorderWidth(1)
```

* **Setting the button border radius:**
```python
captcha.setButtonBorderRadius(5)
```

* **Setting the checkbox color:**
```python
captcha.setCheckboxColor(QColor(255, 255, 0))
```

* **Setting the checkbox width:**
```python
captcha.setCheckboxWidth(2)
```

> The checkbox width is also used for the width of the checkmark.

* **Setting the checkmark color:**
```python
captcha.setCheckmarkColor(QColor(0, 255, 255))
```

* **Setting the CAPTCHA popup foreground color:**
```python
captcha.setCaptchaForegroundColor(QColor(255, 255, 255))
```

> The foreground color (white by default) is used for text elements like the captcha prompt and submit button text as well as for the checkmark on selected images.

* **Setting the CAPTCHA popup background color:**
```python
captcha.setCaptchaBackgroundColor(QColor(255, 0, 255))
```

> The background color (white by default) is used for the background of the popup window.

* **Setting the CAPTCHA popup border color:**
```python
captcha.setCaptchaBorderColor(QColor(100, 255, 0))
```

* **Setting the CAPTCHA popup border radius:**
```python
captcha.setCaptchaBorderRadius(10)
```

* **Setting the CAPTCHA popup primary color:**
```python
captcha.setCaptchaPrimaryColor(QColor(0, 100, 255))
```

> The primary color (green by default) is used for the background of the captcha prompt and the background of the submit button.

* **Setting the CAPTCHA popup primary color (hovered):**
```python
captcha.setCaptchaPrimaryColorHovered(QColor(255, 100, 0))
```

> The primary hovered color (light-green by default) is used for the hovered background of the submit button.

* **Setting the CAPTCHA popup secondary color:**
```python
captcha.setCaptchaSecondaryColor(QColor(255, 255, 100))
```

> The secondary color (gray by default) is used for elements like the refresh button, visual button, audio button and play button.

* **Setting the CAPTCHA popup secondary color (hovered):**
```python
captcha.setCaptchaSecondaryColorHovered(QColor(0, 255, 50))
```

> The secondary hovered color (dark-gray by default) is used as the hover color for elements like the refresh button, visual button, audio button and play button.

* **Connecting methods to the provided events:**
```python
captcha.started.connect(self.some_function)
captcha.aborted.connect(self.some_function)
captcha.passed.connect(self.some_function)
captcha.failed.connect(self.some_function)
```

> The `started` signal is emitted every time the popup window gets opened, while the `aborted` signal is emitted every time the popup window gets closed without submitting an answer. When the submit button is pressed either the `passed` signal or the `failed` signal is emitted depending on the correctness of the answer.

**<br>All available methods:**

| Method                                                 | Description                                     |
|--------------------------------------------------------|-------------------------------------------------|
| `text(self)`                                           | Get the current button text                     |
| `setText(self, text: str)`                             | Set the button text                             |
| `getButtonForegroundColor(self)`                       | Get the current button foreground color         |
| `setButtonForegroundColor(self, color: QColor)`        | Set the button foreground color                 |
| `getButtonBackgroundColor(self)`                       | Get the current button background color         |
| `setButtonBackgroundColor(self, color: QColor)`        | Set the button background color                 |
| `getButtonBorderColor(self)`                           | Get the current button border color             |
| `setButtonBorderColor(self, color: QColor)`            | Set the button border color                     |
| `getButtonBorderWidth(self)`                           | Get the current button border width             |
| `setButtonBorderWidth(self, width: int)`               | Set the button border width                     |
| `getButtonBorderRadius(self)`                          | Get the current button border radius            |
| `setButtonBorderRadius(self, radius: int)`             | Set the button border radius                    |
| `getCheckboxColor(self)`                               | Get the current checkbox color                  |
| `setCheckboxColor(self, color: QColor)`                | Set the checkbox color                          |
| `getCheckboxWidth(self)`                               | Get the current checkbox width                  |
| `setCheckboxWidth(self, width: int)`                   | Set the checkbox width                          |
| `getCheckmarkColor(self)`                              | Get the current checkmark color                 |
| `setCheckmarkColor(self, color: QColor)`               | Set the checkmark color                         |
| `getCaptchaForegroundColor(self)`                      | Get the current captcha foreground color        |
| `setCaptchaForegroundColor(self, color: QColor)`       | Set the captcha foreground color                |
| `getCaptchaBackgroundColor(self)`                      | Get the current captcha background color        |
| `setCaptchaBackgroundColor(self, color: QColor)`       | Set the captcha background color                |
| `getCaptchaBorderColor(self)`                          | Get the current captcha border color            |
| `setCaptchaBorderColor(self, color: QColor)`           | Set the captcha border color                    |
| `getCaptchaBorderRadius(self)`                         | Get the current captcha border radius           |
| `setCaptchaBorderRadius(self, radius: int)`            | Set the captcha border radius                   |
| `getCaptchaPrimaryColor(self)`                         | Get the current captcha primary color           |
| `setCaptchaPrimaryColor(self, color: QColor)`          | Set the captcha primary color                   |
| `getCaptchaPrimaryColorHovered(self)`                  | Get the current captcha primary hovered color   |
| `setCaptchaPrimaryColorHovered(self, color: QColor)`   | Set the captcha primary hovered color           |
| `getCaptchaSecondaryColor(self)`                       | Get the current captcha secondary color         |
| `setCaptchaSecondaryColor(self, color: QColor)`        | Set the captcha secondary color                 |
| `getCaptchaSecondaryColorHovered(self)`                | Get the current captcha secondary hovered color |
| `setCaptchaSecondaryColorHovered(self, color: QColor)` | Set the captcha secondary hovered color         |
| `getDifficulty(self)`                                  | Get the current captcha difficulty              |
| `setDifficulty(self, difficulty: CaptchaDifficulty)`   | Set the captcha difficulty                      |
| `isPassed(self)`                                       | Has the captcha been completed?                 |
| `setPassed(self, passed: bool)`                        | Set the completion status of the captcha        |
| `reset(self)`                                          | Reset the captcha                               |
| `getPopup(self)`                                       | Get the current captcha popup                   |

## Showcase

https://github.com/user-attachments/assets/4a9245ea-3cee-40fd-9457-123a4dc0c58a

## License

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/marcohenning/pyqtcaptcha",
    "name": "pyqtcaptcha",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "python, pyqt, qt, captcha",
    "author": "Marco Henning",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/4f/6b/e238aa3faca5d99103653bcdb5a197304258d878130dd4b042304fb203c8/pyqtcaptcha-1.0.0.tar.gz",
    "platform": null,
    "description": "\r\n# PyQt CAPTCHA\r\n\r\n[![PyPI](https://img.shields.io/badge/pypi-v1.0.0-blue)](https://pypi.org/project/pyqtcaptcha)\r\n[![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/marcohenning/pyqtcaptcha)\r\n[![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/marcohenning/pyqtcaptcha/blob/master/LICENSE)\r\n[![Coverage](https://img.shields.io/badge/coverage-96%25-neon)](https://github.com/marcohenning/pyqtcaptcha)\r\n[![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/marcohenning/pyqtcaptcha)\r\n\r\nA modern and fully customizable CAPTCHA library for PyQt and PySide.\r\n\r\n![main](https://github.com/user-attachments/assets/14af04a6-c953-4038-8121-0c7c91b92f9f)\r\n\r\n## About\r\n\r\nThis library was made to bring CAPTCHA support to PyQt desktop applications. While the measure is mostly used in web applications due to their ease of automation, desktop applications can also be automated using programs like AutoHotkey. This CAPTCHA widget is fully customizable from everything related to visuals to the difficulty of the tasks and helps protect your application from spam and abuse through automation.\r\n\r\n> All images have been sourced from public domain video material and are not subject to copyright restrictions.\r\n\r\n## Installation\r\n\r\n```\r\npip install pyqtcaptcha\r\n```\r\n\r\n## Example\r\n\r\n```python\r\nfrom PyQt6.QtWidgets import QMainWindow\r\nfrom pyqtcaptcha import Captcha, CaptchaDifficulty\r\n\r\n\r\nclass Window(QMainWindow):\r\n    def __init__(self):\r\n        super().__init__(parent=None)\r\n\r\n        self.captcha = Captcha(self)\r\n        self.captcha.setDifficulty(CaptchaDifficulty.HARD)\r\n        self.captcha.setFixedSize(130, 40)\r\n```\r\n\r\n## Documentation\r\n\r\n> **IMPORTANT:** <br>Styling of the widget must not be done by setting the stylesheet manually as the widget calculates the stylesheet itself and overrides it. Use the provided methods such as `setBackgroundColor()` instead.\r\n\r\n* **Setting the difficulty:**\r\n```python\r\ncaptcha.setDifficulty(CaptchaDifficulty.HARD)\r\n```\r\n\r\n> On easy difficulty the user will have to complete image selection tasks (i.e. \"Select all images containing cars\"). On hard difficulty the user will have to select image squares (i.e. \"Select all squares containing traffic lights\"). Medium difficulty alternates between these two options randomly.\r\n\r\n* **Checking the state:**\r\n```python\r\ncaptcha.isPassed()\r\n```\r\n\r\n* **Resetting the state:**\r\n```python\r\ncaptcha.reset()\r\n```\r\n\r\n* **Setting the button text:**\r\n```python\r\ncaptcha.setText('Text')\r\n```\r\n\r\n* **Setting the button foreground color:**\r\n```python\r\ncaptcha.setButtonForegroundColor(QColor(255, 0, 0))\r\n```\r\n\r\n* **Setting the button background color:**\r\n```python\r\ncaptcha.setButtonBackgroundColor(QColor(0, 255, 0))\r\n```\r\n\r\n* **Setting the button border color:**\r\n```python\r\ncaptcha.setButtonBorderColor(QColor(0, 0, 255))\r\n```\r\n\r\n* **Setting the button border width:**\r\n```python\r\ncaptcha.setButtonBorderWidth(1)\r\n```\r\n\r\n* **Setting the button border radius:**\r\n```python\r\ncaptcha.setButtonBorderRadius(5)\r\n```\r\n\r\n* **Setting the checkbox color:**\r\n```python\r\ncaptcha.setCheckboxColor(QColor(255, 255, 0))\r\n```\r\n\r\n* **Setting the checkbox width:**\r\n```python\r\ncaptcha.setCheckboxWidth(2)\r\n```\r\n\r\n> The checkbox width is also used for the width of the checkmark.\r\n\r\n* **Setting the checkmark color:**\r\n```python\r\ncaptcha.setCheckmarkColor(QColor(0, 255, 255))\r\n```\r\n\r\n* **Setting the CAPTCHA popup foreground color:**\r\n```python\r\ncaptcha.setCaptchaForegroundColor(QColor(255, 255, 255))\r\n```\r\n\r\n> The foreground color (white by default) is used for text elements like the captcha prompt and submit button text as well as for the checkmark on selected images.\r\n\r\n* **Setting the CAPTCHA popup background color:**\r\n```python\r\ncaptcha.setCaptchaBackgroundColor(QColor(255, 0, 255))\r\n```\r\n\r\n> The background color (white by default) is used for the background of the popup window.\r\n\r\n* **Setting the CAPTCHA popup border color:**\r\n```python\r\ncaptcha.setCaptchaBorderColor(QColor(100, 255, 0))\r\n```\r\n\r\n* **Setting the CAPTCHA popup border radius:**\r\n```python\r\ncaptcha.setCaptchaBorderRadius(10)\r\n```\r\n\r\n* **Setting the CAPTCHA popup primary color:**\r\n```python\r\ncaptcha.setCaptchaPrimaryColor(QColor(0, 100, 255))\r\n```\r\n\r\n> The primary color (green by default) is used for the background of the captcha prompt and the background of the submit button.\r\n\r\n* **Setting the CAPTCHA popup primary color (hovered):**\r\n```python\r\ncaptcha.setCaptchaPrimaryColorHovered(QColor(255, 100, 0))\r\n```\r\n\r\n> The primary hovered color (light-green by default) is used for the hovered background of the submit button.\r\n\r\n* **Setting the CAPTCHA popup secondary color:**\r\n```python\r\ncaptcha.setCaptchaSecondaryColor(QColor(255, 255, 100))\r\n```\r\n\r\n> The secondary color (gray by default) is used for elements like the refresh button, visual button, audio button and play button.\r\n\r\n* **Setting the CAPTCHA popup secondary color (hovered):**\r\n```python\r\ncaptcha.setCaptchaSecondaryColorHovered(QColor(0, 255, 50))\r\n```\r\n\r\n> The secondary hovered color (dark-gray by default) is used as the hover color for elements like the refresh button, visual button, audio button and play button.\r\n\r\n* **Connecting methods to the provided events:**\r\n```python\r\ncaptcha.started.connect(self.some_function)\r\ncaptcha.aborted.connect(self.some_function)\r\ncaptcha.passed.connect(self.some_function)\r\ncaptcha.failed.connect(self.some_function)\r\n```\r\n\r\n> The `started` signal is emitted every time the popup window gets opened, while the `aborted` signal is emitted every time the popup window gets closed without submitting an answer. When the submit button is pressed either the `passed` signal or the `failed` signal is emitted depending on the correctness of the answer.\r\n\r\n**<br>All available 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| `getButtonForegroundColor(self)`                       | Get the current button foreground color         |\r\n| `setButtonForegroundColor(self, color: QColor)`        | Set the button foreground color                 |\r\n| `getButtonBackgroundColor(self)`                       | Get the current button background color         |\r\n| `setButtonBackgroundColor(self, color: QColor)`        | Set the button background color                 |\r\n| `getButtonBorderColor(self)`                           | Get the current button border color             |\r\n| `setButtonBorderColor(self, color: QColor)`            | Set the button border color                     |\r\n| `getButtonBorderWidth(self)`                           | Get the current button border width             |\r\n| `setButtonBorderWidth(self, width: int)`               | Set the button border width                     |\r\n| `getButtonBorderRadius(self)`                          | Get the current button border radius            |\r\n| `setButtonBorderRadius(self, radius: int)`             | Set the button border radius                    |\r\n| `getCheckboxColor(self)`                               | Get the current checkbox color                  |\r\n| `setCheckboxColor(self, color: QColor)`                | Set the checkbox color                          |\r\n| `getCheckboxWidth(self)`                               | Get the current checkbox width                  |\r\n| `setCheckboxWidth(self, width: int)`                   | Set the checkbox width                          |\r\n| `getCheckmarkColor(self)`                              | Get the current checkmark color                 |\r\n| `setCheckmarkColor(self, color: QColor)`               | Set the checkmark color                         |\r\n| `getCaptchaForegroundColor(self)`                      | Get the current captcha foreground color        |\r\n| `setCaptchaForegroundColor(self, color: QColor)`       | Set the captcha foreground color                |\r\n| `getCaptchaBackgroundColor(self)`                      | Get the current captcha background color        |\r\n| `setCaptchaBackgroundColor(self, color: QColor)`       | Set the captcha background color                |\r\n| `getCaptchaBorderColor(self)`                          | Get the current captcha border color            |\r\n| `setCaptchaBorderColor(self, color: QColor)`           | Set the captcha border color                    |\r\n| `getCaptchaBorderRadius(self)`                         | Get the current captcha border radius           |\r\n| `setCaptchaBorderRadius(self, radius: int)`            | Set the captcha border radius                   |\r\n| `getCaptchaPrimaryColor(self)`                         | Get the current captcha primary color           |\r\n| `setCaptchaPrimaryColor(self, color: QColor)`          | Set the captcha primary color                   |\r\n| `getCaptchaPrimaryColorHovered(self)`                  | Get the current captcha primary hovered color   |\r\n| `setCaptchaPrimaryColorHovered(self, color: QColor)`   | Set the captcha primary hovered color           |\r\n| `getCaptchaSecondaryColor(self)`                       | Get the current captcha secondary color         |\r\n| `setCaptchaSecondaryColor(self, color: QColor)`        | Set the captcha secondary color                 |\r\n| `getCaptchaSecondaryColorHovered(self)`                | Get the current captcha secondary hovered color |\r\n| `setCaptchaSecondaryColorHovered(self, color: QColor)` | Set the captcha secondary hovered color         |\r\n| `getDifficulty(self)`                                  | Get the current captcha difficulty              |\r\n| `setDifficulty(self, difficulty: CaptchaDifficulty)`   | Set the captcha difficulty                      |\r\n| `isPassed(self)`                                       | Has the captcha been completed?                 |\r\n| `setPassed(self, passed: bool)`                        | Set the completion status of the captcha        |\r\n| `reset(self)`                                          | Reset the captcha                               |\r\n| `getPopup(self)`                                       | Get the current captcha popup                   |\r\n\r\n## Showcase\r\n\r\nhttps://github.com/user-attachments/assets/4a9245ea-3cee-40fd-9457-123a4dc0c58a\r\n\r\n## License\r\n\r\nThis software is licensed under the [MIT license](https://github.com/marcohenning/pyqtcaptcha/blob/master/LICENSE).\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A modern and fully customizable CAPTCHA library for PyQt and PySide",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/marcohenning/pyqtcaptcha"
    },
    "split_keywords": [
        "python",
        " pyqt",
        " qt",
        " captcha"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1419d459f88c738bf323eeab4bf49913f0d7d819ae8219d1119d139d8bbd570b",
                "md5": "6e29e16fec148e78eddd538bc41b0871",
                "sha256": "1b884b961a9b049da74e1470a11a9808da87d6c170521f2564089e94b57959a2"
            },
            "downloads": -1,
            "filename": "pyqtcaptcha-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6e29e16fec148e78eddd538bc41b0871",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 29088590,
            "upload_time": "2024-10-21T22:15:09",
            "upload_time_iso_8601": "2024-10-21T22:15:09.164571Z",
            "url": "https://files.pythonhosted.org/packages/14/19/d459f88c738bf323eeab4bf49913f0d7d819ae8219d1119d139d8bbd570b/pyqtcaptcha-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4f6be238aa3faca5d99103653bcdb5a197304258d878130dd4b042304fb203c8",
                "md5": "bd8962973f714cb4c9bae141434b3ad9",
                "sha256": "e99d8aa09fbd9c38586be9b256e77cd14dd364780aabf9f85c53305ef5b77bf5"
            },
            "downloads": -1,
            "filename": "pyqtcaptcha-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bd8962973f714cb4c9bae141434b3ad9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 28638462,
            "upload_time": "2024-10-21T22:16:03",
            "upload_time_iso_8601": "2024-10-21T22:16:03.351527Z",
            "url": "https://files.pythonhosted.org/packages/4f/6b/e238aa3faca5d99103653bcdb5a197304258d878130dd4b042304fb203c8/pyqtcaptcha-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 22:16:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcohenning",
    "github_project": "pyqtcaptcha",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "requirements": [
        {
            "name": "QtPy",
            "specs": [
                [
                    ">=",
                    "2.4.1"
                ]
            ]
        },
        {
            "name": "pygame",
            "specs": [
                [
                    ">=",
                    "2.6.0"
                ]
            ]
        }
    ],
    "lcname": "pyqtcaptcha"
}
        
Elapsed time: 0.34096s