magicclass.functools package

Module contents

A magic-class submodule that mimics the built-in functools module.

class magicclass.functools.partial(func, /, *args, **kwargs)[source]

Bases: functools.partial

Partialize a function and its signature.

This object is similar to functools.partial, but it also update widget options to build magicgui widget with subset of widgets. More precisely, partializing x=0 will add option x={"gui_only": True, "widget_type": EmptyWidget, "visible": False}.

Parameters

func (Callable) -- Callable object to be partialized.

Examples

Suppose you have a magic class.

>>> @magicclass
>>> class A:
>>>     def f(self, i: int): ...

You can partialize method f.

>>> ui = A()
>>> ui.append(partial(ui.f, i=1))
set_options(text: str | None = None, **kwargs)[source]

Set options for the buttons or actions.

class magicclass.functools.partialmethod(func, /, *args, **kwargs)[source]

Bases: functools.partialmethod

Partialize a method and its signature.

This object is similar to functools.partialmethod, but it also update widget options to build magicgui widget with subset of widgets. More precisely, partializing x=0 will add option x={"gui_only": True, "widget_type": EmptyWidget, "visible": False}.

Parameters

func (Callable) -- Callable object to be partialized.

Examples

>>> @magicclass
>>> class A:
>>>     def f(self, i: int): ...
>>>     g = partialmethod(f, i=1)
set_options(text: str | None = None, **kwargs)[source]

Set options for the buttons or actions.

magicclass.functools.singledispatch(func)[source]

Single dispatch function aware of GUI options in magic-class.

Dispatched functions are converted into a multi-valued widget. GUI configurations are also possible using @set_options decorator.

class magicclass.functools.singledispatchmethod(func)[source]

Bases: functools.singledispatchmethod

Single dispatch method aware of GUI options in magic-class.

Dispatched functions are converted into a multi-valued widget. GUI configurations are also possible using @set_options decorator.

register(cls: type | _AnnotatedAlias, func: Callable | None, *, options: magicgui.types.WidgetOptions = '{}')[source]
register(cls: Callable, *, options: magicgui.types.WidgetOptions = '{}')

generic_method.register(cls, func) -> func

Registers a new implementation for the given cls on a generic_method.

magicclass.functools.wraps(template: Callable | inspect.Signature) Callable[[_C], _C][source]

Update signature using a template. If class is wrapped, then all the methods except for those start with "__" will be wrapped.

Parameters

template (Callable or inspect.Signature object) -- Template function or its signature.

Returns

A wrapper which take a function or class as an input and returns same function or class with updated signature(s).

Return type

Callable