1
- # -*- coding: utf-8 -*-
2
1
"""Base classes and functions for 2D browser backends."""
3
2
4
3
# Author: Martin Schulz <[email protected] >
@@ -1457,7 +1456,7 @@ def mouseDragEvent(self, event, axis=None):
1457
1456
self .mne .overview_bar .update_annotations ()
1458
1457
else :
1459
1458
x_to = self .mapSceneToView (event .scenePos ()).x ()
1460
- with SignalBlocker (self ._drag_region ):
1459
+ with QSignalBlocker (self ._drag_region ):
1461
1460
self ._drag_region .setRegion ((self ._drag_start , x_to ))
1462
1461
1463
1462
elif event .isFinish ():
@@ -2481,7 +2480,7 @@ def _region_changed(self):
2481
2480
for region in overlapping_regions :
2482
2481
self .weakmain ()._remove_region (region , from_annot = False )
2483
2482
# re-set while blocking the signal to avoid re-running this function
2484
- with SignalBlocker (self ):
2483
+ with QSignalBlocker (self ):
2485
2484
self .setRegion ((onset , offset ))
2486
2485
2487
2486
self .update_label_pos ()
@@ -2654,7 +2653,7 @@ def mouseDragEvent(self, ev):
2654
2653
for pos in new_pos :
2655
2654
pos .setX (pos .x () - shift )
2656
2655
2657
- with SignalBlocker (self .lines [0 ]):
2656
+ with QSignalBlocker (self .lines [0 ]):
2658
2657
for pos , line in zip (new_pos , self .lines ):
2659
2658
line .setPos (pos )
2660
2659
self .prepareGeometryChange ()
@@ -3066,9 +3065,9 @@ def update_values(self, region):
3066
3065
rgn = region .getRegion ()
3067
3066
self .start_bx .setEnabled (True )
3068
3067
self .stop_bx .setEnabled (True )
3069
- with SignalBlocker (self .start_bx ):
3068
+ with QSignalBlocker (self .start_bx ):
3070
3069
self .start_bx .setValue (rgn [0 ])
3071
- with SignalBlocker (self .stop_bx ):
3070
+ with QSignalBlocker (self .stop_bx ):
3072
3071
self .stop_bx .setValue (rgn [1 ])
3073
3072
3074
3073
def _update_description_cmbx (self ):
@@ -3087,9 +3086,9 @@ def reset(self):
3087
3086
if self .description_cmbx .count () > 0 :
3088
3087
self .description_cmbx .setCurrentIndex (0 )
3089
3088
self .mne .current_description = self .description_cmbx .currentText ()
3090
- with SignalBlocker (self .start_bx ):
3089
+ with QSignalBlocker (self .start_bx ):
3091
3090
self .start_bx .setValue (0 )
3092
- with SignalBlocker (self .stop_bx ):
3091
+ with QSignalBlocker (self .stop_bx ):
3093
3092
self .stop_bx .setValue (1 / self .mne .info ["sfreq" ])
3094
3093
3095
3094
def _show_help (self ):
@@ -4096,7 +4095,7 @@ def hscroll(self, step):
4096
4095
del step
4097
4096
4098
4097
# Get current range and add step to it
4099
- xmin , xmax = [ i + rel_step for i in self .mne .viewbox .viewRange ()[0 ]]
4098
+ xmin , xmax = ( i + rel_step for i in self .mne .viewbox .viewRange ()[0 ])
4100
4099
4101
4100
if xmin < 0 :
4102
4101
xmin = 0
@@ -4125,7 +4124,7 @@ def vscroll(self, step):
4125
4124
step = self .mne .n_channels
4126
4125
elif step == "-full" :
4127
4126
step = - self .mne .n_channels
4128
- ymin , ymax = [ i + step for i in self .mne .viewbox .viewRange ()[1 ]]
4127
+ ymin , ymax = ( i + step for i in self .mne .viewbox .viewRange ()[1 ])
4129
4128
4130
4129
if ymin < 0 :
4131
4130
ymin = 0
@@ -4696,9 +4695,9 @@ def _remove_region(self, region, from_annot=True):
4696
4695
# disable, reset start/stop doubleSpinBox until another region is selected
4697
4696
self .mne .fig_annotation .start_bx .setEnabled (False )
4698
4697
self .mne .fig_annotation .stop_bx .setEnabled (False )
4699
- with SignalBlocker (self .mne .fig_annotation .start_bx ):
4698
+ with QSignalBlocker (self .mne .fig_annotation .start_bx ):
4700
4699
self .mne .fig_annotation .start_bx .setValue (0 )
4701
- with SignalBlocker (self .mne .fig_annotation .stop_bx ):
4700
+ with QSignalBlocker (self .mne .fig_annotation .stop_bx ):
4702
4701
self .mne .fig_annotation .stop_bx .setValue (1 / self .mne .info ["sfreq" ])
4703
4702
4704
4703
# Remove from annotations
@@ -5191,12 +5190,12 @@ def _fake_click(
5191
5190
add_points [idx ] = self .mne .viewbox .mapViewToScene (Point (* apoint ))
5192
5191
5193
5192
elif xform == "none" or xform is None :
5194
- if isinstance (point , ( tuple , list ) ):
5193
+ if isinstance (point , tuple | list ):
5195
5194
point = Point (* point )
5196
5195
else :
5197
5196
point = Point (point )
5198
5197
for idx , apoint in enumerate (add_points ):
5199
- if isinstance (apoint , ( tuple , list ) ):
5198
+ if isinstance (apoint , tuple | list ):
5200
5199
add_points [idx ] = Point (* apoint )
5201
5200
else :
5202
5201
add_points [idx ] = Point (apoint )
@@ -5452,22 +5451,6 @@ def _init_browser(**kwargs):
5452
5451
return browser
5453
5452
5454
5453
5455
- class SignalBlocker (QSignalBlocker ):
5456
- """Wrapper to use QSignalBlocker as a context manager in PySide2."""
5457
-
5458
- def __enter__ (self ):
5459
- if hasattr (super (), "__enter__" ):
5460
- super ().__enter__ ()
5461
- else :
5462
- super ().reblock ()
5463
-
5464
- def __exit__ (self , exc_type , exc_value , traceback ):
5465
- if hasattr (super (), "__exit__" ):
5466
- super ().__exit__ (exc_type , exc_value , traceback )
5467
- else :
5468
- super ().unblock ()
5469
-
5470
-
5471
5454
def _set_window_flags (widget ):
5472
5455
if os .getenv ("_MNE_BROWSER_BACK" , "" ).lower () == "true" :
5473
5456
widget .setWindowFlags (widget .windowFlags () | Qt .WindowStaysOnBottomHint )
0 commit comments