Skip to content

magicgui_widgets

Magicgui widgets.

layer_choice(annotation=Image, **kwargs) #

Create a widget to select a layer from the napari viewer.

Parameters:

Name Type Description Default
annotation Any or None

The annotation type to filter the layers.

Image
**kwargs Any

Additional keyword arguments to pass to the widget.

{}

Returns:

Type Description
Widget

The widget to select a layer from the napari viewer.

Raises:

Type Description
ImportError

If napari is not installed.

Source code in src/careamics_napari/widgets/magicgui_widgets.py
def layer_choice(annotation: Optional[Any] = Image, **kwargs: Any) -> Widget:
    """Create a widget to select a layer from the napari viewer.

    Parameters
    ----------
    annotation : Any or None, default=Image
        The annotation type to filter the layers.
    **kwargs : Any
        Additional keyword arguments to pass to the widget.

    Returns
    -------
    Widget
        The widget to select a layer from the napari viewer.

    Raises
    ------
    ImportError
        If napari is not installed.
    """
    if not _has_napari:
        raise ImportError("napari is not installed.")

    widget: Widget = create_widget(annotation=annotation, **kwargs)
    widget.reset_choices()
    viewer = current_viewer()

    # connect to napari events
    viewer.layers.events.inserted.connect(widget.reset_choices)
    viewer.layers.events.removed.connect(widget.reset_choices)
    viewer.layers.events.changed.connect(widget.reset_choices)

    return widget

load_button(Model) #

A button to load model files.

Parameters:

Name Type Description Default
Model Path

The path to the model file.

required
Source code in src/careamics_napari/widgets/magicgui_widgets.py
@magic_factory(auto_call=True, Model={"mode": "r", "filter": "*.ckpt *.zip"})
def load_button(Model: Path):
    """A button to load model files.

    Parameters
    ----------
    Model : pathlib.Path
        The path to the model file.
    """
    pass