Skip to content
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

GUIModel: new dataclass-based API, support pydantic and python dataclasses #446

Closed
wants to merge 20 commits into from

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Aug 23, 2022

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
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #446 (0667d8a) into main (e803f97) will increase coverage by 0.38%.
The diff coverage is 99.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%) ⬆️
magicgui/_guimodel.py 100.00% <100.00%> (ø)
magicgui/widgets/_bases/container_widget.py 93.15% <100.00%> (+0.03%) ⬆️
magicgui/widgets/_concrete.py 86.73% <100.00%> (ø)
magicgui/backends/_qtpy/widgets.py 87.42% <0.00%> (+0.47%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tlambert03
Copy link
Member Author

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

@tlambert03 tlambert03 closed this Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant