magicgui.type_map#
Widget | Description |
---|---|
get_widget_class |
Return a Widget subclass for the value /annotation . |
register_type |
Register a widget_type to be used for all parameters with type type_ . |
type_registered |
Context manager that temporarily registers a widget type for a given type_ . |
type2callback |
Return any callbacks that have been registered for type_ . |
magicgui.type_map.get_widget_class(value: Any = Undefined, annotation: Any = Undefined, options: dict | None = None, is_result: bool = False, raise_on_unknown: bool = True) -> tuple[WidgetClass, dict]
#
Return a Widget subclass for the value
/annotation
.
Parameters:
-
value
(
Any
, default:Undefined
) –A python value. Will be used to determine the widget type if an
annotation
is not explicitly provided by default None -
annotation
(
Optional[Type]
, default:Undefined
) –A type annotation, by default None
-
options
(
dict
, default:None
) –Options to pass when constructing the widget, by default {}
-
is_result
(
bool
, default:False
) –Identifies whether the returned widget should be tailored to an input or to an output.
-
raise_on_unknown
(
bool
, default:True
) –Raise exception if no widget is found for the given type, by default True
Returns:
magicgui.type_map.register_type(type_: _T | None = None, *, widget_type: WidgetRef | None = None, return_callback: ReturnCallback | None = None, **options: Any) -> _T | Callable[[_T], _T]
#
Register a widget_type
to be used for all parameters with type type_
.
Note: registering a Union (or Optional) type effectively registers all types in the union with the arguments.
Parameters:
-
type_
(
type
, default:None
) –The type for which a widget class or return callback will be provided.
-
widget_type
(
WidgetRef
, default:None
) –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
(
ReturnCallback | None
, default:None
) –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... wherewidget
is the Widget instance, andvalue
is the return value of the decorated function. -
options
(
Any
, default:{}
) –key value pairs where the keys are valid
dict
Raises:
-
ValueError
–If none of
widget_type
,return_callback
,bind
orchoices
are provided.
magicgui.type_map.type_registered(type_: _T, *, widget_type: WidgetRef | None = None, return_callback: ReturnCallback | None = None, **options: Any) -> Iterator[None]
#
Context manager that temporarily registers a widget type for a given type_
.
When the context is exited, the previous widget type associations for type_
is
restored.
Parameters:
-
type_
(
_T
) –The type for which a widget class or return callback will be provided.
-
widget_type
(
Optional[WidgetRef]
, default:None
) –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
(
ReturnCallback | None
, default:None
) –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... wherewidget
is the Widget instance, andvalue
is the return value of the decorated function. -
options
(
Any
, default:{}
) –key value pairs where the keys are valid
dict