Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add support for warning dialog in GUI API #10346

Merged
merged 1 commit into from
Feb 15, 2022

Conversation

GuillaumeFavelier
Copy link
Contributor

This PR is partially extracted from #10305 (comment). It adds support for dialogs in the GUI API, in particular for the pyvistaqt 3d backend. It can serve as draft for notebook too.

@GuillaumeFavelier GuillaumeFavelier self-assigned this Feb 15, 2022
@GuillaumeFavelier GuillaumeFavelier marked this pull request as ready for review February 15, 2022 12:59
@larsoner
Copy link
Member

It does not seem to behave correctly to me. I think if you modify the transformation matrix, it should warn, but it doesn't:

$ mne coreg -s sample -d subjects/ --fif MEG/sample/sample_audvis_raw.fif --trans MEG/sample/sample_audvis_raw-trans.fif
Peek.2022-02-15.08-06.mp4

I would expect that when I click the X it would prompt with "The trans has been modified but not saved" or so.

Then we want the same thing for the scaled MRI -- if and only if the scale params have been changed (since the last save) and you go to exit, it should prompt asking if you want to save the scaled MRI or not.

@larsoner
Copy link
Member

... I think a reasonable approach is to track a self._trans_modified = False and self._scale_modified = False that get set to True whenever the trans and scale, respectively, are modified, and get set to False only at class instantiation and when saving the trans or scaled MRI, respecitively. Then whenever a GUI close is attempted, these are checked, and a prompt comes up telling you that scale, trans, or scale+trans were modified but were not saved.

@GuillaumeFavelier
Copy link
Contributor Author

I'll consider your comments for #10305 @larsoner 👍

This PR just modifies the GUI API though. Could you try the following snippet?

import mne
renderer = mne.viz.backends.renderer._get_renderer(size=(300, 300))
actor = renderer.text2d(0, 0, "testing window")
renderer.show()


def callback(button_name):
    actor.SetInput(button_name)


widget = renderer._dialog_warning(
    title='title',
    text='text',
    info_text='info text',
    callback=callback,
    buttons=["Ok", "Cancel"],
)
widget.show()
output.mp4

@larsoner
Copy link
Member

I get &Cancel and &OK shown, but I assume we can work around this

Thanks @GuillaumeFavelier !

@larsoner larsoner merged commit 0c50010 into mne-tools:main Feb 15, 2022
@GuillaumeFavelier GuillaumeFavelier deleted the enh/dialog branch February 15, 2022 15:42
larsoner added a commit to larsoner/mne-python that referenced this pull request Feb 15, 2022
* upstream/main:
  update (mne-tools#10346)
  BUG: Fix bug with closing and resizing (mne-tools#10342)
  WIP,MNT: disable 3d options during testing (mne-tools#10334)
larsoner added a commit to larsoner/mne-python that referenced this pull request Feb 15, 2022
* upstream/main:
  MAINT: Make public Figure3D class (mne-tools#10347)
  update (mne-tools#10346)
  BUG: Fix bug with closing and resizing (mne-tools#10342)
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.

2 participants