1414from . import qt_compat
1515from .qt_compat import (
1616 QtCore , QtGui , QtWidgets , __version__ , QT_API ,
17- _enum , _to_int , _isdeleted , _maybe_allow_interrupt
17+ _to_int , _isdeleted , _maybe_allow_interrupt
1818)
1919
2020
2121# SPECIAL_KEYS are Qt::Key that do *not* return their Unicode name
2222# instead they have manually specified names.
2323SPECIAL_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 [
2525 ("Key_Escape" , "escape" ),
2626 ("Key_Tab" , "tab" ),
2727 ("Key_Backspace" , "backspace" ),
6666# Elements are (Qt::KeyboardModifiers, Qt::Key) tuples.
6767# Order determines the modifier order (ctrl+alt+...) reported by Matplotlib.
6868_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 )))
7171 for mod , key in [
7272 ("ControlModifier" , "Key_Control" ),
7373 ("AltModifier" , "Key_Alt" ),
7676 ]
7777]
7878cursord = {
79- k : getattr (_enum ( " QtCore.Qt.CursorShape" ) , v ) for k , v in [
79+ k : getattr (QtCore .Qt .CursorShape , v ) for k , v in [
8080 (cursors .MOVE , "SizeAllCursor" ),
8181 (cursors .HAND , "PointingHandCursor" ),
8282 (cursors .POINTER , "ArrowCursor" ),
@@ -132,8 +132,8 @@ def _create_qApp():
132132 break
133133 try :
134134 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 :
137137 pass
138138 try :
139139 QtWidgets .QApplication .setHighDpiScaleFactorRoundingPolicy (
@@ -147,9 +147,9 @@ def _create_qApp():
147147 app .setWindowIcon (icon )
148148 app .lastWindowClosed .connect (app .quit )
149149 cbook ._setup_new_guiapp ()
150-
151150 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 )
153153 except AttributeError :
154154 pass
155155
@@ -191,7 +191,7 @@ class FigureCanvasQT(FigureCanvasBase, QtWidgets.QWidget):
191191 manager_class = _api .classproperty (lambda cls : FigureManagerQT )
192192
193193 buttond = {
194- getattr (_enum ( " QtCore.Qt.MouseButton" ) , k ): v for k , v in [
194+ getattr (QtCore .Qt .MouseButton , k ): v for k , v in [
195195 ("LeftButton" , MouseButton .LEFT ),
196196 ("RightButton" , MouseButton .RIGHT ),
197197 ("MiddleButton" , MouseButton .MIDDLE ),
@@ -209,8 +209,7 @@ def __init__(self, figure=None):
209209 self ._draw_rect_callback = lambda painter : None
210210 self ._in_resize_event = False
211211
212- self .setAttribute (
213- _enum ("QtCore.Qt.WidgetAttribute" ).WA_OpaquePaintEvent )
212+ self .setAttribute (QtCore .Qt .WidgetAttribute .WA_OpaquePaintEvent )
214213 self .setMouseTracking (True )
215214 self .resize (* self .get_width_height ())
216215
@@ -564,7 +563,7 @@ def __init__(self, canvas, num):
564563 # StrongFocus accepts both tab and click to focus and will enable the
565564 # canvas to process event without clicking.
566565 # 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 )
568567 self .canvas .setFocus ()
569568
570569 self .window .raise_ ()
@@ -641,9 +640,9 @@ class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
641640 def __init__ (self , canvas , parent = None , coordinates = True ):
642641 """coordinates: should we show the coordinates on the right?"""
643642 QtWidgets .QToolBar .__init__ (self , parent )
644- self .setAllowedAreas (QtCore . Qt . ToolBarArea (
645- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .TopToolBarArea ) |
646- _to_int ( _enum ( " QtCore.Qt.ToolBarArea" ) .BottomToolBarArea )) )
643+ self .setAllowedAreas (
644+ QtCore .Qt .ToolBarArea .TopToolBarArea |
645+ QtCore .Qt .ToolBarArea .BottomToolBarArea )
647646
648647 self .coordinates = coordinates
649648 self ._actions = {} # mapping of toolitem method names to QActions.
@@ -666,12 +665,13 @@ def __init__(self, canvas, parent=None, coordinates=True):
666665 # will resize this label instead of the buttons.
667666 if self .coordinates :
668667 self .locLabel = QtWidgets .QLabel ("" , self )
669- self .locLabel .setAlignment (QtCore .Qt .AlignmentFlag (
670- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignRight ) |
671- _to_int (_enum ("QtCore.Qt.AlignmentFlag" ).AlignVCenter )))
668+ self .locLabel .setAlignment (
669+ QtCore .Qt .AlignmentFlag .AlignRight |
670+ QtCore .Qt .AlignmentFlag .AlignVCenter
671+ )
672672 self .locLabel .setSizePolicy (QtWidgets .QSizePolicy (
673- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
674- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
673+ QtWidgets .QSizePolicy .Policy .Expanding ,
674+ QtWidgets .QSizePolicy .Policy .Ignored ,
675675 ))
676676 labelAction = self .addWidget (self .locLabel )
677677 labelAction .setVisible (True )
@@ -697,7 +697,7 @@ def _icon(self, name):
697697 icon_color = self .palette ().color (self .foregroundRole ())
698698 mask = pm .createMaskFromColor (
699699 QtGui .QColor ('black' ),
700- _enum ( " QtCore.Qt.MaskMode" ) .MaskOutColor )
700+ QtCore .Qt .MaskMode .MaskOutColor )
701701 pm .fill (icon_color )
702702 pm .setMask (mask )
703703 return QtGui .QIcon (pm )
@@ -801,8 +801,8 @@ def save_figure(self, *args):
801801 except Exception as e :
802802 QtWidgets .QMessageBox .critical (
803803 self , "Error saving file" , str (e ),
804- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .Ok ,
805- _enum ( " QtWidgets.QMessageBox.StandardButton" ) .NoButton )
804+ QtWidgets .QMessageBox .StandardButton .Ok ,
805+ QtWidgets .QMessageBox .StandardButton .NoButton )
806806
807807 def set_history_buttons (self ):
808808 can_backward = self ._nav_stack ._pos > 0
@@ -916,15 +916,15 @@ def __init__(self, toolmanager, parent=None):
916916 ToolContainerBase .__init__ (self , toolmanager )
917917 QtWidgets .QToolBar .__init__ (self , parent )
918918 self .setAllowedAreas (QtCore .Qt .ToolBarArea (
919- _to_int (_enum ( " QtCore.Qt.ToolBarArea" ) .TopToolBarArea ) |
920- _to_int (_enum ( " QtCore.Qt.ToolBarArea" ) .BottomToolBarArea )))
919+ _to_int (QtCore .Qt .ToolBarArea .TopToolBarArea ) |
920+ _to_int (QtCore .Qt .ToolBarArea .BottomToolBarArea )))
921921 message_label = QtWidgets .QLabel ("" )
922922 message_label .setAlignment (QtCore .Qt .AlignmentFlag (
923- _to_int (_enum ( " QtCore.Qt.AlignmentFlag" ) .AlignRight ) |
924- _to_int (_enum ( " QtCore.Qt.AlignmentFlag" ) .AlignVCenter )))
923+ _to_int (QtCore .Qt .AlignmentFlag .AlignRight ) |
924+ _to_int (QtCore .Qt .AlignmentFlag .AlignVCenter )))
925925 message_label .setSizePolicy (QtWidgets .QSizePolicy (
926- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Expanding ,
927- _enum ( " QtWidgets.QSizePolicy.Policy" ) .Ignored ,
926+ QtWidgets .QSizePolicy .Policy .Expanding ,
927+ QtWidgets .QSizePolicy .Policy .Ignored ,
928928 ))
929929 self ._message_action = self .addWidget (message_label )
930930 self ._toolitems = {}
0 commit comments