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

MAINT: Refactor for mne-qt-browser #10414

Merged
merged 1 commit into from
Mar 5, 2022
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
32 changes: 4 additions & 28 deletions mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
_AbstractWindow, _AbstractMplCanvas, _AbstractPlayback,
_AbstractBrainMplCanvas, _AbstractMplInterface,
_AbstractWidgetList, _AbstractAction, _AbstractDialog)
from ._utils import _init_qt_resources, _qt_disable_paint, _qt_raise_window
from ..utils import logger, _check_option, safe_event
from ._utils import (_init_qt_resources, _qt_disable_paint,
_qt_get_stylesheet, _detect_theme, _qt_raise_window)
from ..utils import _check_option, safe_event


class _QtDialog(_AbstractDialog):
Expand Down Expand Up @@ -674,24 +675,7 @@ def _window_ensure_minimum_sizes(self):
self._process_events()

def _window_set_theme(self, theme):
if theme == 'auto':
theme = _detect_theme()

if theme == 'dark':
try:
import qdarkstyle
except ModuleNotFoundError:
logger.info('For Dark-Mode "qdarkstyle" has to be installed! '
'You can install it with `pip install qdarkstyle`')
stylesheet = None
else:
stylesheet = qdarkstyle.load_stylesheet()
elif theme != 'light':
with open(theme, 'r') as file:
stylesheet = file.read()
else:
stylesheet = None

stylesheet = _qt_get_stylesheet(theme)
self._window.setStyleSheet(stylesheet)


Expand Down Expand Up @@ -878,14 +862,6 @@ def _create_dock_widget(window, name, area, *, max_width=None):
return dock, dock_layout


def _detect_theme():
try:
import darkdetect
return darkdetect.theme().lower()
except Exception:
return 'light'


@contextmanager
def _testing_context(interactive):
from . import renderer
Expand Down
29 changes: 29 additions & 0 deletions mne/viz/backends/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ def _qt_app_exec(app):
signal.signal(signal.SIGINT, old_signal)


def _qt_get_stylesheet(theme='auto'):
from ..utils import logger
if theme == 'auto':
theme = _detect_theme()
if theme == 'dark':
try:
import qdarkstyle
except ModuleNotFoundError:
logger.info('For Dark-Mode "qdarkstyle" has to be installed! '
'You can install it with `pip install qdarkstyle`')
stylesheet = None
else:
stylesheet = qdarkstyle.load_stylesheet()
elif theme != 'light':
with open(theme, 'r') as file:
stylesheet = file.read()
else:
stylesheet = None
return stylesheet


def _detect_theme():
try:
import darkdetect
return darkdetect.theme().lower()
except Exception:
return 'light'


def _qt_raise_window(widget):
# Set raise_window like matplotlib if possible
try:
Expand Down