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 UI event link #286

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
54 changes: 54 additions & 0 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
from mne.viz import plot_sensors
from mne.viz._figure import BrowserBase
from mne.viz.backends._utils import _init_mne_qtapp, _qt_raise_window
from mne.viz.ui_events import (
ChannelBrowse,
TimeBrowse,
TimeChange,
disable_ui_events,
publish,
subscribe,
)
from mne.viz.utils import _figure_agg, _merge_annotations, _simplify_float
from pyqtgraph import (
AxisItem,
Expand Down Expand Up @@ -3972,6 +3980,38 @@ def __init__(self, **kwargs):
# disable histogram of epoch PTP amplitude
del self.mne.keyboard_shortcuts["h"]

# Subscribe to vertical line change
subscribe(self, "time_change", self._on_time_change_event)

# Subscribe to time browse
subscribe(self, "time_browse", self._on_time_browse_event)

# Subscribe to channel browse
# self.mne.plt.sigYRangeChanged.connect(self._on_channel_browse_event)
subscribe(self, "channel_browse", self._on_channel_browse_event)

def _on_time_change_event(self, event):
"""Response to TimeChange event from the event-ui system."""
with disable_ui_events(self):
self._add_vline(event.time)

def _on_time_browse_event(self, event):
"""Response to TimeBrowse event from the event-ui system."""
with disable_ui_events(self):
self.mne.plt.setXRange(event.time_start, event.time_end, padding=0)

def _on_channel_browse_event(self, event):
"""Response to ChannelBrowse event from the event-ui system."""
# Get the indices of the subset in the full set of channels
all_channels = self.mne.ch_names[self.mne.ch_order]
ch_indices = [np.where(all_channels == ch)[0][0] for ch in event.channels]

# Take the start index and set range
with disable_ui_events(self):
start_idx = ch_indices[0]
n_chans = len(ch_indices)
self.mne.plt.setYRange(start_idx, start_idx + n_chans + 1, padding=0)

def _hidpi_mkPen(self, *args, **kwargs):
kwargs["width"] = self._pixel_ratio * kwargs.get("width", 1.0)
return mkPen(*args, **kwargs)
Expand Down Expand Up @@ -4249,11 +4289,13 @@ def _add_vline(self, t):
self.mne.vline = VLine(self.mne, t, bounds=(0, self.mne.xmax))
self.mne.vline.sigPositionChangeFinished.connect(self._vline_slot)
self.mne.plt.addItem(self.mne.vline)

else:
self.mne.vline.setPos(t)

self.mne.vline_visible = True
self.mne.overview_bar.update_vline()
publish(self, TimeChange(time=t))

def _mouse_moved(self, pos):
"""Show Crosshair if enabled at mouse move."""
Expand Down Expand Up @@ -4348,6 +4390,15 @@ def _xrange_changed(self, _, xrange):
# Update annotations
self._update_regions_visible()

# Publish event
publish(
self,
TimeBrowse(
time_start=self.mne.t_start,
time_end=self.mne.t_start + self.mne.duration,
),
)

def _yrange_changed(self, _, yrange):
if not self.mne.butterfly:
if not self.mne.fig_selection:
Expand Down Expand Up @@ -4401,6 +4452,9 @@ def _yrange_changed(self, _, yrange):
trace.update_color()
trace.update_data()

# Publish to event system
publish(self, ChannelBrowse(channels=self.mne.ch_names[self.mne.picks]))

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DATA HANDLING
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
Loading