@@ -269,7 +269,8 @@ class _Button(QPushButton, _AbstractButton, _Widget, metaclass=_BaseWidget):
269
269
def __init__ (self , value , callback , icon = None ):
270
270
_AbstractButton .__init__ (value = value , callback = callback )
271
271
_Widget .__init__ (self )
272
- QPushButton .__init__ (self )
272
+ with _disabled_init (_AbstractButton ):
273
+ QPushButton .__init__ (self )
273
274
self .setText (value )
274
275
self .released .connect (callback )
275
276
if icon :
@@ -288,7 +289,8 @@ def __init__(self, value, rng, callback, horizontal=True):
288
289
value = value , rng = rng , callback = callback , horizontal = horizontal
289
290
)
290
291
_Widget .__init__ (self )
291
- QSlider .__init__ (self , Qt .Horizontal if horizontal else Qt .Vertical )
292
+ with _disabled_init (_AbstractSlider ):
293
+ QSlider .__init__ (self , Qt .Horizontal if horizontal else Qt .Vertical )
292
294
self .setMinimum (rng [0 ])
293
295
self .setMaximum (rng [1 ])
294
296
self .setValue (value )
@@ -322,7 +324,8 @@ class _CheckBox(QCheckBox, _AbstractCheckBox, _Widget, metaclass=_BaseWidget):
322
324
def __init__ (self , value , callback ):
323
325
_AbstractCheckBox .__init__ (value = value , callback = callback )
324
326
_Widget .__init__ (self )
325
- QCheckBox .__init__ (self )
327
+ with _disabled_init (_AbstractCheckBox ):
328
+ QCheckBox .__init__ (self )
326
329
self .setChecked (value )
327
330
self .stateChanged .connect (lambda x : callback (bool (x )))
328
331
@@ -337,7 +340,8 @@ class _SpinBox(QDoubleSpinBox, _AbstractSpinBox, _Widget, metaclass=_BaseWidget)
337
340
def __init__ (self , value , rng , callback , step = None ):
338
341
_AbstractSpinBox .__init__ (value = value , rng = rng , callback = callback , step = step )
339
342
_Widget .__init__ (self )
340
- QDoubleSpinBox .__init__ (self )
343
+ with _disabled_init (_AbstractSpinBox ):
344
+ QDoubleSpinBox .__init__ (self )
341
345
self .setAlignment (Qt .AlignCenter )
342
346
self .setMinimum (rng [0 ])
343
347
self .setMaximum (rng [1 ])
@@ -360,7 +364,8 @@ class _ComboBox(QComboBox, _AbstractComboBox, _Widget, metaclass=_BaseWidget):
360
364
def __init__ (self , value , items , callback ):
361
365
_AbstractComboBox .__init__ (value = value , items = items , callback = callback )
362
366
_Widget .__init__ (self )
363
- QComboBox .__init__ (self )
367
+ with _disabled_init (_AbstractComboBox ):
368
+ QComboBox .__init__ (self )
364
369
self .addItems (items )
365
370
self .setCurrentText (value )
366
371
self .currentTextChanged .connect (callback )
@@ -377,7 +382,8 @@ class _RadioButtons(QVBoxLayout, _AbstractRadioButtons, _Widget, metaclass=_Base
377
382
def __init__ (self , value , items , callback ):
378
383
_AbstractRadioButtons .__init__ (value = value , items = items , callback = callback )
379
384
_Widget .__init__ (self )
380
- QVBoxLayout .__init__ (self )
385
+ with _disabled_init (_AbstractRadioButtons ):
386
+ QVBoxLayout .__init__ (self )
381
387
self ._button_group = QButtonGroup ()
382
388
self ._button_group .setExclusive (True )
383
389
for val in items :
@@ -455,7 +461,8 @@ class _PlayMenu(QVBoxLayout, _AbstractPlayMenu, _Widget, metaclass=_BaseWidget):
455
461
def __init__ (self , value , rng , callback ):
456
462
_AbstractPlayMenu .__init__ (value = value , rng = rng , callback = callback )
457
463
_Widget .__init__ (self )
458
- QVBoxLayout .__init__ (self )
464
+ with _disabled_init (_AbstractPlayMenu ):
465
+ QVBoxLayout .__init__ (self )
459
466
self ._slider = QSlider (Qt .Horizontal )
460
467
self ._slider .setMinimum (rng [0 ])
461
468
self ._slider .setMaximum (rng [1 ])
@@ -540,7 +547,8 @@ def __init__(
540
547
window = window ,
541
548
)
542
549
_Widget .__init__ (self )
543
- QMessageBox .__init__ (self , parent = window )
550
+ with _disabled_init (_AbstractPopup ):
551
+ QMessageBox .__init__ (self , parent = window )
544
552
self .setWindowTitle (title )
545
553
self .setText (text )
546
554
# icon is one of _Dialog.supported_icon_names
@@ -693,9 +701,22 @@ def _set_size(self, width=None, height=None):
693
701
# https://github.com/mne-tools/mne-python/issues/9182
694
702
695
703
704
+ # This is necessary to make PySide6 happy -- something weird with the
705
+ # __init__ calling causes the _AbstractXYZ class __init__ to be called twice
706
+ @contextmanager
707
+ def _disabled_init (klass ):
708
+ orig = klass .__init__
709
+ klass .__init__ = lambda * args , ** kwargs : None
710
+ try :
711
+ yield
712
+ finally :
713
+ klass .__init__ = orig
714
+
715
+
696
716
class _MNEMainWindow (MainWindow ):
697
717
def __init__ (self , parent = None , title = None , size = None ):
698
- MainWindow .__init__ (self , parent = parent , title = title , size = size )
718
+ with _disabled_init (_Widget ):
719
+ MainWindow .__init__ (self , parent = parent , title = title , size = size )
699
720
self .setAttribute (Qt .WA_ShowWithoutActivating , True )
700
721
self .setAttribute (Qt .WA_DeleteOnClose , True )
701
722
0 commit comments