protocol
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.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 byresolve_type()
is represented by aModel_Input
.Otherwise, attributes that are themselves other models are recursively added additional
ModelWidget
s.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.
True
by default, but should probably beFalse
for child models.**kwargs – passed to superclass
Attributes:
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
- 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.BaseModel
of 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.
- 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 0x7fa90a2ac3c0>
- class ListModelWidget(model: Union[pydantic.main.BaseModel, Type[pydantic.main.BaseModel]], optional: bool = False, scroll: bool = True, **kwargs)[source]
Bases:
PySide2.QtWidgets.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 causesModelWidget.value()
to returnNone
. IfFalse
,ModelWidget.value()
always attempts to return the modelscroll (bool) – Whether the widget should be within a scrollbar.
True
by default, but should probably beFalse
for 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
Attributes:
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 additionalModelWidget
remove_model
([checked])When the
remove_button
is pressed, remove the last-addedModelWidget
setValue
(value)Create and set values for a list of instantiated data models.
- 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_button
is pressed, add an additionalModelWidget
- 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-addedModelWidget
- Parameters
checked (bool) – Whether the button is checked (from the
clicked
signal)
- 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 0x7fa90a272d00>
- class Model_Filler_Dialogue(model: Union[Type[autopilot.root.Autopilot_Type], Type[pydantic.main.BaseModel]], **kwargs)[source]
Bases:
PySide2.QtWidgets.QDialog
Dialogue wrapper around
ModelWidget
Attributes:
- staticMetaObject = <PySide2.QtCore.QMetaObject object at 0x7fa90a273040>