Skip to main content

pydantic powered forms for Qt

Project description

mikro

codecov PyPI version Maintenance Maintainer PyPI pyversions PyPI status PyPI download month

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtforms-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

qtforms-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file qtforms-0.1.0.tar.gz.

File metadata

  • Download URL: qtforms-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.6 Linux/6.2.0-34-generic

File hashes

Hashes for qtforms-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ecbeba933a095ac67b5fd6f09ada55ba9214fe843bc24346be07620a92ac2672
MD5 aecd74ad4763f4bd6201df83cd20fd46
BLAKE2b-256 67b28c810155a89b39d1af94a94c1d3da56e3d0842444d720bffd3690272e3ae

See more details on using hashes here.

File details

Details for the file qtforms-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qtforms-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.6 Linux/6.2.0-34-generic

File hashes

Hashes for qtforms-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb37c12f861802a4179a12cabd44d7815228d0e7f32702ccb0bf169b40ba745f
MD5 547d13b7c0391c233beaf56761117c48
BLAKE2b-256 dda86bd9a3af276a7d4cd1afbd32bba639cf2c959edfb6f884314bc769b1410e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page