mikro
qtforms is a library that allows you to create simple forms in Qt for Python with the help of pydantic.
Installation
pip install qtforms
Quick Start
from qtpy import QtWidgets
from pydantic import BaseModel, validator, Field
import sys
from qtforms.labeled_registry import LabeledWidgetRegistry
from qtforms.form import Form
class MyModel(BaseModel):
name: str = Field("hundi", min_length=3, max_length=50, description="Your name")
number: int = Field(1, ge=0, le=100, description="A number between 0 and 100")
@validator("name")
def name_must_contain_space(cls, v):
if " " not in v:
raise ValueError("Name must have a space")
return v.title()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
model = MyModel(name="hello world")
##model.events.name.connect(lambda x: print(x))
form = Form(LabeledWidgetRegistry(), MyModel, initial_data=dict(name="hello world"), auto_validate=True)
form.submit.connect(lambda x: print(x))
form.show()
sys.exit(app.exec_())
Design
For the design of qtform, we use the following design:
Form is the container and controller for the form. It calls the widget registry to spawn the widgets for the fields.
These widgets need to follow the FormWidget interface, and implement functions to set values and report errors.
Form also handles the validation of the form, and emits a submit signal when the form is valid and the submit button is pressed
(or when auto_submit is enabled on each valid change). Validation is done by pydantic, and the validated values are immediately
reported to the widgets.
Release files for qtforms 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 | |
|---|---|---|---|
| qtforms-0.1.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qtforms-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:12.1 kB
Release files / qtforms-0.1.0.tar.gz
| Download URL | qtforms-0.1.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ecbeba933a095ac67b5fd6f09ada55ba9214fe843bc24346be07620a92ac2672
|
|
BLAKE2b-256 checksum How to use checksums |
67b28c810155a89b39d1af94a94c1d3da56e3d0842444d720bffd3690272e3ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.6 Linux/6.2.0-34-generic
|
Release files / qtforms-0.1.0-py3-none-any.whl
| Download URL | qtforms-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb37c12f861802a4179a12cabd44d7815228d0e7f32702ccb0bf169b40ba745f
|
|
BLAKE2b-256 checksum How to use checksums |
dda86bd9a3af276a7d4cd1afbd32bba639cf2c959edfb6f884314bc769b1410e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.6 Linux/6.2.0-34-generic
|