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

Improve toolbar tooltips #127

Merged
merged 5 commits into from
Oct 1, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ dmypy.json
*.orig
junit-results.xml
mne_qt_browser/_version.py
.vscode/
51 changes: 36 additions & 15 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3377,42 +3377,60 @@ def __init__(self, **kwargs):
tool_button_style = Qt.ToolButtonIconOnly
self.mne.toolbar.setToolButtonStyle(tool_button_style)

adecr_time = QAction(QIcon.fromTheme("less_time"), "- Time", parent=self)
adecr_time = QAction(
icon=QIcon.fromTheme("less_time"),
text="Show fewer time points",
parent=self,
)
adecr_time.triggered.connect(_methpartial(self.change_duration, step=-0.2))
self.mne.toolbar.addAction(adecr_time)
aincr_time = QAction(QIcon.fromTheme("more_time"), "+ Time", parent=self)
aincr_time = QAction(
icon=QIcon.fromTheme("more_time"), text="Show more time points", parent=self
)
aincr_time.triggered.connect(_methpartial(self.change_duration, step=0.25))
self.mne.toolbar.addAction(aincr_time)
self.mne.toolbar.addSeparator()

adecr_nchan = QAction(
QIcon.fromTheme("less_channels"), "- Channels", parent=self
icon=QIcon.fromTheme("less_channels"),
text="Show fewer channels",
parent=self,
)
adecr_nchan.triggered.connect(_methpartial(self.change_nchan, step=-10))
self.mne.toolbar.addAction(adecr_nchan)
aincr_nchan = QAction(
QIcon.fromTheme("more_channels"), "+ Channels", parent=self
icon=QIcon.fromTheme("more_channels"),
text="Show more channels",
parent=self,
)
aincr_nchan.triggered.connect(_methpartial(self.change_nchan, step=10))
self.mne.toolbar.addAction(aincr_nchan)
self.mne.toolbar.addSeparator()

adecr_nchan = QAction(QIcon.fromTheme("zoom_out"), "Zoom out", parent=self)
adecr_nchan = QAction(
icon=QIcon.fromTheme("zoom_out"), text="Reduce amplitude", parent=self
)
adecr_nchan.triggered.connect(_methpartial(self.scale_all, step=4 / 5))
self.mne.toolbar.addAction(adecr_nchan)
aincr_nchan = QAction(QIcon.fromTheme("zoom_in"), "Zoom in", parent=self)
aincr_nchan = QAction(
icon=QIcon.fromTheme("zoom_in"), text="Increase amplitude", parent=self
)
aincr_nchan.triggered.connect(_methpartial(self.scale_all, step=5 / 4))
self.mne.toolbar.addAction(aincr_nchan)
self.mne.toolbar.addSeparator()

if not self.mne.is_epochs:
atoggle_annot = QAction(
QIcon.fromTheme("annotations"), "Annotations", parent=self
icon=QIcon.fromTheme("annotations"),
text="Toggle annotations mode",
parent=self,
)
atoggle_annot.triggered.connect(self._toggle_annotation_fig)
self.mne.toolbar.addAction(atoggle_annot)

atoggle_proj = QAction(QIcon.fromTheme("ssp"), "SSP", parent=self)
atoggle_proj = QAction(
icon=QIcon.fromTheme("ssp"), text="Show projectors", parent=self
)
atoggle_proj.triggered.connect(self._toggle_proj_fig)
self.mne.toolbar.addAction(atoggle_proj)

