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: Display a dialog to save trans and fids before quitting the coreg app #10305

Merged
merged 41 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8c15db6
patch closeEvent
GuillaumeFavelier Feb 7, 2022
435acae
save_mri_fids
GuillaumeFavelier Feb 7, 2022
6818814
refactor
GuillaumeFavelier Feb 7, 2022
e1ae907
draft
GuillaumeFavelier Feb 7, 2022
91be3a3
fix
GuillaumeFavelier Feb 7, 2022
659745e
revert
GuillaumeFavelier Feb 7, 2022
9f698a4
update testing
GuillaumeFavelier Feb 7, 2022
8652e15
refactor
GuillaumeFavelier Feb 9, 2022
2a2b641
try again
GuillaumeFavelier Feb 9, 2022
909eb60
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 9, 2022
ae2573e
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 11, 2022
f68ddfc
add _dialog_warning
GuillaumeFavelier Feb 14, 2022
c4090d9
set icon
GuillaumeFavelier Feb 14, 2022
17dfb4b
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 14, 2022
5fe7a9f
nitpick
GuillaumeFavelier Feb 14, 2022
0ef604a
one dialog for all
GuillaumeFavelier Feb 14, 2022
07f7e2f
fix
GuillaumeFavelier Feb 14, 2022
a2df6dc
fix
GuillaumeFavelier Feb 14, 2022
a221c2b
refactor
GuillaumeFavelier Feb 14, 2022
363e31b
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 15, 2022
bd510b6
remove _dialog_warning
GuillaumeFavelier Feb 15, 2022
102f488
do not check [ci skip]
GuillaumeFavelier Feb 15, 2022
a40ed6e
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 15, 2022
77a3e46
update
GuillaumeFavelier Feb 15, 2022
4004f96
fix
GuillaumeFavelier Feb 17, 2022
adee5d6
Merge branch 'main' into enh/close_dialog
GuillaumeFavelier Feb 17, 2022
576cc86
improve testing
GuillaumeFavelier Feb 17, 2022
1f9403b
fix
GuillaumeFavelier Feb 17, 2022
931ebd5
refactor
GuillaumeFavelier Feb 17, 2022
cc6d434
fix
GuillaumeFavelier Feb 17, 2022
4394ec4
assert
GuillaumeFavelier Feb 17, 2022
5438c02
assert
GuillaumeFavelier Feb 17, 2022
5318aae
save / discard / cancel
GuillaumeFavelier Feb 18, 2022
7a95b3a
fix init
GuillaumeFavelier Feb 18, 2022
1cc1df0
macos discard
GuillaumeFavelier Feb 19, 2022
d816846
handle cancelling save_trans
GuillaumeFavelier Feb 19, 2022
a9f2d60
refactor
GuillaumeFavelier Feb 19, 2022
ab8fd7d
rename
GuillaumeFavelier Feb 19, 2022
4d669c6
mri_scale_modified
GuillaumeFavelier Feb 19, 2022
9ae9368
FIX: Do not check
larsoner Feb 19, 2022
a0086b7
try again to standardize macos
GuillaumeFavelier Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion mne/gui/_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def _get_default(var, val):
self._to_cf_t = None
self._omit_hsp_distance = 0.0
self._fiducials_file = None
self._trans_saved = False
self._fids_saved = False
self._fid_colors = tuple(
DEFAULTS['coreg'][f'{key}_color'] for key in
('lpa', 'nasion', 'rpa'))
Expand Down Expand Up @@ -226,10 +228,36 @@ def _get_default(var, val):
self._renderer = _get_renderer(
size=self._defaults["size"], bgcolor=self._defaults["bgcolor"])
self._renderer.enable_depth_peeling()
self._renderer._window_close_connect(self._clean)
self._renderer.set_interaction(interaction)
self._renderer._status_bar_initialize()

# connect callback to close event
def closeEventCallback():
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING
if not self._trans_saved:
from PyQt5.QtWidgets import QMessageBox
if MNE_3D_BACKEND_TESTING:
ret = QMessageBox.Cancel
else:
ret = QMessageBox.warning(
self._renderer._window,
"CoregistrationUI",
"The Head<>MRI transform has not been saved. "
"Do you want to save it?",
QMessageBox.Save | QMessageBox.Cancel,
QMessageBox.Save
)
if ret == QMessageBox.Save:
self._forward_widget_command(
"save_trans", "set_value", None)
else:
assert ret == QMessageBox.Cancel
if not self._fids_saved:
self._forward_widget_command(
"save_mri_fids", "set_value", None)
GuillaumeFavelier marked this conversation as resolved.
Show resolved Hide resolved
self._clean()
self._renderer._window_close_connect(closeEventCallback)

# coregistration model setup
self._immediate_redraw = (self._renderer._kind != 'qt')
self._info = info
Expand Down Expand Up @@ -941,6 +969,8 @@ def _reset(self, keep_trans=False):
self._update_plot()
self._update_parameters()
self._update_distance_estimation()
self._trans_saved = False
self._fids_saved = False

def _forward_widget_command(self, names, command, value,
input_value=True, output_value=False):
Expand Down Expand Up @@ -1232,11 +1262,13 @@ def _save_mri_fiducials(self, fname):
)
self._set_fiducials_file(fname)
self._display_message(f"Saving {fname}... Done!")
self._fids_saved = True

def _save_trans(self, fname):
write_trans(fname, self.coreg.trans, overwrite=True)
self._display_message(
f"{fname} transform file is saved.")
self._trans_saved = True

def _load_trans(self, fname):
mri_head_t = _ensure_trans(read_trans(fname, return_all=True),
Expand Down
11 changes: 10 additions & 1 deletion mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,22 @@ def _window_initialize(self):
self._window = self.figure.plotter.app_window
self._window.setLocale(QLocale(QLocale.Language.English))
self._window.signal_close.connect(self._window_clean)
self._window_close_callbacks = list()

# patch closeEvent
def closeEvent(event):
for callback in self._window_close_callbacks:
callback()
self._window.signal_close.emit()
event.accept()
self._window.closeEvent = closeEvent

def _window_clean(self):
self.figure.plotter = None
self._interactor = None

def _window_close_connect(self, func):
self._window.signal_close.connect(func)
self._window_close_callbacks.append(func)

def _window_get_dpi(self):
return self._window.windowHandle().screen().logicalDotsPerInch()
Expand Down