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: Fix PySide6 and PyVista compat #11721

Merged
merged 8 commits into from
Jun 6, 2023
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
8 changes: 5 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ stages:
jobs:
- job: Ultraslow_PG
pool:
vmImage: 'ubuntu-20.04'
vmImage: 'ubuntu-22.04'
variables:
DISPLAY: ':99'
OPENBLAS_NUM_THREADS: '1'
Expand All @@ -107,7 +107,7 @@ stages:
- bash: |
set -e
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off mne-qt-browser[opengl] pyvista scikit-learn pytest-error-for-skips python-picard "PySide6!=6.3.0,!=6.4.0,!=6.4.0.1,!=6.5.0,!=6.5.1" qtpy
python -m pip install --progress-bar off mne-qt-browser[opengl] pyvista scikit-learn pytest-error-for-skips python-picard "PySide6!=6.5.1" qtpy
python -m pip uninstall -yq mne
python -m pip install --progress-bar off --upgrade -e .[test]
displayName: 'Install dependencies with pip'
Expand Down Expand Up @@ -149,7 +149,7 @@ stages:

- job: Qt
pool:
vmImage: 'ubuntu-20.04'
vmImage: 'ubuntu-22.04'
variables:
DISPLAY: ':99'
OPENBLAS_NUM_THREADS: '1'
Expand Down Expand Up @@ -196,6 +196,8 @@ stages:
- bash: |
set -e
python -m pip install PyQt6
# Uncomment if "xcb not found" Qt errors/segfaults come up again
# LD_DEBUG=libs python -c "from PyQt6.QtWidgets import QApplication, QWidget; app = QApplication([]); import matplotlib; matplotlib.use('QtAgg'); import matplotlib.pyplot as plt; plt.figure()"
mne sys_info -pd
mne sys_info -pd | grep "qtpy .* (PyQt6=.*)$"
pytest -m "not slowtest" ${TEST_OPTIONS}
Expand Down
1 change: 1 addition & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bugs
~~~~
- Extended test to highlight bug in :func:`mne.stats.permutation_t_test` (:gh:`11575` by :newcontrib:`Joshua Calder-Travis`)
- Fix bug with :func:`mne.forward.restrict_forward_to_label` where cortical patch information was not adjusted (:gh:`11694` by `Eric Larson`_)
- Fix bug with PySide6 compatibility (:gh:`11721` by `Eric Larson`_)
- Fix hanging interpreter with matplotlib figures using ``mne/viz/_mpl_figure.py`` in spyder console and jupyter notebooks`(:gh:`11696` by `Mathieu Scheltienne`_)
- Fix bug with overlapping text for :meth:`mne.Evoked.plot` (:gh:`11698` by `Alex Rockhill`_)

Expand Down
6 changes: 5 additions & 1 deletion mne/viz/backends/_pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
import pyvista
from pyvista import Plotter, PolyData, Line, close_all, UnstructuredGrid
from pyvistaqt import BackgroundPlotter
from pyvista.plotting.plotting import _ALL_PLOTTERS

try:
from pyvista.plotting.plotter import _ALL_PLOTTERS
except Exception: # PV < 0.40
from pyvista.plotting.plotting import _ALL_PLOTTERS

from vtkmodules.vtkCommonCore import vtkCommand, vtkLookupTable, VTK_UNSIGNED_CHAR
from vtkmodules.vtkCommonDataModel import VTK_VERTEX, vtkPiecewiseFunction
Expand Down
39 changes: 30 additions & 9 deletions mne/viz/backends/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ class _Button(QPushButton, _AbstractButton, _Widget, metaclass=_BaseWidget):
def __init__(self, value, callback, icon=None):
_AbstractButton.__init__(value=value, callback=callback)
_Widget.__init__(self)
QPushButton.__init__(self)
with _disabled_init(_AbstractButton):
QPushButton.__init__(self)
self.setText(value)
self.released.connect(callback)
if icon:
Expand All @@ -288,7 +289,8 @@ def __init__(self, value, rng, callback, horizontal=True):
value=value, rng=rng, callback=callback, horizontal=horizontal
)
_Widget.__init__(self)
QSlider.__init__(self, Qt.Horizontal if horizontal else Qt.Vertical)
with _disabled_init(_AbstractSlider):
QSlider.__init__(self, Qt.Horizontal if horizontal else Qt.Vertical)
self.setMinimum(rng[0])
self.setMaximum(rng[1])
self.setValue(value)
Expand Down Expand Up @@ -322,7 +324,8 @@ class _CheckBox(QCheckBox, _AbstractCheckBox, _Widget, metaclass=_BaseWidget):
def __init__(self, value, callback):
_AbstractCheckBox.__init__(value=value, callback=callback)
_Widget.__init__(self)
QCheckBox.__init__(self)
with _disabled_init(_AbstractCheckBox):
QCheckBox.__init__(self)
self.setChecked(value)
self.stateChanged.connect(lambda x: callback(bool(x)))

Expand All @@ -337,7 +340,8 @@ class _SpinBox(QDoubleSpinBox, _AbstractSpinBox, _Widget, metaclass=_BaseWidget)
def __init__(self, value, rng, callback, step=None):
_AbstractSpinBox.__init__(value=value, rng=rng, callback=callback, step=step)
_Widget.__init__(self)
QDoubleSpinBox.__init__(self)
with _disabled_init(_AbstractSpinBox):
QDoubleSpinBox.__init__(self)
self.setAlignment(Qt.AlignCenter)
self.setMinimum(rng[0])
self.setMaximum(rng[1])
Expand All @@ -360,7 +364,8 @@ class _ComboBox(QComboBox, _AbstractComboBox, _Widget, metaclass=_BaseWidget):
def __init__(self, value, items, callback):
_AbstractComboBox.__init__(value=value, items=items, callback=callback)
_Widget.__init__(self)
QComboBox.__init__(self)
with _disabled_init(_AbstractComboBox):
QComboBox.__init__(self)
self.addItems(items)
self.setCurrentText(value)
self.currentTextChanged.connect(callback)
Expand All @@ -377,7 +382,8 @@ class _RadioButtons(QVBoxLayout, _AbstractRadioButtons, _Widget, metaclass=_Base
def __init__(self, value, items, callback):
_AbstractRadioButtons.__init__(value=value, items=items, callback=callback)
_Widget.__init__(self)
QVBoxLayout.__init__(self)
with _disabled_init(_AbstractRadioButtons):
QVBoxLayout.__init__(self)
self._button_group = QButtonGroup()
self._button_group.setExclusive(True)
for val in items:
Expand Down Expand Up @@ -455,7 +461,8 @@ class _PlayMenu(QVBoxLayout, _AbstractPlayMenu, _Widget, metaclass=_BaseWidget):
def __init__(self, value, rng, callback):
_AbstractPlayMenu.__init__(value=value, rng=rng, callback=callback)
_Widget.__init__(self)
QVBoxLayout.__init__(self)
with _disabled_init(_AbstractPlayMenu):
QVBoxLayout.__init__(self)
self._slider = QSlider(Qt.Horizontal)
self._slider.setMinimum(rng[0])
self._slider.setMaximum(rng[1])
Expand Down Expand Up @@ -540,7 +547,8 @@ def __init__(
window=window,
)
_Widget.__init__(self)
QMessageBox.__init__(self, parent=window)
with _disabled_init(_AbstractPopup):
QMessageBox.__init__(self, parent=window)
self.setWindowTitle(title)
self.setText(text)
# icon is one of _Dialog.supported_icon_names
Expand Down Expand Up @@ -693,9 +701,22 @@ def _set_size(self, width=None, height=None):
# https://github.com/mne-tools/mne-python/issues/9182


# This is necessary to make PySide6 happy -- something weird with the
# __init__ calling causes the _AbstractXYZ class __init__ to be called twice
@contextmanager
def _disabled_init(klass):
orig = klass.__init__
klass.__init__ = lambda *args, **kwargs: None
try:
yield
finally:
klass.__init__ = orig


class _MNEMainWindow(MainWindow):
def __init__(self, parent=None, title=None, size=None):
MainWindow.__init__(self, parent=parent, title=title, size=size)
with _disabled_init(_Widget):
MainWindow.__init__(self, parent=parent, title=title, size=size)
self.setAttribute(Qt.WA_ShowWithoutActivating, True)
self.setAttribute(Qt.WA_DeleteOnClose, True)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ h5io
packaging
pymatreader
qtpy
PySide6!=6.3.0,!=6.4.0,!=6.4.0.1,!=6.5.0,!=6.5.1 # incompat with Matplotlib 3.6.1 and qtpy
PySide6!=6.5.1
pyobjc-framework-Cocoa>=5.2.0; platform_system=="Darwin"
sip
scikit-learn
Expand Down