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: Union[pydantic.main.BaseModel, Type[pydantic.main.BaseModel]], optional: bool = False, scroll: bool = True, **kwargs)[source]
Bases:
PySide2.QtWidgets.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: Union[pydantic.main.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() Optional[dict][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: Optional[autopilot.gui.widgets.model.ModelWidget.dict] = None, dialog: bool = False) Union[List[autopilot.gui.widgets.model.ModelWidget.dict], autopilot.root.Autopilot_Type, pydantic.main.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 = <PySide2.QtCore.QMetaObject object at 0x7fa122cfca40>
- class ListModelWidget(model: Union[pydantic.main.BaseModel, Type[pydantic.main.BaseModel]], optional: bool = False, scroll: bool = True, **kwargs)[source]
Bases:
PySide2.QtWidgets.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: Optional[pydantic.main.BaseModel] = 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[pydantic.main.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 = <PySide2.QtCore.QMetaObject object at 0x7fa122cfca00>
- class Model_Filler_Dialogue(model: Union[Type[autopilot.root.Autopilot_Type], Type[pydantic.main.BaseModel]], **kwargs)[source]
Bases:
PySide2.QtWidgets.QDialogDialogue wrapper around
ModelWidgetAttributes:
- staticMetaObject = <PySide2.QtCore.QMetaObject object at 0x7fa122cfcd80>