Skip to content

Commit

Permalink
update (#10458)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeFavelier authored Apr 1, 2022
1 parent 4301092 commit 4359456
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 47 deletions.
2 changes: 2 additions & 0 deletions mne/gui/_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ def _configure_dock(self):
desc="Load",
func=self._set_subjects_dir,
is_directory=True,
icon=True,
tooltip="Load the path to the directory containing the "
"FreeSurfer subjects",
layout=subjects_dir_layout,
Expand Down Expand Up @@ -1528,6 +1529,7 @@ def _configure_dock(self):
name="info_file",
desc="Load",
func=self._set_info_file,
icon=True,
tooltip="Load the FIFF file with digitization data for "
"coregistration",
layout=info_file_layout,
Expand Down
1 change: 0 additions & 1 deletion mne/gui/tests/test_gui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def _check_widget_trigger(widget, mock, before, after, call_count=True,
name="default",
window=None,
)
renderer._tool_bar_load_icons()

# button
assert 'reset' not in renderer.actions
Expand Down
1 change: 1 addition & 0 deletions mne/icons/dark/actions/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mne/icons/light/actions/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion mne/viz/_brain/_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,6 @@ def _configure_picking(self):
)

def _configure_tool_bar(self):
self._renderer._tool_bar_load_icons()
self._renderer._tool_bar_initialize(name="Toolbar")
self._renderer._tool_bar_add_file_button(
name="screenshot",
Expand Down
14 changes: 8 additions & 6 deletions mne/viz/backends/_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,6 @@ def remove_mesh(self, mesh_data):


class _AbstractToolBar(ABC):
@abstractmethod
def _tool_bar_load_icons(self):
pass

@abstractmethod
def _tool_bar_initialize(self, name="default", window=None):
pass
Expand Down Expand Up @@ -555,7 +551,8 @@ def _dock_add_label(

@abstractmethod
def _dock_add_button(
self, name, callback, *, style='pushbutton', tooltip=None, layout=None
self, name, callback, *, style='pushbutton', icon=None, tooltip=None,
layout=None
):
pass

Expand Down Expand Up @@ -602,7 +599,7 @@ def _dock_add_text(self, name, value, placeholder, *, callback=None,
@abstractmethod
def _dock_add_file_button(
self, name, desc, func, *, filter=None, initial_directory=None,
save=False, is_directory=False, tooltip=None, layout=None
save=False, is_directory=False, icon=False, tooltip=None, layout=None
):
pass

Expand Down Expand Up @@ -863,13 +860,18 @@ def clear(self):

class _AbstractWindow(ABC):
def _window_initialize(self):
self._icons = dict()
self._window = None
self._interactor = None
self._mplcanvas = None
self._show_traces = None
self._separate_canvas = None
self._interactor_fraction = None

@abstractmethod
def _window_load_icons(self):
pass

@abstractmethod
def _window_close_connect(self, func, *, after=True):
pass
Expand Down
58 changes: 37 additions & 21 deletions mne/viz/backends/_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,20 @@ def _dock_add_label(
self._layout_add_widget(layout, widget)
return _IpyWidget(widget)

def _dock_add_button(self, name, callback, *, style=None, tooltip=None,
layout=None):
def _dock_add_button(
self, name, callback, *, style='pushbutton', icon=None, tooltip=None,
layout=None
):
layout = self._dock_layout if layout is None else layout
kwargs = dict(description=name)
kwargs = dict()
if style == 'pushbutton':
kwargs["description"] = name
if tooltip is not None:
kwargs["tooltip"] = tooltip
widget = Button(**kwargs)
widget.on_click(lambda x: callback())
if icon is not None:
widget.icon = icon
self._layout_add_widget(layout, widget)
return _IpyWidget(widget)

Expand Down Expand Up @@ -345,7 +351,7 @@ def _dock_add_text(self, name, value, placeholder, *, callback=None,

def _dock_add_file_button(
self, name, desc, func, *, filter=None, initial_directory=None,
save=False, is_directory=False, tooltip=None, layout=None
save=False, is_directory=False, icon=False, tooltip=None, layout=None
):
layout = self._dock_layout if layout is None else layout

Expand All @@ -354,11 +360,16 @@ def callback():
self._file_picker.connect(func)
self._file_picker.show()

if icon:
kwargs = dict(style='toolbutton', icon='folder')
else:
kwargs = dict()
widget = self._dock_add_button(
name=desc,
callback=callback,
tooltip=tooltip,
layout=layout,
**kwargs
)
return widget

Expand All @@ -371,20 +382,6 @@ def func(data):


class _IpyToolBar(_AbstractToolBar, _IpyLayout):
def _tool_bar_load_icons(self):
self.icons = dict()
self.icons["help"] = "question"
self.icons["play"] = None
self.icons["pause"] = None
self.icons["reset"] = "history"
self.icons["scale"] = "magic"
self.icons["clear"] = "trash"
self.icons["movie"] = "video-camera"
self.icons["restore"] = "replay"
self.icons["screenshot"] = "camera"
self.icons["visibility_on"] = "eye"
self.icons["visibility_off"] = "eye"

def _tool_bar_initialize(self, name="default", window=None):
self.actions = dict()
self._tool_bar = self._tool_bar_layout = HBox()
Expand All @@ -393,7 +390,7 @@ def _tool_bar_initialize(self, name="default", window=None):
def _tool_bar_add_button(self, name, desc, func, *, icon_name=None,
shortcut=None):
icon_name = name if icon_name is None else icon_name
icon = self.icons[icon_name]
icon = self._icons[icon_name]
if icon is None:
return
widget = Button(tooltip=desc, icon=icon)
Expand All @@ -402,7 +399,7 @@ def _tool_bar_add_button(self, name, desc, func, *, icon_name=None,
self.actions[name] = widget

def _tool_bar_update_button_icon(self, name, icon_name):
self.actions[name].icon = self.icons[icon_name]
self.actions[name].icon = self._icons[icon_name]

def _tool_bar_add_text(self, name, value, placeholder):
widget = Text(value=value, placeholder=placeholder)
Expand Down Expand Up @@ -520,6 +517,25 @@ def __init__(self, brain, width, height, dpi):


class _IpyWindow(_AbstractWindow):
def _window_initialize(self):
super()._window_initialize()
self._window_load_icons()

def _window_load_icons(self):
# from: https://fontawesome.com/icons
self._icons["help"] = "question"
self._icons["play"] = None
self._icons["pause"] = None
self._icons["reset"] = "history"
self._icons["scale"] = "magic"
self._icons["clear"] = "trash"
self._icons["movie"] = "video-camera"
self._icons["restore"] = "replay"
self._icons["screenshot"] = "camera"
self._icons["visibility_on"] = "eye"
self._icons["visibility_off"] = "eye"
self._icons["folder"] = "folder"

def _window_close_connect(self, func, *, after=True):
pass

Expand Down Expand Up @@ -657,13 +673,13 @@ def __init__(self, *args, **kwargs):
self._file_picker = _FilePicker(rows=10)
kwargs["notebook"] = True
super().__init__(*args, **kwargs)
self._window_initialize()

def _update(self):
if self.figure.display is not None:
self.figure.display.update_canvas()

def _display_default_tool_bar(self):
self._tool_bar_load_icons()
self._tool_bar_initialize()
self._tool_bar_add_file_button(
name="screenshot",
Expand Down
45 changes: 27 additions & 18 deletions mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def _dock_add_label(
return _QtWidget(widget)

def _dock_add_button(
self, name, callback, *, style='pushbutton', tooltip=None, layout=None
self, name, callback, *, style='pushbutton', icon=None, tooltip=None,
layout=None
):
_check_option(
parameter='style',
Expand All @@ -153,6 +154,8 @@ def _dock_add_button(
widget.setStyleSheet(
'QPushButton:pressed {color: none;}'
)
if icon is not None:
widget.setIcon(self._icons[icon])

_set_widget_tooltip(widget, tooltip)
widget.clicked.connect(callback)
Expand Down Expand Up @@ -271,7 +274,7 @@ def _dock_add_text(self, name, value, placeholder, *, callback=None,

def _dock_add_file_button(
self, name, desc, func, *, filter=None, initial_directory=None,
save=False, is_directory=False, tooltip=None, layout=None
save=False, is_directory=False, icon=False, tooltip=None, layout=None
):
layout = self._dock_layout if layout is None else layout

Expand All @@ -296,11 +299,16 @@ def callback():
return
func(name)

if icon:
kwargs = dict(style='toolbutton', icon='folder')
else:
kwargs = dict()
button_widget = self._dock_add_button(
name=desc,
callback=callback,
tooltip=tooltip,
layout=layout,
**kwargs
)
return button_widget # It's already a _QtWidget instance

Expand Down Expand Up @@ -379,20 +387,6 @@ def mousePressEvent(self, event):


class _QtToolBar(_AbstractToolBar, _QtLayout):
def _tool_bar_load_icons(self):
self.icons = dict()
self.icons["help"] = QIcon.fromTheme("help")
self.icons["play"] = QIcon.fromTheme("play")
self.icons["pause"] = QIcon.fromTheme("pause")
self.icons["reset"] = QIcon.fromTheme("reset")
self.icons["scale"] = QIcon.fromTheme("scale")
self.icons["clear"] = QIcon.fromTheme("clear")
self.icons["movie"] = QIcon.fromTheme("movie")
self.icons["restore"] = QIcon.fromTheme("restore")
self.icons["screenshot"] = QIcon.fromTheme("screenshot")
self.icons["visibility_on"] = QIcon.fromTheme("visibility_on")
self.icons["visibility_off"] = QIcon.fromTheme("visibility_off")

def _tool_bar_initialize(self, name="default", window=None):
self.actions = dict()
window = self._window if window is None else window
Expand All @@ -402,13 +396,13 @@ def _tool_bar_initialize(self, name="default", window=None):
def _tool_bar_add_button(self, name, desc, func, *, icon_name=None,
shortcut=None):
icon_name = name if icon_name is None else icon_name
icon = self.icons[icon_name]
icon = self._icons[icon_name]
self.actions[name] = self._tool_bar.addAction(icon, desc, func)
if shortcut is not None:
self.actions[name].setShortcut(shortcut)

def _tool_bar_update_button_icon(self, name, icon_name):
self.actions[name].setIcon(self.icons[icon_name])
self.actions[name].setIcon(self._icons[icon_name])

def _tool_bar_add_text(self, name, value, placeholder):
pass
Expand Down Expand Up @@ -516,6 +510,7 @@ def _window_initialize(self):
super()._window_initialize()
self._interactor = self.figure.plotter.interactor
self._window = self.figure.plotter.app_window
self._window_load_icons()
self._window_set_theme()
self._window.setLocale(QLocale(QLocale.Language.English))
self._window.signal_close.connect(self._window_clean)
Expand Down Expand Up @@ -543,6 +538,20 @@ def closeEvent(event):
callback()
self._window.closeEvent = closeEvent

def _window_load_icons(self):
self._icons["help"] = QIcon.fromTheme("help")
self._icons["play"] = QIcon.fromTheme("play")
self._icons["pause"] = QIcon.fromTheme("pause")
self._icons["reset"] = QIcon.fromTheme("reset")
self._icons["scale"] = QIcon.fromTheme("scale")
self._icons["clear"] = QIcon.fromTheme("clear")
self._icons["movie"] = QIcon.fromTheme("movie")
self._icons["restore"] = QIcon.fromTheme("restore")
self._icons["screenshot"] = QIcon.fromTheme("screenshot")
self._icons["visibility_on"] = QIcon.fromTheme("visibility_on")
self._icons["visibility_off"] = QIcon.fromTheme("visibility_off")
self._icons["folder"] = QIcon.fromTheme("folder")

def _window_clean(self):
self.figure._plotter = None
self._interactor = None
Expand Down

0 comments on commit 4359456

Please sign in to comment.