Skip to content

Commit cd6a069

Browse files
Improve toolbar tooltips (#127)
Co-authored-by: Eric Larson <[email protected]>
1 parent a6d1caa commit cd6a069

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ dmypy.json
134134
*.orig
135135
junit-results.xml
136136
mne_qt_browser/_version.py
137+
.vscode/

mne_qt_browser/_pg_figure.py

+36-15
Original file line numberDiff line numberDiff line change
@@ -3377,42 +3377,60 @@ def __init__(self, **kwargs):
33773377
tool_button_style = Qt.ToolButtonIconOnly
33783378
self.mne.toolbar.setToolButtonStyle(tool_button_style)
33793379

3380-
adecr_time = QAction(QIcon.fromTheme("less_time"), "- Time", parent=self)
3380+
adecr_time = QAction(
3381+
icon=QIcon.fromTheme("less_time"),
3382+
text="Show fewer time points",
3383+
parent=self,
3384+
)
33813385
adecr_time.triggered.connect(_methpartial(self.change_duration, step=-0.2))
33823386
self.mne.toolbar.addAction(adecr_time)
3383-
aincr_time = QAction(QIcon.fromTheme("more_time"), "+ Time", parent=self)
3387+
aincr_time = QAction(
3388+
icon=QIcon.fromTheme("more_time"), text="Show more time points", parent=self
3389+
)
33843390
aincr_time.triggered.connect(_methpartial(self.change_duration, step=0.25))
33853391
self.mne.toolbar.addAction(aincr_time)
33863392
self.mne.toolbar.addSeparator()
33873393

33883394
adecr_nchan = QAction(
3389-
QIcon.fromTheme("less_channels"), "- Channels", parent=self
3395+
icon=QIcon.fromTheme("less_channels"),
3396+
text="Show fewer channels",
3397+
parent=self,
33903398
)
33913399
adecr_nchan.triggered.connect(_methpartial(self.change_nchan, step=-10))
33923400
self.mne.toolbar.addAction(adecr_nchan)
33933401
aincr_nchan = QAction(
3394-
QIcon.fromTheme("more_channels"), "+ Channels", parent=self
3402+
icon=QIcon.fromTheme("more_channels"),
3403+
text="Show more channels",
3404+
parent=self,
33953405
)
33963406
aincr_nchan.triggered.connect(_methpartial(self.change_nchan, step=10))
33973407
self.mne.toolbar.addAction(aincr_nchan)
33983408
self.mne.toolbar.addSeparator()
33993409

3400-
adecr_nchan = QAction(QIcon.fromTheme("zoom_out"), "Zoom out", parent=self)
3410+
adecr_nchan = QAction(
3411+
icon=QIcon.fromTheme("zoom_out"), text="Reduce amplitude", parent=self
3412+
)
34013413
adecr_nchan.triggered.connect(_methpartial(self.scale_all, step=4 / 5))
34023414
self.mne.toolbar.addAction(adecr_nchan)
3403-
aincr_nchan = QAction(QIcon.fromTheme("zoom_in"), "Zoom in", parent=self)
3415+
aincr_nchan = QAction(
3416+
icon=QIcon.fromTheme("zoom_in"), text="Increase amplitude", parent=self
3417+
)
34043418
aincr_nchan.triggered.connect(_methpartial(self.scale_all, step=5 / 4))
34053419
self.mne.toolbar.addAction(aincr_nchan)
34063420
self.mne.toolbar.addSeparator()
34073421

34083422
if not self.mne.is_epochs:
34093423
atoggle_annot = QAction(
3410-
QIcon.fromTheme("annotations"), "Annotations", parent=self
3424+
icon=QIcon.fromTheme("annotations"),
3425+
text="Toggle annotations mode",
3426+
parent=self,
34113427
)
34123428
atoggle_annot.triggered.connect(self._toggle_annotation_fig)
34133429
self.mne.toolbar.addAction(atoggle_annot)
34143430

3415-
atoggle_proj = QAction(QIcon.fromTheme("ssp"), "SSP", parent=self)
3431+
atoggle_proj = QAction(
3432+
icon=QIcon.fromTheme("ssp"), text="Show projectors", parent=self
3433+
)
34163434
atoggle_proj.triggered.connect(self._toggle_proj_fig)
34173435
self.mne.toolbar.addAction(atoggle_proj)
34183436

@@ -3597,7 +3615,7 @@ def __init__(self, **kwargs):
35973615
"qt_key": Qt.Key_A,
35983616
"slot": [self._toggle_annotation_fig, self._toggle_annotations],
35993617
"modifier": [None, "Shift"],
3600-
"description": ["Toggle Annotation-Tool", "Toggle Annotations visible"],
3618+
"description": ["Toggle Annotation Tool", "Toggle Annotations visible"],
36013619
},
36023620
"b": {
36033621
"qt_key": Qt.Key_B,
@@ -3607,7 +3625,7 @@ def __init__(self, **kwargs):
36073625
"d": {
36083626
"qt_key": Qt.Key_D,
36093627
"slot": [self._toggle_dc],
3610-
"description": ["Toggle DC-Correction"],
3628+
"description": ["Toggle DC Correction"],
36113629
},
36123630
"e": {
36133631
"qt_key": Qt.Key_E,
@@ -3617,7 +3635,7 @@ def __init__(self, **kwargs):
36173635
"h": {
36183636
"qt_key": Qt.Key_H,
36193637
"slot": [self._toggle_epoch_histogram],
3620-
"description": ["Toggle Epoch-Histogram"],
3638+
"description": ["Toggle Epochs Histogram"],
36213639
},
36223640
"j": {
36233641
"qt_key": Qt.Key_J,
@@ -3633,12 +3651,12 @@ def __init__(self, **kwargs):
36333651
"o": {
36343652
"qt_key": Qt.Key_O,
36353653
"slot": [self._toggle_overview_bar],
3636-
"description": ["Toggle Overview-Bar"],
3654+
"description": ["Toggle Overview Bar"],
36373655
},
36383656
"t": {
36393657
"qt_key": Qt.Key_T,
36403658
"slot": [self._toggle_time_format],
3641-
"description": ["Toggle Time-Format"],
3659+
"description": ["Toggle Time Format"],
36423660
},
36433661
"s": {
36443662
"qt_key": Qt.Key_S,
@@ -3658,7 +3676,7 @@ def __init__(self, **kwargs):
36583676
"z": {
36593677
"qt_key": Qt.Key_Z,
36603678
"slot": [self._toggle_zenmode],
3661-
"description": ["Toggle Zen-Mode"],
3679+
"description": ["Toggle Zen Mode"],
36623680
},
36633681
"?": {
36643682
"qt_key": Qt.Key_Question,
@@ -3668,7 +3686,7 @@ def __init__(self, **kwargs):
36683686
"f11": {
36693687
"qt_key": Qt.Key_F11,
36703688
"slot": [self._toggle_fullscreen],
3671-
"description": ["Toggle Full-Screen"],
3689+
"description": ["Toggle Fullscreen"],
36723690
},
36733691
"escape": {
36743692
"qt_key": Qt.Key_Escape,
@@ -5048,6 +5066,9 @@ def _fake_click_on_toolbar_action(self, action_name, wait_after=500):
50485066
if not action.isSeparator():
50495067
if action.iconText() == action_name:
50505068
action.trigger()
5069+
break
5070+
else:
5071+
raise ValueError(f"action_name={repr(action_name)} not found")
50515072
QTest.qWait(wait_after)
50525073

50535074

mne_qt_browser/tests/test_pg_specific.py

+40-27
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44
# License: BSD-3-Clause
55

66
import numpy as np
7+
import pytest
78
from qtpy.QtTest import QTest
89
from mne import Annotations
910
from pyqtgraph.graphicsItems.FillBetweenItem import FillBetweenItem
1011

1112

13+
LESS_TIME = "Show fewer time points"
14+
MORE_TIME = "Show more time points"
15+
FEWER_CHANNELS = "Show fewer channels"
16+
MORE_CHANNELS = "Show more channels"
17+
REDUCE_AMPLITUDE = "Reduce amplitude"
18+
INCREASE_AMPLITUDE = "Increase amplitude"
19+
TOGGLE_ANNOTATIONS = "Toggle annotations mode"
20+
SHOW_PROJECTORS = "Show projectors"
21+
22+
1223
def test_annotations_interactions(raw_orig, pg_backend):
1324
"""Test interactions specific to pyqtgraph-backend."""
1425
# Add test-annotations
@@ -143,6 +154,8 @@ def test_pg_settings_dialog(raw_orig, pg_backend):
143154
QTest.qWaitForWindowExposed(fig)
144155
QTest.qWait(50)
145156
assert fig.mne.fig_settings is None
157+
with pytest.raises(ValueError, match="FooAction"):
158+
fig._fake_click_on_toolbar_action("FooAction")
146159
fig._fake_click_on_toolbar_action("Settings", wait_after=500)
147160
assert fig.mne.fig_settings is not None
148161
assert pg_backend._get_n_figs() == 2
@@ -263,44 +276,44 @@ def test_pg_toolbar_time_plus_minus(raw_orig, pg_backend):
263276
for _ in range(100):
264277
if xmax - xmin <= min_duration:
265278
break
266-
fig._fake_click_on_toolbar_action("- Time", wait_after=20)
279+
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=20)
267280
xmin, xmax = fig.mne.viewbox.viewRange()[0]
268281
assert xmax - xmin == min_duration
269282

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

276289
xmin, xmax = fig.mne.viewbox.viewRange()[0]
277290
for _ in range(100):
278291
if xmax + fig.mne.duration * step >= fig.mne.xmax:
279292
break
280-
fig._fake_click_on_toolbar_action("+ Time", wait_after=20)
293+
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=20)
281294
xmin, xmax = fig.mne.viewbox.viewRange()[0]
282295

283-
fig._fake_click_on_toolbar_action("+ Time", wait_after=200)
284-
fig._fake_click_on_toolbar_action("+ Time", wait_after=200)
296+
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=200)
297+
fig._fake_click_on_toolbar_action(MORE_TIME, wait_after=200)
285298

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

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

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

302315
for _ in range(7):
303-
fig._fake_click_on_toolbar_action("- Time", wait_after=20)
316+
fig._fake_click_on_toolbar_action(LESS_TIME, wait_after=20)
304317

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

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

314327
if fig.mne.butterfly is not True:
315328
fig._fake_keypress("b") # toggle butterfly mode
316-
fig._fake_click_on_toolbar_action("- Channels", wait_after=100)
329+
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=100)
317330
ymin, ymax = fig.mne.viewbox.viewRange()[1]
318-
fig._fake_click_on_toolbar_action("- Channels", wait_after=100)
331+
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=100)
319332
assert [ymin, ymax] == fig.mne.viewbox.viewRange()[1]
320-
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
333+
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
321334
assert [ymin, ymax] == fig.mne.viewbox.viewRange()[1]
322335

323336
if fig.mne.butterfly is True:
@@ -326,25 +339,25 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
326339
for _ in range(10):
327340
if ymax - ymin <= 2:
328341
break
329-
fig._fake_click_on_toolbar_action("- Channels", wait_after=40)
342+
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=40)
330343
ymin, ymax = fig.mne.viewbox.viewRange()[1]
331344
assert ymax - ymin == 2
332-
fig._fake_click_on_toolbar_action("- Channels", wait_after=40)
345+
fig._fake_click_on_toolbar_action(FEWER_CHANNELS, wait_after=40)
333346
ymin, ymax = fig.mne.viewbox.viewRange()[1]
334347
assert ymax - ymin == 2
335348

