magicgui
magicgui copied to clipboard
Support pydantic types
As @sofroniewn suggested, pydantic's constrained types make for a natural way to express things like ranges and widget parameters as type annotations. We should detect and support pydantic types
Currently I am building my user interface using the direct widget API and noticed I should avoid repetition by keeping widget constraints (type, min/max) in a central place, my data model which is a Pydantic class and has all these constraints. As a Pydantic class (from which I can generate documentation) it also can hold widget texts (Pydantic title) and tooltips (Pydantic description). Basically I ended up with rather repetitive code that feeds each Pydantic field property to an argument of the widget constructor.
It would be nice to generate a magicgui either from a pydantic class (like magic-class from basic dataclasses), or to have something similar to widgets.create_widget() with a Pydantic field as single required argument.
thanks @aeisenbarth ... I have a local branch where I started to implement this. will try to get back on it soon
Seeing the discussions in #474 and #475, is the plan still to have first-class support for Pydantic classes?
Or should I rather look into using @dataclass or @guiclass?
it's basically possible already with the logic underlying guiclass, but not everything is public yet.
Can you read through this topic on imagesc and let me know what your specific desired use case would be?
https://forum.image.sc/t/building-a-napari-widget-from-a-pydantic-model/90257/5
This issue has been mentioned on Image.sc Forum. There might be relevant details there:
https://forum.image.sc/t/using-magicgui-to-create-pydantic-class-instances/92520/1
Can you read through this topic on imagesc and let me know what your specific desired use case would be? forum.image.sc/t/building-a-napari-widget-from-a-pydantic-model/90257/5
Thanks @tlambert03, that's a very useful forum post! I opened a new topic (Using magicgui to create pydantic class instances) to describe my intended use case and post a few more questions 🙂.