|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -"""Backports for MNE versions (mostly).""" |
| 2 | +"""Backports for older installations.""" |
3 | 3 |
|
4 | 4 | # Author: Martin Schulz <[email protected]> |
5 | 5 | # |
6 | 6 | # License: BSD-3-Clause |
7 | 7 |
|
8 | | -import platform |
9 | | -import sys |
10 | 8 | from contextlib import contextmanager |
11 | 9 |
|
12 | 10 | from mne.utils import logger |
13 | 11 |
|
14 | | -############################################################################### |
15 | | -# MNE 1.0+ |
16 | | -try: |
17 | | - from mne.viz.backends._utils import _qt_raise_window |
18 | | -except ImportError: |
19 | | - |
20 | | - def _qt_raise_window(win): |
21 | | - try: |
22 | | - from matplotlib import rcParams |
23 | | - |
24 | | - raise_window = rcParams["figure.raise_window"] |
25 | | - except ImportError: |
26 | | - raise_window = True |
27 | | - if raise_window: |
28 | | - win.activateWindow() |
29 | | - win.raise_() |
30 | | - |
31 | | - |
32 | | -try: |
33 | | - from mne.viz.backends._utils import _init_mne_qtapp |
34 | | -except ImportError: |
35 | | - from mne.viz.backends._utils import _init_qt_resources |
36 | | - |
37 | | - def _init_mne_qtapp(enable_icon=True, pg_app=False): |
38 | | - """Get QApplication-instance for MNE-Python. |
39 | | -
|
40 | | - Parameter |
41 | | - --------- |
42 | | - enable_icon: bool |
43 | | - If to set an MNE-icon for the app. |
44 | | - pg_app: bool |
45 | | - If to create the QApplication with pyqtgraph. For an until know |
46 | | - undiscovered reason the pyqtgraph-browser won't show without |
47 | | - mkQApp from pyqtgraph. |
48 | | -
|
49 | | - Returns |
50 | | - ------- |
51 | | - app: ``qtpy.QtWidgets.QApplication`` |
52 | | - Instance of QApplication. |
53 | | - """ |
54 | | - from qtpy.QtGui import QIcon |
55 | | - from qtpy.QtWidgets import QApplication |
56 | | - |
57 | | - app_name = "MNE-Python" |
58 | | - organization_name = "MNE" |
59 | | - |
60 | | - # Fix from cbrnr/mnelab for app name in menu bar |
61 | | - if sys.platform.startswith("darwin"): |
62 | | - try: |
63 | | - # set bundle name on macOS (app name shown in the menu bar) |
64 | | - from Foundation import NSBundle |
65 | | - |
66 | | - bundle = NSBundle.mainBundle() |
67 | | - info = bundle.localizedInfoDictionary() or bundle.infoDictionary() |
68 | | - info["CFBundleName"] = app_name |
69 | | - except ModuleNotFoundError: |
70 | | - pass |
71 | | - |
72 | | - if pg_app: |
73 | | - from pyqtgraph import mkQApp |
74 | | - |
75 | | - app = mkQApp(app_name) |
76 | | - else: |
77 | | - app = QApplication.instance() or QApplication(sys.argv or [app_name]) |
78 | | - app.setApplicationName(app_name) |
79 | | - app.setOrganizationName(organization_name) |
80 | | - |
81 | | - if enable_icon: |
82 | | - # Set icon |
83 | | - _init_qt_resources() |
84 | | - kind = "bigsur-" if platform.mac_ver()[0] >= "10.16" else "" |
85 | | - app.setWindowIcon(QIcon(f":/mne-{kind}icon.png")) |
86 | | - |
87 | | - return app |
88 | | - |
89 | | - |
90 | | -############################################################################### |
91 | 12 | # pytestqt |
92 | 13 | try: |
93 | 14 | from pytestqt.exceptions import capture_exceptions |
94 | 15 | except ImportError: |
95 | 16 | logger.debug( |
96 | | - "If pytest-qt is not installed, the errors from inside " |
97 | | - "the Qt-loop will be occluded and it will be harder " |
98 | | - "to trace back the cause." |
| 17 | + "If pytest-qt is not installed, errors from inside the event loop will be " |
| 18 | + "occluded and it will be harder to trace back the cause." |
99 | 19 | ) |
100 | 20 |
|
101 | 21 | @contextmanager |
|
0 commit comments