Skip to content

v0.3.0 (Change in event system)

Compare
Choose a tag to compare
@tlambert03 tlambert03 released this 10 Oct 18:46
· 282 commits to main since this release

Version 0.3.0 of magicgui introduced some changes to the events and callbacks API.
See https://github.com/napari/magicgui/pull/253 for details.

Existing code should continue to work with v0.3.0, but you will see warnings during runtime. See the v0.3.0 migration guide for help in migrating and silencing the warnings. In v0.4.0, these warnings will become errors.

old method

@widget.changed.connect
def my_callback(event):
    # event was an `Event` object with a `value` attribute
    new_value = event.value

Existing code using callbacks with a single positional argument will continue to receive a single Event object (and a
warning will be shown, until v0.4.0 where it will become an error).

new method

To silence the warning and opt in to the new pattern of receiving value directly, you can do one of two things:

  1. type hint your single positional argument as anything other than magicgui.events.Event
  2. provide a callback that takes no arguments
@widget.changed.connect
def my_callback(new_value: int):
    ...  # use new_value directly

# or, if you don't need to use new_value
@widget.changed.connect
def my_callback():
    # something that didn't need the value
    ...

All commits since 0.2.11