protocol

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(model, **kwargs)

Dialogue wrapper around ModelWidget

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 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

Attributes:

inputs

checked

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

staticMetaObject

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 in ModelWidget.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, returns True (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.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

Attributes:

model_widgets

staticMetaObject

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.

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[pydantic.main.BaseModel][source]

A list of instantiated models

add_model(checked: bool = False, model: Optional[pydantic.main.BaseModel] = 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[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.QDialog

Dialogue wrapper around ModelWidget

Attributes:

staticMetaObject

staticMetaObject = <PySide2.QtCore.QMetaObject object at 0x7fa122cfcd80>