Cross-figure event passing system#11685
Conversation
|
@larsoner is right, we need a better name than just "event" because that is easily confused with MEG event markers. edit: this change has now been made. |
|
I think I prefer |
|
What is the current status / plan here? |
|
Status is that the basic ui-event system seems to be working nicely. However, there are unit tests failing still (that somehow worked when testing locally?). The plan for this PR is to only implement the ui-event system and the |
|
In the upcoming developer sprint, the ui-event system can be a nice thing to work on. |
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
|
Leaving this for 1.6 sounds good. This PR only makes sense in combination with a bunch of others that integrate the UI events into the interactive figures. |
|
@wmvanvliet FYI I edited the top comment with a tentative plan, feel free to adjust as you see fit |
|
Working on An issue with the design of the UI event system is how it interacts with GUI elements:
I thought the loop could be prevented by basically adding boilerplate to the event handlers checking whether
I guess a more elegant solution is a context manager |
|
A signal blocker, |
|
Good to go again @wmvanvliet ? We cut 1.5 yesterday so this can be merged after one final review I think |
| def callback(event): | ||
| """Respond to time change event.""" | ||
| global callback_called | ||
| callback_called = True | ||
| assert isinstance(event, ui_events.TimeChange) | ||
| assert event.time == 10.2 |
There was a problem hiding this comment.
FYI to avoid this global business another (quicker/easier usually) approach is to use something mutable like a list:
callback_calls = list()
def callback(event):
callback_calls.append(event)
...
assert len(callback_calls) # or whatever
It automatically deals with this scoping stuff. I'll push a commit to do it then mark for merge when green, but if you really like the global approach I can live with it (and you can put it back in the next PR)!
There was a problem hiding this comment.
No strong feelings about it :)
doc/changes/latest.inc
Outdated
| API changes | ||
| ~~~~~~~~~~~ | ||
| - None yet | ||
| - Added :mod:`mne.viz.ui_events` API for controlling interactive figures (:gh:`11685` by `Marijn van Vliet`_). |
There was a problem hiding this comment.
This isn't really an API change the way we use it in latest.inc... it's a feature. API is really for deprecations
* upstream/main: Refactor test_epochs.py::test_split_saving (2 out of 2) (mne-tools#11884) Cross-figure event passing system (mne-tools#11685)
|
Cool! Now we can build lots of PRs on top of this. Adding interactivity everywhere. |
|
Great! |
* upstream/main: [pre-commit.ci] pre-commit autoupdate (mne-tools#11911) [BUG, MRG] Remove check on `mne.viz.Brain.add_volume_labels` (mne-tools#11889) Small splits fix (mne-tools#11905) adds niseq package to "Related software" (mne-tools#11909) Minor fixes for ERDS maps example (mne-tools#11904) FIX: Fix pyvista rendering (mne-tools#11896) BUG: Fix epoch splits naming (mne-tools#11876) ENH: Use section-title for HTML anchors in Report (mne-tools#11890) CI: Deploy [circle deploy] MAINT: Clean up whats_new and doc versions (mne-tools#11888) Refactor test_epochs.py::test_split_saving (2 out of 2) (mne-tools#11884) Cross-figure event passing system (mne-tools#11685) MAINT: Post-release deprecations, updates [circle deploy] (mne-tools#11887) MAINT: Release 1.5.0 (mne-tools#11886) [pre-commit.ci] pre-commit autoupdate (mne-tools#11883) Refactor test_epochs.py::test_split_saving (1 out of 2) (mne-tools#11880) FIX: Missing Saccade information in Eyelink File (mne-tools#11877) Improve drawing of annotations with matplotlib (mne-tools#11855) MAINT: Work around NumPy deprecation (mne-tools#11878)
Proposed in #11678, this PR works on the actual implementation of
mne.viz.ui_events. The idea is to run our own event passing system so that figures can talk to each other. For example, if you change the time slider on one figure, the time in other figures is updated accordingly.TODO:
publishsubscribeunsubscribelink,unlinkdisable_ui_eventscontext managerTimeChangeevent forplot_topomap(time='interactive')tutorials/visualizationtutorials/visualizationwith aredirect(indoc/conf.py)Follow-up PRs:
@legacythelink_brainsfunction and replace their internals with UI event passing (WIP: Add UI event support for Brain class #11891)Closes #11678