From a1fb286a3b6d861bf711597ed39d818c1d13478f Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Thu, 11 Mar 2021 07:46:01 -0500 Subject: [PATCH] fix nested functiongui show --- magicgui/widgets/_function_gui.py | 6 ++++-- tests/test_widgets.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/magicgui/widgets/_function_gui.py b/magicgui/widgets/_function_gui.py index 3e31d58fd..3a9fbc753 100644 --- a/magicgui/widgets/_function_gui.py +++ b/magicgui/widgets/_function_gui.py @@ -80,7 +80,9 @@ class FunctionGui(Container, Generic[_R]): app : magicgui.Application or str, optional A backend to use, by default ``None`` (use the default backend.) visible : bool, optional - Whether to immediately show the widget, by default False + Whether to immediately show the widget. If ``False``, widget is explicitly + hidden. If ``None``, widget is not shown, but will be shown if a parent + container is shown, by default None. auto_call : bool, optional If True, changing any parameter in either the GUI or the widget attributes will call the original function with the current settings. by default False @@ -113,7 +115,7 @@ def __init__( labels: bool = True, tooltips: bool = True, app: AppRef = None, - visible: bool = False, + visible: bool = None, auto_call: bool = False, result_widget: bool = False, param_options: dict[str, dict] | None = None, diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 6fa12bffb..c77c8d1d8 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -485,3 +485,17 @@ def test_range_widget_min(): v = rw.value assert isinstance(v, range) assert (v.start, v.stop, v.step) == (0, 1000, 5) + + +def test_containers_show_nested_containers(): + """make sure showing a container shows a nested FunctionGui.""" + + @magicgui + def func(x: int, y: str): + pass + + assert not func.visible + c2 = widgets.Container(widgets=[func]) + assert not c2.visible + c2.show() + assert c2.visible and func.visible