Skip to content

Conversation

@GuillaumeFavelier
Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier commented Jan 19, 2022

This PR introduces the block parameter to start the Qt event loop and effectively hold the context.

This PR is what I had in mind @hoechenberger

Related to #10221

@GuillaumeFavelier GuillaumeFavelier self-assigned this Jan 19, 2022
@hoechenberger
Copy link
Member

Beautiful!!!!! 😍😍😍

@GuillaumeFavelier
Copy link
Contributor Author

Did you try it @hoechenberger ? Does it work for you?

@GuillaumeFavelier
Copy link
Contributor Author

We have to use brain_kwargs to set the block parameter with stc or we can use get_brain_class() and it will block at the call to show().

Details
import os
import mne
from mne.datasets import sample


data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
mne.viz.set_3d_backend('pyvista')

brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )

@hoechenberger
Copy link
Member

Yes, works!

@GuillaumeFavelier
Copy link
Contributor Author

Any opinion @larsoner ?

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my deprecation complaint and needing latest.inc entries, looks reasonable to me.

Has anyone tested if multiple block=True calls can be made (e.g., sequential stc.plot(brain_kwargs=dict(block=True)) calls)?

Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@GuillaumeFavelier
Copy link
Contributor Author

Has anyone tested if multiple block=True calls can be made

I think the first call should block so anything after should be executed when the window is closed.

@larsoner
Copy link
Member

Agreed that should happen in theory, can you test that it works as expected?

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Jan 19, 2022

I tested the following real quick:

import os
import mne
from mne.datasets import sample


data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
mne.viz.set_3d_backend('pyvista')

brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )
brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                 clim=dict(kind='value', lims=[3, 6, 9]),
                 size=600,
                 hemi='rh',
                 views=['lat', 'med'],
                 brain_kwargs=dict(block=True),
                 )

and this is what I got:

output.mp4

I realize now that it is NOT obvious. I actually close the windows with my shortcut 😅 they do not close by themselves

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecation not fully implemented or documented yet

GuillaumeFavelier and others added 2 commits January 20, 2022 12:10
Co-authored-by: Richard Höchenberger <richard.hoechenberger@gmail.com>
This reverts commit e3b8420.
@GuillaumeFavelier GuillaumeFavelier changed the title ENH: block parameter for viz plots WIP,ENH: block parameter for viz plots Jan 20, 2022
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge. Good to go from your end @GuillaumeFavelier ?

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Jan 20, 2022

It is ready for me @larsoner

@GuillaumeFavelier GuillaumeFavelier changed the title WIP,ENH: block parameter for viz plots ENH: block parameter for viz plots Jan 20, 2022
@larsoner larsoner merged commit e05151a into mne-tools:main Jan 20, 2022
@larsoner
Copy link
Member

Thanks @GuillaumeFavelier @hoechenberger !

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.

3 participants