Skip to content

Commit

Permalink
fix function with no params and callbutton (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Feb 10, 2021
1 parent f2955c3 commit aaa4eb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions magicgui/widgets/_bases/container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ def insert(self, key: int, widget: Widget):
def _unify_label_widths(self, event=None):
if not self._initialized:
return
if self.layout == "vertical" and self.labels and len(self):

need_labels = [w for w in self if not isinstance(w, ButtonWidget)]
if self.layout == "vertical" and self.labels and need_labels:
measure = use_app().get_obj("get_text_width")
widest_label = max(
measure(w.label) for w in self if not isinstance(w, ButtonWidget)
)
widest_label = max(measure(w.label) for w in need_labels)
for w in self:
labeled_widget = w._labeled_widget()
if labeled_widget:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_magicgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,13 @@ def local_self_referencing_function(x: int = 1):
return local_self_referencing_function

assert isinstance(local_self_referencing_function(), widgets.FunctionGui)


def test_empty_function():
"""Test that a function with no params works."""

@magicgui(call_button=True)
def f():
...

f.show()

0 comments on commit aaa4eb9

Please sign in to comment.