Expand Down Expand Up @@ -3597,7 +3615,7 @@ def __init__(self, **kwargs):
"qt_key": Qt.Key_A,
"slot": [self._toggle_annotation_fig, self._toggle_annotations],
"modifier": [None, "Shift"],
"description": ["Toggle Annotation-Tool", "Toggle Annotations visible"],
"description": ["Toggle Annotation Tool", "Toggle Annotations visible"],
},
"b": {
"qt_key": Qt.Key_B,
Expand All @@ -3607,7 +3625,7 @@ def __init__(self, **kwargs):
"d": {
"qt_key": Qt.Key_D,
"slot": [self._toggle_dc],
"description": ["Toggle DC-Correction"],
"description": ["Toggle DC Correction"],
},
"e": {
"qt_key": Qt.Key_E,
Expand All @@ -3617,7 +3635,7 @@ def __init__(self, **kwargs):
"h": {
"qt_key": Qt.Key_H,
"slot": [self._toggle_epoch_histogram],
"description": ["Toggle Epoch-Histogram"],
"description": ["Toggle Epochs Histogram"],
},
"j": {
"qt_key": Qt.Key_J,
Expand All @@ -3633,12 +3651,12 @@ def __init__(self, **kwargs):
"o": {
"qt_key": Qt.Key_O,
"slot": [self._toggle_overview_bar],
"description": ["Toggle Overview-Bar"],
"description": ["Toggle Overview Bar"],
},
"t": {
"qt_key": Qt.Key_T,
"slot": [self._toggle_time_format],
"description": ["Toggle Time-Format"],
"description": ["Toggle Time Format"],
},
"s": {
"qt_key": Qt.Key_S,
Expand All @@ -3658,7 +3676,7 @@ def __init__(self, **kwargs):
"z": {
"qt_key": Qt.Key_Z,
"slot": [self._toggle_zenmode],
"description": ["Toggle Zen-Mode"],
"description": ["Toggle Zen Mode"],
},
"?": {
"qt_key": Qt.Key_Question,
Expand All @@ -3668,7 +3686,7 @@ def __init__(self, **kwargs):
"f11": {
"qt_key": Qt.Key_F11,
"slot": [self._toggle_fullscreen],
"description": ["Toggle Full-Screen"],
"description": ["Toggle Fullscreen"],
},
"escape": {
"qt_key": Qt.Key_Escape,
Expand Down Expand Up @@ -5048,6 +5066,9 @@ def _fake_click_on_toolbar_action(self, action_name, wait_after=500):
if not action.isSeparator():
if action.iconText() == action_name:
action.trigger()
break
else:
raise ValueError(f"action_name={repr(action_name)} not found")
QTest.qWait(wait_after)


Expand Down
67 changes: 40 additions & 27 deletions mne_qt_browser/tests/test_pg_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
# License: BSD-3-Clause

import numpy as np
import pytest
from qtpy.QtTest import QTest
from mne import Annotations
from pyqtgraph.graphicsItems.FillBetweenItem import FillBetweenItem


LESS_TIME = "Show fewer time points"
MORE_TIME = "Show more time points"
FEWER_CHANNELS = "Show fewer channels"
MORE_CHANNELS = "Show more channels"
REDUCE_AMPLITUDE = "Reduce amplitude"
INCREASE_AMPLITUDE = "Increase amplitude"
TOGGLE_ANNOTATIONS = "Toggle annotations mode"
SHOW_PROJECTORS = "Show projectors"


def test_annotations_interactions(raw_orig, pg_backend):
"""Test interactions specific to pyqtgraph-backend."""
# Add test-annotations
Expand Down Expand Up @@ -143,6 +154,8 @@ def test_pg_settings_dialog(raw_orig, pg_backend):
QTest.qWaitForWindowExposed(fig)
QTest.qWait(50)
assert fig.mne.fig_settings is None
with pytest.raises(ValueError, match="FooAction"):
fig._fake_click_on_toolbar_action("FooAction")
fig._fake_click_on_toolbar_action("Settings", wait_after=500)
assert fig.mne.fig_settings is not None
assert pg_backend._get_n_figs() == 2
Expand Down Expand Up @@ -263,44 +276,44 @@ def test_pg_toolbar_time_plus_minus(raw_orig, pg_backend):
for _ in range(100):
if xmax - xmin <= min_duration:
break
fig._fake_click_on_toolbar_action("- Time", wait_after=20)
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=20)
xmin, xmax = fig.mne.viewbox.viewRange()[0]
assert xmax - xmin == min_duration

eps = 0.01
step = 0.25
fig._fake_click_on_toolbar_action("+ Time", wait_after=100)
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=100)
xmin_new, xmax_new = fig.mne.viewbox.viewRange()[0]
assert xmax_new - (xmax + (xmax - xmin * step)) < eps

xmin, xmax = fig.mne.viewbox.viewRange()[0]
for _ in range(100):
if xmax + fig.mne.duration * step >= fig.mne.xmax:
break
fig._fake_click_on_toolbar_action("+ Time", wait_after=20)
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=20)
xmin, xmax = fig.mne.viewbox.viewRange()[0]

fig._fake_click_on_toolbar_action("+ Time", wait_after=200)
fig._fake_click_on_toolbar_action("+ Time", wait_after=200)
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=200)
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=200)

xmin, xmax = fig.mne.viewbox.viewRange()[0]
fig._fake_click_on_toolbar_action("+ Time", wait_after=200)
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=200)
xmin_new, xmax_new = fig.mne.viewbox.viewRange()[0]
assert xmax_new == xmax # no effect after span maxed

step = -0.2
xmin, xmax = fig.mne.viewbox.viewRange()[0]
fig._fake_click_on_toolbar_action("- Time", wait_after=200)
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=200)
xmin_new, xmax_new = fig.mne.viewbox.viewRange()[0]
assert xmax_new == xmax + ((xmax - xmin) * step)

