magicgui icon indicating copy to clipboard operation
magicgui copied to clipboard

Enable Return press on "keyboardable" widgets to call the wrapped function

Open gselzer opened this issue 3 years ago • 1 comments

While reviewing imagej/napari-imagej#70, @ctrueden was hoping that pressing Return while focusing on a keyboardable component of a magicgui widget would call the function with the current inputs. Specifically, he noted:

Pressing enter while one of the widget's components is focused, or while the Run button is focused, does not execute the module.

This is a problem that is seemingly better solved here.

For example, suppose I wrote the following widget:

@magic_factory()
def example_magic_widget(b: int) -> List["napari.types.LayerDataTuple"]:
    return [(np.ones((4, 4)), {'name': f"foo{i}"}) for i in range(b)]

This generates the following widget in napari: image It might be nice that, while focused on/editing the b parameter, pressing Return would call the wrapped function.

Do you have more to add @ctrueden?

gselzer avatar Jun 30 '22 14:06 gselzer

Nope, I think that about sums it up. Thanks @gselzer!

ctrueden avatar Jul 01 '22 02:07 ctrueden