register_type

magicgui.type_map.register_type(type_: magicgui.type_map._T, *, widget_type: WidgetRef | None = 'None', return_callback: ReturnCallback | None = 'None', **options) magicgui.type_map._T[source]
magicgui.type_map.register_type(type_: Literal[None] = None, *, widget_type: WidgetRef | None = 'None', return_callback: ReturnCallback | None = 'None', **options) Callable[[magicgui.type_map._T], magicgui.type_map._T]

Register a widget_type to be used for all parameters with type type_.

Parameters
  • type (type) – The type for which a widget class or return callback will be provided.

  • widget_type (WidgetRef, optional) – A widget class from the current backend that should be used whenever type_ is used as the type annotation for an argument in a decorated function, by default None

  • return_callback (callable, optional) – If provided, whenever type_ is declared as the return type of a decorated function, return_callback(widget, value, return_type) will be called whenever the decorated function is called… where widget is the Widget instance, and value is the return value of the decorated function.

  • **options – key value pairs where the keys are valid WidgetOptions

Raises

ValueError – If none of widget_type, return_callback, bind or choices are provided.

Return type

_T | Callable[[_T], _T]