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

MRG: Add time player for the notebook backend #7940

Merged
merged 2 commits into from
Jul 1, 2020
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
53 changes: 35 additions & 18 deletions mne/viz/_brain/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,9 @@ def __init__(self, time_viewer):
super().__init__(self.brain._renderer)

def configure_controllers(self):
from ipywidgets import IntSlider, FloatSlider, interactive
from ipywidgets import (IntSlider, interactive, Play, VBox,
HBox, Label, jslink)
super().configure_controllers()
# time slider
max_time = len(self.brain._data['time']) - 1
if max_time >= 1:
self.sliders["time"] = FloatSlider(
value=self.brain._data['time_idx'],
min=0,
max=max_time,
continuous_update=False
)
self.controllers["time"] = interactive(
self.brain.set_time_point,
time_idx=self.sliders["time"],
)
# orientation
self.controllers["orientation"] = interactive(
self.set_orientation,
Expand All @@ -40,12 +28,41 @@ def configure_controllers(self):
max=self.time_viewer.default_smoothing_range[1],
continuous_update=False
)
self.controllers["smoothing"] = interactive(
self.brain.set_data_smoothing,
n_steps=self.sliders["smoothing"]
)
self.controllers["smoothing"] = VBox([
Label(value='Smoothing steps'),
interactive(
self.brain.set_data_smoothing,
n_steps=self.sliders["smoothing"]
)
])
# time slider
max_time = len(self.brain._data['time']) - 1
if max_time >= 1:
time_player = Play(
value=self.brain._data['time_idx'],
min=0,
max=max_time,
continuous_update=False
)
time_slider = IntSlider(
min=0,
max=max_time,
)
jslink((time_player, 'value'), (time_slider, 'value'))
time_slider.observe(self.set_time_point, 'value')
self.controllers["time"] = VBox([
HBox([
Label(value='Select time point'),
time_player,
]),
time_slider,
])
self.sliders["time"] = time_slider

def set_orientation(self, orientation):
row, col = self.plotter.index_to_loc(
self.plotter._active_renderer_index)
self.brain.show_view(orientation, row=row, col=col)

def set_time_point(self, data):
self.brain.set_time_point(data['new'])
22 changes: 11 additions & 11 deletions mne/viz/backends/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def update(self):
def configure_controllers(self):
from ipywidgets import (interactive, Label, VBox, FloatSlider,
IntSlider, Checkbox)
# continuous update
self.continuous_update_button = Checkbox(
value=False,
description='Continuous update',
disabled=False,
indent=False,
)
self.controllers["continuous_update"] = interactive(
self.set_continuous_update,
value=self.continuous_update_button
)
# subplot
number_of_plots = len(self.plotter.renderers)
if number_of_plots > 1:
Expand Down Expand Up @@ -128,17 +139,6 @@ def configure_controllers(self):
distance=self.sliders["distance"],
)
])
# continuous update
self.continuous_update_button = Checkbox(
value=False,
description='Continuous update',
disabled=False,
indent=False,
)
self.controllers["continuous_update"] = interactive(
self.set_continuous_update,
value=self.continuous_update_button
)

def set_camera(self, azimuth, elevation, distance):
focalpoint = self.plotter.camera.GetFocalPoint()
Expand Down