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 browserfig UI events #12819

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions mne/viz/_mpl_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from ..fixes import _close_event
from ..utils import Bunch, _click_ch_name, check_version, logger
from ._figure import BrowserBase
from .ui_events import TimeChange, disable_ui_events, publish, subscribe
from .utils import (
DraggableLine,
_events_off,
Expand Down Expand Up @@ -566,6 +567,9 @@ def __init__(self, inst, figsize, ica=None, xlabel="Time (s)", **kwargs):
vline_text=vline_text,
)

# Start listening to incoming UI events
subscribe(self, "time_change", self._on_time_change_event)

def _get_size(self):
return self.get_size_inches()

Expand Down Expand Up @@ -2227,6 +2231,7 @@ def _show_vline(self, xdata):
text = self._xtick_formatter(xdata, ax_type="vline")[:12]
self.mne.vline_text.set_text(text)
self._toggle_vline(True)
publish(self, TimeChange(time=xdata))

def _toggle_vline(self, visible):
"""Show or hide the vertical line(s)."""
Expand Down Expand Up @@ -2318,6 +2323,16 @@ def _get_scale_bar_texts(self):

return texts

def _on_time_change_event(self, event):
"""Respond to the TimeChange UI event."""
if self.mne.is_epochs:
# last_time = self.mne.n_times / self.mne.info["sfreq"]
time = event.time
else:
time = np.clip(event.time, self.mne.inst.times[0], self.mne.inst.times[-1])
with disable_ui_events(self):
self._show_vline(time)


class MNELineFigure(MNEFigure):
"""Interactive figure for non-scrolling line plots."""
Expand Down
Loading
Loading