Skip to content

Commit

Permalink
BUG: Fix bug with arrow-key-based scrolling (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored Jun 12, 2023
1 parent eff27c0 commit 93db548
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3148,7 +3148,7 @@ def __init__(self, **kwargs):
'qt_key': Qt.Key_Left,
'modifier': [None, 'Shift'],
'slot': [self.hscroll],
'parameter': [-40, '-full'],
'parameter': ['left', '-full'],
'description': [f'Scroll left ({hscroll_type})',
'Scroll left (full page)']
},
Expand All @@ -3157,7 +3157,7 @@ def __init__(self, **kwargs):
'qt_key': Qt.Key_Right,
'modifier': [None, 'Shift'],
'slot': [self.hscroll],
'parameter': [40, '+full'],
'parameter': ['right', '+full'],
'description': [f'Scroll right ({hscroll_type})',
'Scroll right (full page)']
},
Expand Down Expand Up @@ -3425,15 +3425,30 @@ def scale_all(self, checked=False, *, step):

def hscroll(self, step):
"""Scroll horizontally by step."""
if step == '+full':
rel_step = self.mne.duration
elif step == '-full':
rel_step = - self.mne.duration
elif self.mne.is_epochs:
direction = 1 if step > 0 else -1
rel_step = direction * self.mne.duration / self.mne.n_epochs
if isinstance(step, str):
if step in ('-full', '+full'):
rel_step = self.mne.duration
if step == '-full':
rel_step = rel_step * -1
else:
assert step in ('left', 'right')
if self.mne.is_epochs:
rel_step = self.mne.duration / self.mne.n_epochs
else:
rel_step = 0.25 * self.mne.duration
if step == 'left':
rel_step = rel_step * -1
else:
rel_step = step * self.mne.duration / self.mne.scroll_sensitivity
if self.mne.is_epochs:
rel_step = (
np.sign(step) * self.mne.duration / self.mne.n_epochs
)
else:
rel_step = (
step * self.mne.duration / self.mne.scroll_sensitivity
)
del step

# Get current range and add step to it
xmin, xmax = [i + rel_step for i in self.mne.viewbox.viewRange()[0]]

Expand Down

0 comments on commit 93db548

Please sign in to comment.