Skip to content

Commit a4bd21e

Browse files
committed
force close event on the sensor window
1 parent d23104b commit a4bd21e

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

mne/gui/_xfit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def _on_sensor_data_close(self, event):
432432
for act in self._actors["sensors"]:
433433
act.prop.SetColor(1, 1, 1)
434434
self._renderer._update()
435+
print("sensor window closed.")
435436

436437
def _on_channels_select(self, event):
437438
"""Color selected sensor meshes."""

mne/gui/tests/test_xfit.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License: BSD-3-Clause
33
# Copyright the MNE-Python contributors.
44

5-
import matplotlib.pyplot as plt
65
import numpy as np
76
import pytest
87
from numpy.testing import assert_allclose, assert_equal
@@ -70,6 +69,10 @@ def test_dipolefit_gui_basic(renderer_interactive_pyvistaqt):
7069
assert len(g._dipoles) == len(g.dipoles) == 2
7170
dip2 = g.dipoles[1]
7271

72+
# During tests, matplotlib does not open an actual window so we need to force the
73+
# close event.
74+
g._fig_sensors.canvas.callbacks.process("close_event", None)
75+
7376
# The selected time of 0.09 is not actually in evoked.times, find the closest value
7477
# that is (0.08990784...). That should be the time recorded in the dipole object.
7578
closest_time = evoked.times[np.argmin(np.abs(evoked.times - g._current_time))]
@@ -100,9 +103,6 @@ def test_dipolefit_gui_basic(renderer_interactive_pyvistaqt):
100103
new_timecourses = np.vstack((dip1_dict["timecourse"], dip2_dict["timecourse"]))
101104
assert not np.allclose(old_timecourses, new_timecourses, atol=1e-10)
102105

103-
plt.close(g._fig_sensors)
104-
g._fig._renderer.close()
105-
106106

107107
@pytest.mark.slowtest
108108
@testing.requires_testing_data
@@ -118,7 +118,6 @@ def test_dipolefit_gui_toggle_meshes(renderer_interactive_pyvistaqt):
118118
assert not g._actors["helmet"].visibility
119119
with pytest.raises(ValueError, match="Invalid value for the 'name' parameter"):
120120
g.toggle_mesh("non existent")
121-
g._fig._renderer.close()
122121

123122

124123
@pytest.mark.slowtest
@@ -170,7 +169,6 @@ def test_dipolefit_gui_dipole_controls(renderer_interactive_pyvistaqt):
170169
assert 2 in g._dipoles
171170
assert list(g._dipoles.keys())[1] == 2
172171
assert list(g._dipoles.values())[1]["num"] == 2 # new dipole number
173-
g._fig._renderer.close()
174172

175173

176174
@pytest.mark.slowtest
@@ -194,4 +192,3 @@ def test_dipolefit_gui_save_load(tmpdir, renderer_interactive_pyvistaqt):
194192
assert_allclose(
195193
np.vstack([d.pos for d in g.dipoles[4:]]), dip_from_file.pos, atol=0
196194
)
197-
g._fig._renderer.close()

0 commit comments

Comments
 (0)