model
Widget to fill fields for a pydantic model
Classes:
|
Recursive collection of all inputs for a given model. |
|
Container class to make lists of |
|
Dialogue wrapper around |
- class ModelWidget(model: BaseModel | Type[BaseModel], optional: bool = False, scroll: bool = True, **kwargs)[source]
Bases:
QWidgetRecursive 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 byresolve_type()is represented by aModel_Input.Otherwise, attributes that are themselves other models are recursively added additional
ModelWidgets.When a model’s field is
typing.Optional, passed asModelWidget.optional, The groupbox for the model has a checkbox. When it is unchecked, the model fields are inactive and it is returned byModelWidget.value()asNone. (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 causesModelWidget.value()to returnNone. IfFalse,ModelWidget.value()always attempts to return the modelscroll (bool) – Whether the widget should be within a scrollbar.
Trueby default, but should probably beFalsefor 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:
If
self.optional, whether or not this widget is checked/enabled.- 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.BaseModelof the type specified inModelWidget.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, returnsTrue(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:
QWidgetContainer class to make lists of
ModelWidgets for when a field is aList- 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 causesModelWidget.value()to returnNone. IfFalse,ModelWidget.value()always attempts to return the modelscroll (bool) – Whether the widget should be within a scrollbar.
Trueby default, but should probably beFalsefor child models**kwargs
- Variables:
model_layout (
QVBoxLayout) – Layout containing model widgetsadd_button (
QPushButton) – Button pressed to add new modelsremove_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_buttonis pressed, add an additionalModelWidgetremove_model([checked])When the
remove_buttonis pressed, remove the last-addedModelWidgetsetValue(value)Create and set values for a list of instantiated data models.
Attributes:
- 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
- add_model(checked: bool = False, model: BaseModel | None = None)[source]
When the
add_buttonis pressed, add an additionalModelWidget- Parameters:
checked (bool) – Whether the button is checked (from the
clickedsignal)model (
pydantic.BaseModel) – Manually override the model to construct. (default is to use the.modelattribute)
- remove_model(checked: bool = False)[source]
When the
remove_buttonis pressed, remove the last-addedModelWidget- Parameters:
checked (bool) – Whether the button is checked (from the
clickedsignal)
- 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))[source]
Bases:
QDialogDialogue wrapper around
ModelWidgetInitialize self. See help(type(self)) for accurate signature.
Attributes:
- staticMetaObject = PySide6.QtCore.QMetaObject("Model_Filler_Dialogue" inherits "QDialog": )