-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scrollable widgets #388
Conversation
Codecov Report
@@ Coverage Diff @@
## main #388 +/- ##
==========================================
- Coverage 88.74% 88.71% -0.03%
==========================================
Files 30 30
Lines 3838 3864 +26
==========================================
+ Hits 3406 3428 +22
- Misses 432 436 +4
Continue to review full report at Codecov.
|
thanks for taking this on @dstansby! This is a great start. couple first impressions:
|
Fixed, you can now set/unset scrollable and it works as intended.
Fixed - this was just setting
I'll take a look into this. Additional question I now have: I've tagged this on to the |
I like it on the container protocol. happy to leave it there |
I've updated this so that:
I think that's a good place to be from an API and functionality point of view. I've added a sentence to the docs, is there anywhere else I should add docs? I've also added a really basic smoke test. Is there any other tests I should add? |
test fail in mpl_widget does appear to be real... for better or worse, accessing |
Naïvely copying the layout onto the def test_reset_choice_recursion():
"""Test that reset_choices recursion works for multiple types of widgets."""
x = 0
def get_choices(widget):
nonlocal x
x += 1
return list(range(x))
@magicgui(c={"choices": get_choices})
def f(c):
pass
> assert f.c.choices == (0,)
E assert (0, 1) == (0,)
E Left contains one more item: 1
E Full diff:
E - (0,)
E + (0, 1)
E ? ++
tests/test_widgets.py:420: AssertionError |
I took a look into the failing test ( /Users/dstansby/projects/napari/magicgui/magicgui/widgets/_bases/container_widget.py(226)scrollable()
-> self._widget._mgui_set_scrollable(value)
/Users/dstansby/projects/napari/magicgui/magicgui/backends/_qtpy/widgets.py(408)_mgui_set_scrollable()
-> self._scroll.setWidget(self._qwidget)
/Users/dstansby/projects/napari/magicgui/magicgui/backends/_qtpy/widgets.py(36)eventFilter()
-> self.parentChanged.emit()
/Users/dstansby/projects/napari/magicgui/magicgui/widgets/_bases/widget.py(348)_emit_parent()
-> self.parent_changed.emit(self.parent)
/Users/dstansby/projects/napari/magicgui/magicgui/widgets/_bases/container_widget.py(237)reset_choices()
-> widget.reset_choices() # type: ignore
/Users/dstansby/projects/napari/magicgui/magicgui/widgets/_bases/categorical_widget.py(66)reset_choices()
-> self.choices = self._default_choices
/Users/dstansby/projects/napari/magicgui/magicgui/widgets/_bases/categorical_widget.py(114)choices()
-> _choices = choices(self)
> /Users/dstansby/projects/napari/magicgui/tests/test_widgets.py(414)get_choices()
-> x += 1 I think this is fine, so I've modified the test accordingly, and added a new explanatory comment. @tlambert03 I think this is now ready for review. |
hmm, something weird is still happening. If I run |
I don't have time to debug in the very near future, but it seems to be an issue when |
👍 , I fixed the |
thanks @dstansby! there are two things I'd like to do before merge, if it's ok with you:
I can make/push these changes if you want. just want to get your opinion |
👍 makes sense - I think I've made those changes, and I checked it works fine by locally adding |
thanks!! will merge and release this weekend |
arg... more issues. I removed this line (which was overriding the False default for scrollable), and it exposed another issue. Looks like when scrollable is true, the parent_changed signal gets fired quite a few times, which is problematic for the (currently poorly implemented) choices behavior (see #306). I know it's now just an opt-in behavior, but I fear the actual swapping of |
for more information, see https://pre-commit.ci
ok, for now, I've removed scrollable mutability. It is what it is when you create the widget for the first time, and it can't be changed. This simplifies the swapping out of the underlying qwidget after construction, and should be a little easier to reason about. Is that ok with you? If someone comes along and want to toggle scrollability after construction we can revisit it at that time. but this at least gets something in. sorry for the delay |
Thanks a lot for improving this! I'm 👍 to making the scrollable state immutable and set on creation. |
awesome. Then LGTM! Thanks a lot for your patience and effort on this! |
Fixes https://github.com/napari/magicgui/issues/380. With