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

Add clear_points in _TimeViewer #7386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions mne/viz/_brain/_timeviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ def __init__(self, brain, show_traces=False):
'i': self.toggle_interface,
's': self.apply_auto_scaling,
'r': self.restore_user_scaling,
'c': self.clear_points,
' ': self.toggle_playback,
}
menu = self.plotter.main_menu.addMenu('Help')
Expand Down Expand Up @@ -716,6 +717,14 @@ def remove_point(self, mesh):
self.picked_points[mesh._hemi].remove(mesh._vertex_id)
self.plotter.remove_actor(mesh._actors)

def clear_points(self):
for sphere in self._spheres:
vertex_id = sphere._vertex_id
hemi = sphere._hemi
if vertex_id in self.picked_points[hemi]:
self.remove_point(sphere)
self._spheres.clear()

def plot_time_course(self, hemi, vertex_id, color):
time = self.brain._data['time']
hemi_str = 'L' if hemi == 'lh' else 'R'
Expand Down Expand Up @@ -744,6 +753,7 @@ def help(self):
('i', 'Toggle interface'),
('s', 'Apply auto-scaling'),
('r', 'Restore original clim'),
('c', 'Clear all traces'),
Copy link
Member

Choose a reason for hiding this comment

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

pressing c is not working for me. Did you forget to configure the callback?

Copy link
Member

Choose a reason for hiding this comment

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

also pressing i or s does not work anymore for me :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you try with pyvista 0.23.1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now the recommended version:
#7162 (comment)

('Space', 'Start/Pause playback'),
]
text1, text2 = zip(*pairs)
Expand Down
4 changes: 1 addition & 3 deletions mne/viz/_brain/tests/test_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,9 @@ def test_brain_timeviewer_traces(renderer_interactive, hemi):
assert len(spheres) == len(hemi_str)

# test removing points
for sphere in spheres:
time_viewer.remove_point(sphere)
time_viewer.clear_points()
assert len(picked_points['lh']) == 0
assert len(picked_points['rh']) == 0
spheres.clear() # necessary for the rest of the test

# test picking a cell at random
for idx, current_hemi in enumerate(hemi_str):
Expand Down