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" ),
@@ -130,11 +130,8 @@ def _create_qApp():
130
130
'versions may not work as expected.'
131
131
)
132
132
break
133
- try :
134
- QtWidgets .QApplication .setAttribute (
135
- QtCore .Qt .AA_EnableHighDpiScaling )
136
- except AttributeError : # Only for Qt>=5.6, <6.
137
- pass
133
+ QtWidgets .QApplication .setAttribute (
134
+ QtCore .Qt .ApplicationAttribute .AA_EnableHighDpiScaling )
138
135
try :
139
136
QtWidgets .QApplication .setHighDpiScaleFactorRoundingPolicy (
140
137
QtCore .Qt .HighDpiScaleFactorRoundingPolicy .PassThrough )
@@ -148,10 +145,7 @@ def _create_qApp():
148
145
app .lastWindowClosed .connect (app .quit )
149
146
cbook ._setup_new_guiapp ()
150
147
151
- try :
152
- app .setAttribute (QtCore .Qt .AA_UseHighDpiPixmaps ) # Only for Qt<6.
153
- except AttributeError :
154
- pass
148
+ app .setAttribute (QtCore .Qt .ApplicationAttribute .AA_UseHighDpiPixmaps )
155
149
156
150
return app
157
151
@@ -191,7 +185,7 @@ class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
191
185
manager_class = _api .classproperty (lambda cls : FigureManagerQT )
192
186
193
187
buttond = {
194
- getattr (_enum ( " QtCore.Qt.MouseButton" ) , k ): v for k , v in [
188
+ getattr (QtCore .Qt .MouseButton , k ): v for k , v in [
195
189
("LeftButton" , MouseButton .LEFT ),
196
190
("RightButton" , MouseButton .RIGHT ),
197
191
("MiddleButton" , MouseButton .MIDDLE ),
@@ -209,8 +203,7 @@ def __init__(self, figure=None):
209
203
self ._draw_rect_callback = lambda painter : None
210
204
self ._in_resize_event = False
211
205
212
- self .setAttribute (
213
- _enum ("QtCore.Qt.WidgetAttribute" ).WA_OpaquePaintEvent )
206
+ self .setAttribute (QtCore .Qt .WidgetAttribute .WA_OpaquePaintEvent )
214
207
self .setMouseTracking (True )
215
208
self .resize (* self .get_width_height ())
216
209
@@ -564,7 +557,7 @@ def __init__(self, canvas, num):
564
557
# StrongFocus accepts both tab and click to focus and will enable the
565
558
# canvas to process event without clicking.
566
559
# https://doc.qt.io/qt-5/qt.html#FocusPolicy-enum
567
- self .canvas .setFocusPolicy (_enum ( " QtCore.Qt.FocusPolicy" ) .StrongFocus )
560
+ self .canvas .setFocusPolicy (QtCore .Qt .FocusPolicy .StrongFocus )
568
561
self .canvas .setFocus ()
569
562
570
563
self .window .raise_ ()
@@ -642,8 +635,8 @@ def __init__(self, canvas, parent=None, coordinates=True):
642
635
"""coordinates: should we show the coordinates on the right?"""
643
636
QtWidgets .QToolBar .__init__ (self , parent )
644
637
self .setAllowedAreas (QtCore .Qt .ToolBarArea (
645
- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .TopToolBarArea ) |
646
- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .BottomToolBarArea ) ))
638
+ QtCore .Qt .ToolBarArea .TopToolBarArea |
639
+ QtCore .Qt .ToolBarArea .BottomToolBarArea ))
647
640
648
641
self .coordinates = coordinates
649
642
self ._actions = {} # mapping of toolitem method names to QActions.
@@ -667,11 +660,12 @@ def __init__(self, canvas, parent=None, coordinates=True):
667
660
if self .coordinates :
668
661
self .locLabel = QtWidgets .QLabel ("" , self )
669
662
self .locLabel .setAlignment (QtCore .Qt .AlignmentFlag (
670
- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignRight ) |
671
- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignVCenter )))
663
+ QtCore .Qt .AlignmentFlag .AlignRight |
664
+ QtCore .Qt .AlignmentFlag .AlignVCenter
665
+ ))
672
666
self .locLabel .setSizePolicy (QtWidgets .QSizePolicy (
673
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
674
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
667
+ QtWidgets .QSizePolicy .Policy .Expanding ,
668
+ QtWidgets .QSizePolicy .Policy .Ignored ,
675
669
))
676
670
labelAction = self .addWidget (self .locLabel )
677
671
labelAction .setVisible (True )
@@ -697,7 +691,7 @@ def _icon(self, name):
697
691
icon_color = self .palette ().color (self .foregroundRole ())
698
692
mask = pm .createMaskFromColor (
699
693
QtGui .QColor ('black' ),
700
- _enum ( " QtCore.Qt.MaskMode" ) .MaskOutColor )
694
+ QtCore .Qt .MaskMode .MaskOutColor )
701
695
pm .fill (icon_color )
702
696
pm .setMask (mask )
703
697
return QtGui .QIcon (pm )
@@ -801,8 +795,8 @@ def save_figure(self, *args):
801
795
except Exception as e :
802
796
QtWidgets .QMessageBox .critical (
803
797
self , "Error saving file" , str (e ),
804
- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .Ok ,
805
- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .NoButton )
798
+ QtWidgets .QMessageBox .StandardButton .Ok ,
799
+ QtWidgets .QMessageBox .StandardButton .NoButton )
806
800
807
801
def set_history_buttons (self ):
808
802
can_backward = self ._nav_stack ._pos > 0
@@ -916,15 +910,15 @@ def __init__(self, toolmanager, parent=None):
916
910
ToolContainerBase .__init__ (self , toolmanager )
917
911
QtWidgets .QToolBar .__init__ (self , parent )
918
912
self .setAllowedAreas (QtCore .Qt .ToolBarArea (
919
- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .TopToolBarArea ) |
920
- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .BottomToolBarArea ) ))
913
+ QtCore .Qt .ToolBarArea .TopToolBarArea |
914
+ QtCore .Qt .ToolBarArea .BottomToolBarArea ))
921
915
message_label = QtWidgets .QLabel ("" )
922
916
message_label .setAlignment (QtCore .Qt .AlignmentFlag (
923
- _to_int ( _enum ( " QtCore.Qt.AlignmentFlag" ) .AlignRight ) |
924
- _to_int ( _enum ( " QtCore.Qt.AlignmentFlag" ) .AlignVCenter ) ))
917
+ QtCore .Qt .AlignmentFlag .AlignRight |
918
+ QtCore .Qt .AlignmentFlag .AlignVCenter ))
925
919
message_label .setSizePolicy (QtWidgets .QSizePolicy (
926
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
927
- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
920
+ QtWidgets .QSizePolicy .Policy .Expanding ,
921
+ QtWidgets .QSizePolicy .Policy .Ignored ,
928
922
))
929
923
self ._message_action = self .addWidget (message_label )
930
924
self ._toolitems = {}
0 commit comments