xmin, xmax = fig.mne.viewbox.viewRange()[0]
fig._fake_click_on_toolbar_action("- Time", wait_after=200)
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=200)
xmin_new, xmax_new = fig.mne.viewbox.viewRange()[0]
assert xmax_new == xmax + ((xmax - xmin) * step)

for _ in range(7):
fig._fake_click_on_toolbar_action("- Time", wait_after=20)
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=20)

assert pg_backend._get_n_figs() == 1 # still alive

Expand All @@ -313,11 +326,11 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):

if fig.mne.butterfly is not True:
fig._fake_keypress("b") # toggle butterfly mode
fig._fake_click_on_toolbar_action("- Channels", wait_after=100)
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=100)
ymin, ymax = fig.mne.viewbox.viewRange()[1]
fig._fake_click_on_toolbar_action("- Channels", wait_after=100)
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=100)
assert [ymin, ymax] == fig.mne.viewbox.viewRange()[1]
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
assert [ymin, ymax] == fig.mne.viewbox.viewRange()[1]

if fig.mne.butterfly is True:
Expand All @@ -326,25 +339,25 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
for _ in range(10):
if ymax - ymin <= 2:
break
fig._fake_click_on_toolbar_action("- Channels", wait_after=40)
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=40)
ymin, ymax = fig.mne.viewbox.viewRange()[1]
assert ymax - ymin == 2
fig._fake_click_on_toolbar_action("- Channels", wait_after=40)
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=40)
ymin, ymax = fig.mne.viewbox.viewRange()[1]
assert ymax - ymin == 2

step = 10
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
assert ymax_new == ymax + step

ymin, ymax = fig.mne.viewbox.viewRange()[1]
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
assert ymax_new == ymax + step

ymin, ymax = fig.mne.viewbox.viewRange()[1]
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
assert ymax_new == ymax + step

Expand All @@ -359,21 +372,21 @@ def test_pg_toolbar_zoom(raw_orig, pg_backend):

step = 4 / 5
scale_factor = fig.mne.scale_factor
fig._fake_click_on_toolbar_action("Zoom out", wait_after=100)
fig._fake_click_on_toolbar_action(REDUCE_AMPLITUDE, wait_after=100)
scale_factor_new = fig.mne.scale_factor
assert scale_factor_new == scale_factor * step

for _ in range(6):
fig._fake_click_on_toolbar_action("Zoom out", wait_after=100)
fig._fake_click_on_toolbar_action(REDUCE_AMPLITUDE, wait_after=100)

step = 5 / 4
scale_factor = fig.mne.scale_factor
fig._fake_click_on_toolbar_action("Zoom in", wait_after=100)
fig._fake_click_on_toolbar_action(INCREASE_AMPLITUDE, wait_after=100)
scale_factor_new = fig.mne.scale_factor
assert scale_factor_new == scale_factor * step

for _ in range(6):
fig._fake_click_on_toolbar_action("Zoom in", wait_after=100)
fig._fake_click_on_toolbar_action(INCREASE_AMPLITUDE, wait_after=100)

assert pg_backend._get_n_figs() == 1 # still alive

Expand All @@ -385,12 +398,12 @@ def test_pg_toolbar_annotations(raw_orig, pg_backend):
assert pg_backend._get_n_figs() == 1

state_annotation_widget = fig.mne.annotation_mode
fig._fake_click_on_toolbar_action("Annotations", wait_after=100)
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=100)
assert fig.mne.annotation_mode != state_annotation_widget

fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)

assert pg_backend._get_n_figs() == 1 # still alive

Expand All @@ -404,7 +417,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
QTest.qWaitForWindowExposed(fig)
assert pg_backend._get_n_figs() == 1

fig._fake_click_on_toolbar_action("SSP", wait_after=200)
fig._fake_click_on_toolbar_action(SHOW_PROJECTORS, wait_after=200)
assert pg_backend._get_n_figs() == 2
fig._fake_click_on_toolbar_action("Settings", wait_after=200)
assert pg_backend._get_n_figs() == 3
Expand All @@ -414,7 +427,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
assert pg_backend._get_n_figs() == 3
fig._fake_click_on_toolbar_action("Settings", wait_after=200)
assert pg_backend._get_n_figs() == 4
fig._fake_click_on_toolbar_action("SSP", wait_after=200)
fig._fake_click_on_toolbar_action(SHOW_PROJECTORS, wait_after=200)
assert pg_backend._get_n_figs() == 3
fig._fake_click_on_toolbar_action("Settings", wait_after=100)
assert pg_backend._get_n_figs() == 2
Expand Down
Loading