magicgui icon indicating copy to clipboard operation
magicgui copied to clipboard

Model-based widget creation

Open tlambert03 opened this issue 3 years ago • 1 comments

quite similar to #318 ... this pattern would use pydantic directly in widget declaration:

from magicgui import Field, GUIModel
from magicgui.widgets import Slider

# this is a pydantic subclass
class MyWidget(GUIModel):
    x: int = 1
    # magicgui kwargs are prefaced by ui_
    y: int = Field(2, ui_widget_type=Slider)

    class Config:
        #container kwargs in the config
        layout = "horizontal"


obj = MyWidget()
obj.x  # values are directly on the object, like pydantic
obj.events.x.connect  # events are in a psygnal group
obj.gui.show(run=True)  # the widget is at the `.gui` attribute

tlambert03 avatar Feb 22 '22 23:02 tlambert03

Codecov Report

Merging #379 (519e2a7) into main (876190a) will decrease coverage by 2.33%. The diff coverage is 4.08%.

@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
- Coverage   88.64%   86.30%   -2.34%     
==========================================
  Files          30       31       +1     
  Lines        3804     3900      +96     
==========================================
- Hits         3372     3366       -6     
- Misses        432      534     +102     
Impacted Files Coverage Δ
magicgui/_gui_model.py 0.00% <0.00%> (ø)
magicgui/types.py 97.67% <80.00%> (-2.33%) :arrow_down:
magicgui/_type_wrapper.py 65.70% <0.00%> (-2.53%) :arrow_down:
magicgui/widgets/_table.py 96.06% <0.00%> (-0.25%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 876190a...519e2a7. Read the comment docs.

codecov[bot] avatar Feb 22 '22 23:02 codecov[bot]

closing this in favor of #446

tlambert03 avatar Aug 24 '22 13:08 tlambert03