336349
step = 10
337-
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
350+
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
338351
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
339352
assert ymax_new == ymax + step
340353

341354
ymin, ymax = fig.mne.viewbox.viewRange()[1]
342-
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
355+
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
343356
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
344357
assert ymax_new == ymax + step
345358

346359
ymin, ymax = fig.mne.viewbox.viewRange()[1]
347-
fig._fake_click_on_toolbar_action("+ Channels", wait_after=100)
360+
fig._fake_click_on_toolbar_action(MORE_CHANNELS, wait_after=100)
348361
ymin_new, ymax_new = fig.mne.viewbox.viewRange()[1]
349362
assert ymax_new == ymax + step
350363

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

360373
step = 4 / 5
361374
scale_factor = fig.mne.scale_factor
362-
fig._fake_click_on_toolbar_action("Zoom out", wait_after=100)
375+
fig._fake_click_on_toolbar_action(REDUCE_AMPLITUDE, wait_after=100)
363376
scale_factor_new = fig.mne.scale_factor
364377
assert scale_factor_new == scale_factor * step
365378

366379
for _ in range(6):
367-
fig._fake_click_on_toolbar_action("Zoom out", wait_after=100)
380+
fig._fake_click_on_toolbar_action(REDUCE_AMPLITUDE, wait_after=100)
368381

