model

Widget to fill fields for a pydantic model

Classes:

ModelWidget(model[, optional, scroll])

Recursive collection of all inputs for a given model.

ListModelWidget(model[, optional, scroll])

Container class to make lists of ModelWidget s for when a field is a List

Model_Filler_Dialogue(self, /[, parent, f, ...])

Dialogue wrapper around ModelWidget

class ModelWidget(model: BaseModel | Type[BaseModel], optional: bool = False, scroll: bool = True, **kwargs)[source]

Bases: QWidget

Recursive collection of all inputs for a given model.

Each attribute that has a single Input (eg. a single number, string, and so on) that can be resolved by resolve_type() is represented by a Model_Input.

Otherwise, attributes that are themselves other models are recursively added additional ModelWidget s.

When a model’s field is typing.Optional, passed as ModelWidget.optional , The groupbox for the model has a checkbox. When it is unchecked, the model fields are inactive and it is returned by ModelWidget.value() as None. (Shouldn’t be used with a top-level model.)

Parameters:
  • model (pydantic.BaseModel) – The model to represent. Can either be a model class or an instantiated model. If an instantiated model, the fields are filled with the current values.

  • optional (bool) – If True, the enclosing groupbox has a checkbox that when unchecked causes ModelWidget.value() to return None. If False, ModelWidget.value() always attempts to return the model

  • scroll (bool) – Whether the widget should be within a scrollbar. True by default, but should probably be False for child models.

  • **kwargs – passed to superclass

Methods:

setValue(model)

Set all values of the form given an instantiated model.

value()

Return an instance of the model populated with values from dict()

dict()

Return a (recursive) dictionary of all current model values.

validate([kwargs, dialog])

Test whether the given inputs pass model validation, and if not return which fail

Attributes:

checked

If self.optional, whether or not this widget is checked/enabled.

staticMetaObject

inputs
setValue(model: BaseModel | dict)[source]

Set all values of the form given an instantiated model.

To set values of individual inputs, use Input.setValue()

value() ['BaseModel', None][source]

Return an instance of the model populated with values from dict()

If model fails to validate, pop a dialog with the validation errors and return None (see validate())

Returns:

pydantic.BaseModel of the type specified in ModelWidget.model

dict() dict | None[source]

Return a (recursive) dictionary of all current model values.

Returns:

dict None: if model is optional and unchecked.

property checked: bool

If self.optional, whether or not this widget is checked/enabled.

If not self.optional, returns True (since it is required, it is always enabled)

Returns:

bool

validate(kwargs: dict | None = None, dialog: bool = False) List[dict] | Autopilot_Type | BaseModel[source]

Test whether the given inputs pass model validation, and if not return which fail

Parameters:

dialog (bool) – Whether or not to pop a dialogue showing which fields failed to validate

staticMetaObject = PySide6.QtCore.QMetaObject("ModelWidget" inherits "QWidget": )
class ListModelWidget(model: BaseModel | Type[BaseModel], optional: bool = False, scroll: bool = True, **kwargs)[source]

Bases: QWidget

Container class to make lists of ModelWidget s for when a field is a List

Parameters:
  • model (pydantic.BaseModel) – The model to represent. Can either be a model class or an instantiated model. If an instantiated model, the fields are filled with the current values.

  • optional (bool) – If True, the enclosing groupbox has a checkbox that when unchecked causes ModelWidget.value() to return None. If False, ModelWidget.value() always attempts to return the model

  • scroll (bool) – Whether the widget should be within a scrollbar. True by default, but should probably be False for child models

  • **kwargs

Variables:
  • model_layout (QVBoxLayout) – Layout containing model widgets

  • add_button (QPushButton) – Button pressed to add new models

  • remove_button (QPushButton) – Button pressed to remove the bottom-most model

Methods:

dict()

Sort of a misnomer, but return a list of dictionaries that contain the values to be used in the model

value()

A list of instantiated models

add_model([checked, model])

When the add_button is pressed, add an additional ModelWidget

remove_model([checked])

When the remove_button is pressed, remove the last-added ModelWidget

setValue(value)

Create and set values for a list of instantiated data models.

Attributes:

staticMetaObject

model_widgets
dict() List[dict][source]

Sort of a misnomer, but return a list of dictionaries that contain the values to be used in the model

value() List[BaseModel][source]

A list of instantiated models

add_model(checked: bool = False, model: BaseModel | None = None)[source]

When the add_button is pressed, add an additional ModelWidget

Parameters:
  • checked (bool) – Whether the button is checked (from the clicked signal)

  • model (pydantic.BaseModel) – Manually override the model to construct. (default is to use the .model attribute)

remove_model(checked: bool = False)[source]

When the remove_button is pressed, remove the last-added ModelWidget

Parameters:

checked (bool) – Whether the button is checked (from the clicked signal)

setValue(value: List[BaseModel])[source]

Create and set values for a list of instantiated data models.

First clears any existing models that have been made.

Parameters:

value (list[BaseModel]) – List of instantiated base models.

staticMetaObject = PySide6.QtCore.QMetaObject("ListModelWidget" inherits "QWidget": )
class Model_Filler_Dialogue(self, /, parent: PySide6.QtWidgets.QWidget | None = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags), *, sizeGripEnabled: bool | None = None, modal: bool | None = None)[source]

Bases: QDialog

Dialogue wrapper around ModelWidget

Initialize self. See help(type(self)) for accurate signature.

Attributes:

staticMetaObject

staticMetaObject = PySide6.QtCore.QMetaObject("Model_Filler_Dialogue" inherits "QDialog": )