qtier
Cuter approach to Qt-for-python, with focus on type hints, JSON APIs and QML.
Example Usage:
The following example shows how qtier can be used to query a graphql service. models.py
from qtier.itemsystem import role, define_roles
@define_roles
class Worm:
name: str = role()
family: str = role()
size: int = role()
@define_roles
class Apple:
size: int = role()
owner: str = role()
color: str = role()
# nested models are also supported!
worms: Worm = role(default=None)
qtier will create for you QAbstractListModel to be used in QML you only need to
define your models with define_roles.
qtier initializes the data with a dict, in this case coming from graphql service.
main.py
import glob
import os
import sys
from pathlib import Path
from qtpy.QtQml import QQmlApplicationEngine
from qtpy.QtCore import QObject, Signal
from qtpy import QtCore, QtGui, QtQml, QtQuick
from qtier import slot
from qtier.gql.client import HandlerProto, GqlClientMessage, GqlWsTransportClient
from qtier.itemsystem import GenericModel
from tests.test_sample_ui.models import Apple
class EntryPoint(QObject):
class AppleHandler(HandlerProto):
message = GqlClientMessage.from_query(
"""
query MyQuery {
apples {
color
owner
size
worms {
family
name
size
}
}
}
"""
)
def __init__(self, app: 'EntryPoint'):
self.app = app
def on_data(self, message: dict) -> None:
self.app.apple_model.initialize_data(message['apples'])
def on_error(self, message: dict) -> None:
print(message)
def on_completed(self, message: dict) -> None:
print(message)
def __init__(self, parent=None):
super().__init__(parent)
main_qml = Path(__file__).parent / 'qml' / 'main.qml'
QtGui.QFontDatabase.addApplicationFont(str(main_qml.parent / 'materialdesignicons-webfont.ttf'))
self.qml_engine = QQmlApplicationEngine()
self.gql_client = GqlWsTransportClient(url='ws://localhost:8080/graphql')
self.apple_query_handler = self.AppleHandler(self)
self.gql_client.query(self.apple_query_handler)
self.apple_model: GenericModel[Apple] = Apple.Model()
QtQml.qmlRegisterSingletonInstance(EntryPoint, "com.props", 1, 0, "EntryPoint", self) # type: ignore
# for some reason the app won't initialize without this event processing here.
QtCore.QEventLoop().processEvents(QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 1000)
self.qml_engine.load(str(main_qml.resolve()))
@QtCore.Property(QtCore.QObject, constant=True)
def appleModel(self) -> GenericModel[Apple]:
return self.apple_model
def main():
app = QtGui.QGuiApplication(sys.argv)
ep = EntryPoint() # noqa: F841, this collected by the gc otherwise.
ret = app.exec()
sys.exit(ret)
if __name__ == "__main__":
main()
Metadata
Release files for qtier 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qtier-0.1.0.tar.gz | 12.7 kB | Without provenance | Details for qtier-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qtier-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for qtier-0.1.0-py3-none-any.whl |
Total release size: 26.2 kB
Release files / qtier-0.1.0.tar.gz
| Download URL | qtier-0.1.0.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf4173c199ce024f112be20dda1c90bf3efda6c7cc0c6f8ba2cc5d197dbc5bd2
|
|
BLAKE2b-256 checksum How to use checksums |
c2576be01f90f60a295f1cbe8ad2662851da520f2d55e74661efb39f4af42c24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-56-generic
|
Release files / qtier-0.1.0-py3-none-any.whl
| Download URL | qtier-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9428d532acd842db24226348e6e497f3cb07fe15bc929106b5fbe7a351236f0
|
|
BLAKE2b-256 checksum How to use checksums |
111876fa109b3906dff928d8f2e85542a3b898726e3c067ffd775f9efc3b8a2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-56-generic
|
Security for qtier 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.