14
14
from . import qt_compat
15
15
from .qt_compat import (
16
16
QtCore , QtGui , QtWidgets , __version__ , QT_API ,
17
- _enum , _to_int , _isdeleted , _maybe_allow_interrupt
17
+ _to_int , _isdeleted , _maybe_allow_interrupt
18
18
)
19
19
20
20
21
21
# SPECIAL_KEYS are Qt::Key that do *not* return their Unicode name
22
22
# instead they have manually specified names.
23
23
SPECIAL_KEYS = {
24
- _to_int (getattr (_enum ( " QtCore.Qt.Key" ) , k )): v for k , v in [
24
+ _to_int (getattr (QtCore .Qt .Key , k )): v for k , v in [
25
25
("Key_Escape" , "escape" ),
26
26
("Key_Tab" , "tab" ),
27
27
("Key_Backspace" , "backspace" ),
66
66
# Elements are (Qt::KeyboardModifiers, Qt::Key) tuples.
67
67
# Order determines the modifier order (ctrl+alt+...) reported by Matplotlib.
68
68
_MODIFIER_KEYS = [
69
- (_to_int (getattr (_enum ( " QtCore.Qt.KeyboardModifier" ) , mod )),
70
- _to_int (getattr (_enum ( " QtCore.Qt.Key" ) , key )))
69
+ (_to_int (getattr (QtCore .Qt .KeyboardModifier , mod )),
70
+ _to_int (getattr (QtCore .Qt .Key , key )))
71
71
for mod , key in [
72
72
("ControlModifier" , "Key_Control" ),
73
73
("AltModifier" , "Key_Alt" ),
76
76
]
77
77
]
78
78
cursord = {
79
- k : getattr (_enum ( " QtCore.Qt.CursorShape" ) , v ) for k , v in [
79
+ k : getattr (QtCore .Qt .CursorShape , v ) for k , v in [
80
80
(cursors .MOVE , "SizeAllCursor" ),
81
81
(cursors .HAND , "PointingHandCursor" ),
82
82
(cursors .POINTER , "ArrowCursor" ),
@@ -132,8 +132,8 @@ def _create_qApp():
132
132
break
133
133
try :
134
134
QtWidgets .QApplication .setAttribute (
135
- QtCore .Qt .AA_EnableHighDpiScaling )
136
- except AttributeError : # Only for Qt>=5.6, <6.
135
+ QtCore .Qt .ApplicationAttribute . AA_EnableHighDpiScaling )
136
+ except AttributeError :
137
137
pass
138
138
try :
139
139
QtWidgets .QApplication .setHighDpiScaleFactorRoundingPolicy (
@@ -147,9 +147,9 @@ def _create_qApp():
147
147
app .setWindowIcon (icon )
148
148
app .lastWindowClosed .connect (app .quit )
149
149
cbook ._setup_new_guiapp ()
150
-
151
150
try :
152
- app .setAttribute (QtCore .Qt .AA_UseHighDpiPixmaps ) # Only for Qt<6.
151
+ # Only for Qt<6.
152
+ app .setAttribute (QtCore .Qt .ApplicationAttribute .AA_UseHighDpiPixmaps )
153
153
except AttributeError :
154
154
pass
155
155
@@ -191,7 +191,7 @@ class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
191
191
manager_class = _api .classproperty (lambda cls : FigureManagerQT )
192
192
193
193
buttond = {
194
- getattr (_enum ( " QtCore.Qt.MouseButton" ) , k ): v for k , v in [
194
+ getattr (QtCore .Qt .MouseButton , k ): v for k , v in [
195
195
("LeftButton" , MouseButton .LEFT ),
196
196
("RightButton" , MouseButton .RIGHT ),
197
197
("MiddleButton" , MouseButton .MIDDLE ),
@@ -209,8 +209,7 @@ def __init__(self, figure=None):
209
209
self ._draw_rect_callback = lambda painter : None
210
210
self ._in_resize_event = False
211
211
212
- self .setAttribute (
213
- _enum ("QtCore.Qt.WidgetAttribute" ).WA_OpaquePaintEvent )
212
+ self .setAttribute (QtCore .Qt .WidgetAttribute .WA_OpaquePaintEvent )
214
213
self .setMouseTracking (True )
215
214
self .resize (* self .get_width_height ())
216
215
@@ -564,7 +563,7 @@ def __init__(self, canvas, num):
564
563
# StrongFocus accepts both tab and click to focus and will enable the
565
564
# canvas to process event without clicking.
566
565
# https://doc.qt.io/qt-5/qt.html#FocusPolicy-enum
567
- self .canvas .setFocusPolicy (_enum ( " QtCore.Qt.FocusPolicy" ) .StrongFocus )
566
+ self .canvas .setFocusPolicy (QtCore .Qt .FocusPolicy .StrongFocus )
568
567
self .canvas .setFocus ()
569
568
570
569
self .window .raise_ ()
@@ -642,9 +641,8 @@ def __init__(self, canvas, parent=None, coordinates=True):
642
641
"""coordinates: should we show the coordinates on the right?"""
643
642
QtWidgets .QToolBar .__init__ (self , parent )
644
643
self .setAllowedAreas (QtCore .Qt .ToolBarArea (
645
- _to_int (_enum ("QtCore.Qt.ToolBarArea" ).TopToolBarArea ) |
646
- _to_int (_enum ("QtCore.Qt.ToolBarArea" ).BottomToolBarArea )))
647
-
644
+ _to_int (QtCore .Qt .ToolBarArea .TopToolBarArea ) |
645
+ _to_int (QtCore .Qt .ToolBarArea .BottomToolBarArea )))
648
646
self .coordinates = coordinates
649
647
self ._actions = {} # mapping of toolitem method names to QActions.
650
648
self ._subplot_dialog = None
@@ -667,11 +665,12 @@ def __init__(self, canvas, parent=None, coordinates=True):
667
665
if self .coordinates :
668
666
self .locLabel = QtWidgets .QLabel ("" , self )
669
667
self .locLabel .setAlignment (QtCore .Qt .AlignmentFlag (
670
- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignRight ) |
671
- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignVCenter )))
668
+ _to_int (QtCore .Qt .AlignmentFlag .AlignRight ) |
669
+ _to_int (QtCore .Qt .AlignmentFlag .AlignVCenter )))
670
+
672
671
self .locLabel .setSizePolicy (QtWidgets .QSizePolicy (
673
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
674
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
672
+ QtWidgets .QSizePolicy .Policy .Expanding ,
673
+ QtWidgets .QSizePolicy .Policy .Ignored ,
675
674
))
676
675
labelAction = self .addWidget (self .locLabel )
677
676
labelAction .setVisible (True )
@@ -697,7 +696,7 @@ def _icon(self, name):
697
696
icon_color = self .palette ().color (self .foregroundRole ())
698
697
mask = pm .createMaskFromColor (
699
698
QtGui .QColor ('black' ),
700
- _enum ( " QtCore.Qt.MaskMode" ) .MaskOutColor )
699
+ QtCore .Qt .MaskMode .MaskOutColor )
701
700
pm .fill (icon_color )
702
701
pm .setMask (mask )
703
702
return QtGui .QIcon (pm )
@@ -801,8 +800,8 @@ def save_figure(self, *args):
801
800
except Exception as e :
802
801
QtWidgets .QMessageBox .critical (
803
802
self , "Error saving file" , str (e ),
804
- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .Ok ,
805
- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .NoButton )
803
+ QtWidgets .QMessageBox .StandardButton .Ok ,
804
+ QtWidgets .QMessageBox .StandardButton .NoButton )
806
805
807
806
def set_history_buttons (self ):
808
807
can_backward = self ._nav_stack ._pos > 0
@@ -916,15 +915,15 @@ def __init__(self, toolmanager, parent=None):
916
915
ToolContainerBase .__init__ (self , toolmanager )
917
916
QtWidgets .QToolBar .__init__ (self , parent )
918
917
self .setAllowedAreas (QtCore .Qt .ToolBarArea (
919
- _to_int (_enum ( " QtCore.Qt.ToolBarArea" ) .TopToolBarArea ) |
920
- _to_int (_enum ( " QtCore.Qt.ToolBarArea" ) .BottomToolBarArea )))
918
+ _to_int (QtCore .Qt .ToolBarArea .TopToolBarArea ) |
919
+ _to_int (QtCore .Qt .ToolBarArea .BottomToolBarArea )))
921
920
message_label = QtWidgets .QLabel ("" )
922
921
message_label .setAlignment (QtCore .Qt .AlignmentFlag (
923
- _to_int (_enum ( " QtCore.Qt.AlignmentFlag" ) .AlignRight ) |
924
- _to_int (_enum ( " QtCore.Qt.AlignmentFlag" ) .AlignVCenter )))
922
+ _to_int (QtCore .Qt .AlignmentFlag .AlignRight ) |
923
+ _to_int (QtCore .Qt .AlignmentFlag .AlignVCenter )))
925
924
message_label .setSizePolicy (QtWidgets .QSizePolicy (
926
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
927
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
925
+ QtWidgets .QSizePolicy .Policy .Expanding ,
926
+ QtWidgets .QSizePolicy .Policy .Ignored ,
928
927
))
929
928
self ._message_action = self .addWidget (message_label )
930
929
self ._toolitems = {}
0 commit comments