369382
step = 5 / 4
370383
scale_factor = fig.mne.scale_factor
371-
fig._fake_click_on_toolbar_action("Zoom in", wait_after=100)
384+
fig._fake_click_on_toolbar_action(INCREASE_AMPLITUDE, wait_after=100)
372385
scale_factor_new = fig.mne.scale_factor
373386
assert scale_factor_new == scale_factor * step
374387

375388
for _ in range(6):
376-
fig._fake_click_on_toolbar_action("Zoom in", wait_after=100)
389+
fig._fake_click_on_toolbar_action(INCREASE_AMPLITUDE, wait_after=100)
377390

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

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

387400
state_annotation_widget = fig.mne.annotation_mode
388-
fig._fake_click_on_toolbar_action("Annotations", wait_after=100)
401+
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=100)
389402
assert fig.mne.annotation_mode != state_annotation_widget
390403

391-
fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
392-
fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
393-
fig._fake_click_on_toolbar_action("Annotations", wait_after=300)
404+
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)
405+
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)
406+
fig._fake_click_on_toolbar_action(TOGGLE_ANNOTATIONS, wait_after=300)
394407

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

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

407-
fig._fake_click_on_toolbar_action("SSP", wait_after=200)
420+
fig._fake_click_on_toolbar_action(SHOW_PROJECTORS, wait_after=200)
408421
assert pg_backend._get_n_figs() == 2
409422
fig._fake_click_on_toolbar_action("Settings", wait_after=200)
410423
assert pg_backend._get_n_figs() == 3
@@ -414,7 +427,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
414427
assert pg_backend._get_n_figs() == 3
415428
fig._fake_click_on_toolbar_action("Settings", wait_after=200)
416429
assert pg_backend._get_n_figs() == 4
417-
fig._fake_click_on_toolbar_action("SSP", wait_after=200)
430+
fig._fake_click_on_toolbar_action(SHOW_PROJECTORS, wait_after=200)
418431
assert pg_backend._get_n_figs() == 3
419432
fig._fake_click_on_toolbar_action("Settings", wait_after=100)
420433
assert pg_backend._get_n_figs() == 2

0 commit comments

Comments
 (0)