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

WIP: Add a menu #126

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 @@ -133,3 +133,4 @@ dmypy.json

*.orig
junit-results.xml
.vscode/
75 changes: 61 additions & 14 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ def _hidpi_mkPen(*args, **kwargs):
if self.mne.use_opengl is None: # default: opt-in
# OpenGL needs to be enabled on macOS
# (https://github.com/mne-tools/mne-qt-browser/issues/53)
default = 'true' if sys.platform == 'darwin' else ''
default = 'true' if platform.system() == 'Darwin' else ''
config_val = get_config(opengl_key, default).lower()
self.mne.use_opengl = (config_val == 'true')

Expand All @@ -2901,7 +2901,7 @@ def _hidpi_mkPen(*args, **kwargs):
# it can lead to segfaults. If a user really knows what they
# are doing, they can pass use_opengl=False (or set
# MNE_BROWSER_USE_OPENGL=false)
if sys.platform == 'darwin':
if platform.system() == 'Darwin':
raise RuntimeError(
'Plotting on macOS without OpenGL may be unstable! '
'We recommend installing PyOpenGL, but it could not '
Expand Down Expand Up @@ -3062,17 +3062,6 @@ def _hidpi_mkPen(*args, **kwargs):
button.setPopupMode(QToolButton.InstantPopup)
self.mne.toolbar.addWidget(button)

self.mne.toolbar.addSeparator()

asettings = QAction(QIcon.fromTheme("settings"), 'Settings',
parent=self)
asettings.triggered.connect(self._toggle_settings_fig)
self.mne.toolbar.addAction(asettings)

ahelp = QAction(QIcon.fromTheme("help"), 'Help', parent=self)
ahelp.triggered.connect(self._toggle_help_fig)
self.mne.toolbar.addAction(ahelp)

# Set Start-Range (after all necessary elements are initialized)
self.mne.plt.setXRange(self.mne.t_start,
self.mne.t_start + self.mne.duration,
Expand Down Expand Up @@ -4698,10 +4687,68 @@ def _init_browser(**kwargs):
if kwargs.get('splash', False):
app_kwargs['splash'] = 'Initializing mne-qt-browser...'
out = _init_mne_qtapp(pg_app=True, **app_kwargs)

if 'splash' in app_kwargs:
kwargs['splash'] = out[1] # returned as second element
app, kwargs['splash'] = out
else:
app = out
del out

browser = MNEQtBrowser(**kwargs)

# Add a menu
menu_bar = browser.menuBar()

file_menu = menu_bar.addMenu('&File')
file_menu.addAction(
'&Preferences' if platform.system() == 'Darwin' else '&Settings',
browser._toggle_settings_fig
)

view_menu = menu_bar.addMenu('&View')
# view_menu.addAction('Zoom in', lambda: print('zoom in'))
# view_menu.addAction('Zoom out', lambda: print('zoom out'))
view_menu.addAction(
'Toggle butterfly mode',
browser._toggle_butterfly,
shortcut=browser.mne.keyboard_shortcuts['b']['qt_key']
)
view_menu.addSeparator()
view_menu.addAction(
'Show fewer time points',
partial(browser.change_duration, -0.2),
shortcut=browser.mne.keyboard_shortcuts['home']['qt_key']
)
view_menu.addAction(
'Show more time points',
partial(browser.change_duration, +0.2),
shortcut=browser.mne.keyboard_shortcuts['end']['qt_key']
)
view_menu.addSeparator()
view_menu.addAction(
'Show fewer channels',
partial(browser.change_nchan, -10),
shortcut=browser.mne.keyboard_shortcuts['pageup']['qt_key']
)
view_menu.addAction(
'Show more channels',
partial(browser.change_nchan, +10),
shortcut=browser.mne.keyboard_shortcuts['pagedown']['qt_key']
)
if platform.system() == 'Darwin':
# insert before auto-added fullscreen toggle
# XXX doesn't seem to work
view_menu.addSeparator()


help_menu = menu_bar.addMenu('&Help')
help_menu.addAction('&About', lambda: print('about'))
help_menu.addAction(
'Show keyboard shortcuts',
browser._toggle_help_fig,
shortcut=browser.mne.keyboard_shortcuts['?']['qt_key']
)

return browser


Expand Down