magicgui
magicgui copied to clipboard
reset_choices with reparenting behavior can be confusing
this code does not result in a combobox with 1,2,3,4
import napari
from magicgui.widgets import ComboBox, Container
class MyWidget(Container):
def __init__(self, viewer: napari.Viewer):
super().__init__()
self._viewer = viewer
self._combobox = ComboBox()
self.append(self._combobox)
self._combobox.choices = (1, 2, 3, 4)
viewer = napari.Viewer()
widget = MyWidget(viewer)
viewer.window.add_dock_widget(widget)
napari.run()
The issue here is that when you reparent a widget, like when you add it as a dock widget to the viewer. It will reset choices. This is the thing that makes a magicgui able to update Layer combobox with the available layers in whatever viewer it's in (even though it's not necessarily in a viewer when you create the widget).
but it's obviously confusing behavior, so should be fixed
I think I just ran into this. Note to self: always check for open issues first.
I tried to assign to w.choices in a Combobox widget w that has been docked into napari. I get weird results.
E.g. I assign a list of items to .choices and only some of the items appear in Combobox. However, if I print w.choices, everything that I assigned is there.
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/resetting-choices-in-select-widget/63545/2
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/visualizing-feature-measurements-in-napari-using-colormaps-as-luts/51567/37