-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b7f95
commit 77ba542
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# v0.3.0 migration guide | ||
|
||
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 | ||
|
||
## Callbacks now receive the value directly, instead of an `Event` object | ||
|
||
magicgui 0.3.0 is now using [psygnal](https://github.com/tlambert03/psygnal) | ||
as its event/callback handler. | ||
|
||
Callbacks connected to `widget.changed` (and other event emitters) now receive the | ||
value(s) directly, instead of an event object: | ||
|
||
```python | ||
# before: | ||
@widget.changed.connect | ||
def my_callback(event): | ||
new_value = event.value | ||
|
||
# now becomes | ||
@widget.changed.connect | ||
def my_callback(value): | ||
new_value = value | ||
|
||
# note also that psygnal lets you accept _less_ | ||
# arguments than the emitter provides | ||
# so this also works fine | ||
@widget.changed.connect | ||
def my_callback(): | ||
# something that didn't need the value | ||
... | ||
``` | ||
|
||
## Event emitters take no keyword arguments | ||
|
||
For the few packages who were manually emitting change events, | ||
you should no longer provide the `value=` keyword when emitting. | ||
|
||
```python | ||
# before: | ||
widget.changed(value='whatever') | ||
|
||
# now becomes | ||
widget.changed.emit('whatever') | ||
# OR (if you prefer the direct __call__ syntax) | ||
widget.changed('whatever') | ||
``` |