magicgui
magicgui copied to clipboard
GUIModel: new dataclass-based API, support pydantic and python dataclasses
this will supersede #379 and #318 docs to follow
from magicgui import GUIModel, Field
from datetime import date
class MyModel(GUIModel):
name: str
age: int
married: bool
salary: float = Field(..., ge=0, le=999999)
birthday: date
obj = MyModel(
name="Frank", age=55, married=True, salary=100000, birthday=date(1980, 1, 1)
)
obj.gui.show(run=True)
obj.age = 42
assert obj.age == obj.gui.age.value == 42
Codecov Report
Merging #446 (0667d8a) into main (e803f97) will increase coverage by
0.38%. The diff coverage is99.23%.
@@ Coverage Diff @@
## main #446 +/- ##
==========================================
+ Coverage 89.02% 89.40% +0.38%
==========================================
Files 30 31 +1
Lines 3953 4057 +104
==========================================
+ Hits 3519 3627 +108
+ Misses 434 430 -4
| Impacted Files | Coverage Δ | |
|---|---|---|
| magicgui/type_map.py | 95.75% <95.65%> (+0.16%) |
:arrow_up: |
| magicgui/_guimodel.py | 100.00% <100.00%> (ø) |
|
| magicgui/widgets/_bases/container_widget.py | 93.15% <100.00%> (+0.03%) |
:arrow_up: |
| magicgui/widgets/_concrete.py | 86.73% <100.00%> (ø) |
|
| magicgui/backends/_qtpy/widgets.py | 87.42% <0.00%> (+0.47%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
closing this in favor of #475 ... this PR was going to add pydantic as a dependency, and require using magicgui.GuiModel as a base class. I think we implement something lighter that will also support native dataclasses, attrs, NamedTuple, TypedDict, etc... see #474 for discussion