Name | qtinter JSON |
Version |
0.11.0
JSON |
| download |
home_page | |
Summary | Interop between asyncio and Qt for Python |
upload_time | 2022-12-16 02:56:27 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | |
keywords |
asyncio
coroutine
qt
signal
slot
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# qtinter — Interop between asyncio and Qt for Python
[![codecov](https://codecov.io/gh/fancidev/qtinter/branch/master/graph/badge.svg?token=JZ5ON6CHKA)](https://codecov.io/gh/fancidev/qtinter)
[![docs](https://readthedocs.org/projects/qtinter/badge/?version=latest)](https://qtinter.readthedocs.io/en/latest/?badge=latest)
[![tests](https://github.com/fancidev/qtinter/actions/workflows/tests.yml/badge.svg)](https://github.com/fancidev/qtinter/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/qtinter)](https://pypi.org/project/qtinter/)
`qtinter` is a Python module that brings together asyncio and Qt
for Python, allowing you to use one from the other seamlessly.
Read the [full documentation](https://qtinter.readthedocs.io) or check out the quickstart below.
## Installation
```commandline
$ pip install qtinter
```
## Using asyncio from Qt
To use asyncio-based libraries in Qt for Python, enclose `app.exec()`
inside context manager `qtinter.using_asyncio_from_qt()`.
Example (taken from `examples/clock.py`):
```Python
"""Display LCD-style digital clock"""
import asyncio
import datetime
import qtinter # <-- import module
from PySide6 import QtWidgets
class Clock(QtWidgets.QLCDNumber):
def __init__(self, parent=None):
super().__init__(parent)
self.setDigitCount(8)
def showEvent(self, event):
self._task = asyncio.create_task(self._tick())
def hideEvent(self, event):
self._task.cancel()
async def _tick(self):
while True:
t = datetime.datetime.now()
self.display(t.strftime("%H:%M:%S"))
await asyncio.sleep(1.0 - t.microsecond / 1000000 + 0.05)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
widget = Clock()
widget.setWindowTitle("qtinter - Digital Clock example")
widget.resize(300, 50)
with qtinter.using_asyncio_from_qt(): # <-- enable asyncio in qt code
widget.show()
app.exec()
```
## Using Qt from asyncio
To use Qt components from asyncio-based code, enclose the asyncio
entry-point inside context manager `qtinter.using_qt_from_asyncio()`.
Example (taken from `examples/color.py`):
```Python
"""Display the RGB code of a color chosen by the user"""
import asyncio
import qtinter # <-- import module
from PySide6 import QtWidgets
async def choose_color():
dialog = QtWidgets.QColorDialog()
dialog.show()
future = asyncio.Future()
dialog.finished.connect(future.set_result)
result = await future
if result == QtWidgets.QDialog.DialogCode.Accepted:
return dialog.selectedColor().name()
else:
return None
if __name__ == "__main__":
app = QtWidgets.QApplication([])
with qtinter.using_qt_from_asyncio(): # <-- enable qt in asyncio code
color = asyncio.run(choose_color())
if color is not None:
print(color)
```
## Using modal dialogs
To execute a modal dialog without blocking the asyncio event loop,
wrap the dialog entry-point in `qtinter.modal()` and `await` on it.
Example (taken from `examples/hit_100.py`):
```Python
import asyncio
import qtinter
from PySide6 import QtWidgets
async def main():
async def counter():
nonlocal n
while True:
print(f"\r{n}", end='', flush=True)
await asyncio.sleep(0.025)
n += 1
n = 0
counter_task = asyncio.create_task(counter())
await qtinter.modal(QtWidgets.QMessageBox.information)(
None, "Hit 100", "Click OK when you think you hit 100.")
counter_task.cancel()
if n == 100:
print("\nYou did it!")
else:
print("\nTry again!")
if __name__ == "__main__":
app = QtWidgets.QApplication([])
with qtinter.using_qt_from_asyncio():
asyncio.run(main())
```
## Requirements
`qtinter` supports the following:
- Python version: 3.7 or higher
- Qt binding: PyQt5, PyQt6, PySide2, PySide6
- Operating system: Linux, MacOS, Windows
## License
BSD License.
## Contributing
Please raise an issue if you have any questions. Pull requests are more
than welcome!
## Credits
`qtinter` is derived from
[qasync](https://github.com/CabbageDevelopment/qasync) but rewritten from
scratch. qasync is derived from
[asyncqt](https://github.com/gmarull/asyncqt), which is derived from
[quamash](https://github.com/harvimt/quamash).
Raw data
{
"_id": null,
"home_page": "",
"name": "qtinter",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "asyncio,coroutine,qt,signal,slot",
"author": "",
"author_email": "fancidev <fancidev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a8/77/617f55a7b73391b0d5387bf38074c5c231f782d4cbc4f8839a46588ce319/qtinter-0.11.0.tar.gz",
"platform": null,
"description": "# qtinter \u2014 Interop between asyncio and Qt for Python\n\n[![codecov](https://codecov.io/gh/fancidev/qtinter/branch/master/graph/badge.svg?token=JZ5ON6CHKA)](https://codecov.io/gh/fancidev/qtinter)\n[![docs](https://readthedocs.org/projects/qtinter/badge/?version=latest)](https://qtinter.readthedocs.io/en/latest/?badge=latest)\n[![tests](https://github.com/fancidev/qtinter/actions/workflows/tests.yml/badge.svg)](https://github.com/fancidev/qtinter/actions/workflows/tests.yml)\n[![PyPI](https://img.shields.io/pypi/v/qtinter)](https://pypi.org/project/qtinter/)\n\n`qtinter` is a Python module that brings together asyncio and Qt\nfor Python, allowing you to use one from the other seamlessly.\n\nRead the [full documentation](https://qtinter.readthedocs.io) or check out the quickstart below.\n\n## Installation\n\n```commandline\n$ pip install qtinter\n```\n\n## Using asyncio from Qt\n\nTo use asyncio-based libraries in Qt for Python, enclose `app.exec()`\ninside context manager `qtinter.using_asyncio_from_qt()`.\n\nExample (taken from `examples/clock.py`):\n\n```Python\n\"\"\"Display LCD-style digital clock\"\"\"\n\nimport asyncio\nimport datetime\nimport qtinter # <-- import module\nfrom PySide6 import QtWidgets\n\nclass Clock(QtWidgets.QLCDNumber):\n def __init__(self, parent=None):\n super().__init__(parent)\n self.setDigitCount(8)\n\n def showEvent(self, event):\n self._task = asyncio.create_task(self._tick())\n\n def hideEvent(self, event):\n self._task.cancel()\n\n async def _tick(self):\n while True:\n t = datetime.datetime.now()\n self.display(t.strftime(\"%H:%M:%S\"))\n await asyncio.sleep(1.0 - t.microsecond / 1000000 + 0.05)\n\nif __name__ == \"__main__\":\n app = QtWidgets.QApplication([])\n\n widget = Clock()\n widget.setWindowTitle(\"qtinter - Digital Clock example\")\n widget.resize(300, 50)\n\n with qtinter.using_asyncio_from_qt(): # <-- enable asyncio in qt code\n widget.show()\n app.exec()\n```\n\n## Using Qt from asyncio\n\nTo use Qt components from asyncio-based code, enclose the asyncio\nentry-point inside context manager `qtinter.using_qt_from_asyncio()`.\n\nExample (taken from `examples/color.py`):\n\n```Python\n\"\"\"Display the RGB code of a color chosen by the user\"\"\"\n\nimport asyncio\nimport qtinter # <-- import module\nfrom PySide6 import QtWidgets\n\nasync def choose_color():\n dialog = QtWidgets.QColorDialog()\n dialog.show()\n future = asyncio.Future()\n dialog.finished.connect(future.set_result)\n result = await future\n if result == QtWidgets.QDialog.DialogCode.Accepted:\n return dialog.selectedColor().name()\n else:\n return None\n\nif __name__ == \"__main__\":\n app = QtWidgets.QApplication([])\n with qtinter.using_qt_from_asyncio(): # <-- enable qt in asyncio code\n color = asyncio.run(choose_color())\n if color is not None:\n print(color)\n```\n\n## Using modal dialogs\n\nTo execute a modal dialog without blocking the asyncio event loop,\nwrap the dialog entry-point in `qtinter.modal()` and `await` on it.\n\nExample (taken from `examples/hit_100.py`):\n\n```Python\nimport asyncio\nimport qtinter\nfrom PySide6 import QtWidgets\n\nasync def main():\n async def counter():\n nonlocal n\n while True:\n print(f\"\\r{n}\", end='', flush=True)\n await asyncio.sleep(0.025)\n n += 1\n\n n = 0\n counter_task = asyncio.create_task(counter())\n await qtinter.modal(QtWidgets.QMessageBox.information)(\n None, \"Hit 100\", \"Click OK when you think you hit 100.\")\n counter_task.cancel()\n if n == 100:\n print(\"\\nYou did it!\")\n else:\n print(\"\\nTry again!\")\n\nif __name__ == \"__main__\":\n app = QtWidgets.QApplication([])\n with qtinter.using_qt_from_asyncio():\n asyncio.run(main())\n```\n\n\n## Requirements\n\n`qtinter` supports the following:\n\n- Python version: 3.7 or higher\n- Qt binding: PyQt5, PyQt6, PySide2, PySide6\n- Operating system: Linux, MacOS, Windows\n\n\n## License\n\nBSD License.\n\n\n## Contributing\n\nPlease raise an issue if you have any questions. Pull requests are more\nthan welcome!\n\n\n## Credits\n\n`qtinter` is derived from\n[qasync](https://github.com/CabbageDevelopment/qasync) but rewritten from \nscratch. qasync is derived from \n[asyncqt](https://github.com/gmarull/asyncqt), which is derived from\n[quamash](https://github.com/harvimt/quamash).\n",
"bugtrack_url": null,
"license": "",
"summary": "Interop between asyncio and Qt for Python",
"version": "0.11.0",
"split_keywords": [
"asyncio",
"coroutine",
"qt",
"signal",
"slot"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "243013dee5c6a9b90be7bf813ebd7d16",
"sha256": "0d4814cb2ddffb8138b618f8e95687e2c3144b76f095b5c9e3abe08090d773f1"
},
"downloads": -1,
"filename": "qtinter-0.11.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "243013dee5c6a9b90be7bf813ebd7d16",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 27496,
"upload_time": "2022-12-16T02:56:25",
"upload_time_iso_8601": "2022-12-16T02:56:25.112462Z",
"url": "https://files.pythonhosted.org/packages/6e/0d/0602ee5f941bdf95aa3b53c245ab957565300c966d945bb122b5281bba8a/qtinter-0.11.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "6a2be1afd5d1e74ebb151729e6fe76f3",
"sha256": "0d4d9e4c3c3c6789a19c9b1c2e098491ed36f0a8d106162c2679dd05e460bffd"
},
"downloads": -1,
"filename": "qtinter-0.11.0.tar.gz",
"has_sig": false,
"md5_digest": "6a2be1afd5d1e74ebb151729e6fe76f3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 320215,
"upload_time": "2022-12-16T02:56:27",
"upload_time_iso_8601": "2022-12-16T02:56:27.574380Z",
"url": "https://files.pythonhosted.org/packages/a8/77/617f55a7b73391b0d5387bf38074c5c231f782d4cbc4f8839a46588ce319/qtinter-0.11.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-16 02:56:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "qtinter"
}