input

Widgets for representing input widgets for different types.

The metaclass {class}`.Input` represents the basic structure, which each of the inheriting classes override. Subclasses can be retrieved and instantiated with the overloaded from_type() method:

# retrieve the class
int_input_class = Input.from_type(int)
# instantiate the class -- some subtypes (see :class:`.LiteralInput` ) need arguments on instantiation.
int_input = int_input_class()

and can then be used to make and manipulate Qt Widgets:

# make the literal ``QWidget`` to be used
widget = int_input.make()
# get/set the value of the created widget
value = int_input.value()
int_input.setValue(value)

This allows the ModelWidget class to provide a uniform interface to fill end edit models.

Classes:

Input([args, kwargs, range])

Metaclass to parametrically spawn a Qt Input widget for a given type.

BoolInput([args, kwargs, range])

IntInput([args, kwargs, range])

FloatInput([args, kwargs, range])

StrInput([args, kwargs, range])

DatetimeInput([args, kwargs, range])

ListInput([args, kwargs, range])

DictInput([args, kwargs, range])

LiteralInput(choices[, default])

class Input(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: ABC

Metaclass to parametrically spawn a Qt Input widget for a given type.

Primarily for the purpose of making a unified widget creation and value retreival syntax within the ModelWidget class

widget: ClassVar[Type[QWidget]] = None

The widget that is made with the make() method

validator: ClassVar[Type[QValidator] | None] = None

The validator applied to the input widget

method_calls: ClassVar[List[Tuple[str, List]] | None] = None

Names of methods to call after instantiation, passed as a tuple of (method_name, [method_args])

python_type: ClassVar[Type]

The python type that this input provides interface for

permissiveness: ClassVar[int] = 0

When a type is annotated with a Union, the more permissive (higher number) one will be chosen. Arbitrary units.

args: list | None = FieldInfo(default=PydanticUndefined, default_factory=<class 'list'>, extra={})

Args to pass to the widget on creation

kwargs: dict | None = FieldInfo(default=PydanticUndefined, default_factory=<class 'dict'>, extra={})

Kwargs to pass to the widget on creation

range: Tuple[int | float, int | float] | None = None

Limit numerical types to a specific range

classmethod from_type(type_: Type[bool]) Type[BoolInput][source]
classmethod from_type(type_: Type[int]) Type[IntInput]
classmethod from_type(type_: Type[float]) Type[FloatInput]
classmethod from_type(type_: Type[str]) Type[StrInput]
classmethod from_type(type_: Type[datetime]) Type[DatetimeInput]
classmethod from_type(type_: Type[list]) Type[ListInput]

Get a subclass of Input that represents a given type.

Parameters:

type_ (typing.Type) – The type (eg. float, int) to be represented

Returns:

An appropriate Input subclass

Raises:

ValueError

abstract setValue(value: Any)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

abstract value() Any[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

make(widget_kwargs: dict | None = None, validator_kwargs: dict | None = None) QWidget[source]

Make the appropriate widget for this input.

Stores the made widget in the private _widget attr, which is then used in subsequent Input.value() and Input.setValue() calls.

Parameters:
  • widget_kwargs (dict) – Optional: kwargs given to the widget on instantiation

  • validator_kwargs (dict) – Optional: kwargs given to the validator on instantiation

Returns:

Subclass of QWidget according to Input type

Return type:

PySide6.QtWidgets.QWidget

class BoolInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QCheckBox

python_type

alias of bool

setValue(value: bool)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() bool[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class IntInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QLineEdit

validator

alias of QIntValidator

permissiveness: ClassVar[int] = 1

When a type is annotated with a Union, the more permissive (higher number) one will be chosen. Arbitrary units.

python_type

alias of int

setValue(value: int)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() int | None[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class FloatInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QLineEdit

validator

alias of QIntValidator

permissiveness: ClassVar[int] = (2,)

When a type is annotated with a Union, the more permissive (higher number) one will be chosen. Arbitrary units.

python_type

alias of float

setValue(value: float)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() float | None[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class StrInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QLineEdit

permissiveness: ClassVar[int] = 3

When a type is annotated with a Union, the more permissive (higher number) one will be chosen. Arbitrary units.

python_type

alias of str

setValue(value: str)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() str[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class DatetimeInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QDateTimeEdit

method_calls: ClassVar[List[Tuple[str, List]] | None] = [('setCalendarPopup', [True])]

Names of methods to call after instantiation, passed as a tuple of (method_name, [method_args])

python_type

alias of datetime

setValue(value: datetime)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() datetime[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class ListInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QLineEdit

python_type

alias of list

setValue(value: list)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() list[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class DictInput(args: list | None = None, kwargs: dict | None = None, range: Tuple[int | float, int | float] | None = None)[source]

Bases: Input

widget

alias of QLineEdit

python_type

alias of dict

setValue(value: dict)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() dict[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.

class LiteralInput(choices: list, default: Any | None = None, **kwargs)[source]

Bases: Input

widget

alias of QComboBox

python_type(*args, **kwds): ClassVar[Type] = typing.Literal

The python type that this input provides interface for

choices: list

Args are not optional for literal input types

default: Any | None = None

If one of the entries in the literal type should be default, set this on widget creation

make(widget_kwargs: dict | None = None, validator_kwargs: dict | None = None) QComboBox[source]

Call the superclass make method, but then set the options for the combobox based on our LiteralInput.args attribute.

Parameters:
  • widget_kwargs (dict) – Optional: kwargs given to the widget on instantiation

  • validator_kwargs (dict) – Optional: kwargs given to the validator on instantiation

Returns:

PySide6.QtWidgets.QComboBox

setValue(value: Any)[source]

Set a value in the created widget

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then allows its value to be set, doing appropriate type conversions and invoking the correct methods.

value() Any[source]

Retrieve the value from the widget!

After the Input.make() method is called, returning a widget, the Input instance will store a reference to it. This method then returns the value, doing appropriate type conversion.