src/eric7/Preferences/ShortcutDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
--- a/src/eric7/Preferences/ShortcutDialog.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/Preferences/ShortcutDialog.py	Wed Jul 13 14:55:47 2022 +0200
@@ -17,16 +17,17 @@
 class ShortcutDialog(QDialog, Ui_ShortcutDialog):
     """
     Class implementing a dialog for the configuration of a keyboard shortcut.
-    
+
     @signal shortcutChanged(QKeySequence, QKeySequence, bool, string) emitted
         after the OK button was pressed
     """
+
     shortcutChanged = pyqtSignal(QKeySequence, QKeySequence, bool, str)
-    
+
     def __init__(self, parent=None, name=None, modal=False):
         """
         Constructor
-        
+
         @param parent The parent widget of this dialog. (QWidget)
         @param name The name of this dialog. (string)
         @param modal Flag indicating a modal dialog. (boolean)
@@ -37,17 +38,17 @@
         self.setModal(modal)
         self.setupUi(self)
         self.setWindowFlags(Qt.WindowType.Window)
-        
+
         self.__clearKeys()
-        
+
         self.noCheck = False
         self.objectType = ""
-        
+
         self.primaryClearButton.clicked.connect(self.__clear)
         self.alternateClearButton.clicked.connect(self.__clear)
         self.primaryButton.clicked.connect(self.__typeChanged)
         self.alternateButton.clicked.connect(self.__typeChanged)
-        
+
         self.shortcutsGroup.installEventFilter(self)
         self.primaryButton.installEventFilter(self)
         self.alternateButton.installEventFilter(self)
@@ -55,15 +56,17 @@
         self.alternateClearButton.installEventFilter(self)
         self.keyEdit.installEventFilter(self)
         self.alternateKeyEdit.installEventFilter(self)
-        
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).installEventFilter(
+            self
+        )
         self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).installEventFilter(self)
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Cancel).installEventFilter(self)
-        
+            QDialogButtonBox.StandardButton.Cancel
+        ).installEventFilter(self)
+
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
-    
+
     def __clearKeys(self):
         """
         Private method to clear the list of recorded keys.
@@ -73,13 +76,13 @@
             QKeyCombination(),
             QKeyCombination(),
             QKeyCombination(),
-            QKeyCombination()
+            QKeyCombination(),
         ]
-    
+
     def setKeys(self, key, alternateKey, noCheck, objectType):
         """
         Public method to set the key to be configured.
-        
+
         @param key key sequence to be changed (QKeySequence)
         @param alternateKey alternate key sequence to be changed (QKeySequence)
         @param noCheck flag indicating that no uniqueness check should
@@ -87,13 +90,13 @@
         @param objectType type of the object (string).
         """
         self.__clearKeys()
-        
+
         self.keyEdit.setText(key.toString())
         self.alternateKeyEdit.setText(alternateKey.toString())
         self.primaryButton.setChecked(True)
         self.noCheck = noCheck
         self.objectType = objectType
-        
+
     def on_buttonBox_accepted(self):
         """
         Private slot to handle the OK button press.
@@ -102,7 +105,9 @@
         self.shortcutChanged.emit(
             QKeySequence(self.keyEdit.text()),
             QKeySequence(self.alternateKeyEdit.text()),
-            self.noCheck, self.objectType)
+            self.noCheck,
+            self.objectType,
+        )
 
     def __clear(self):
         """
@@ -110,28 +115,28 @@
         """
         self.__clearKeys()
         self.__setKeyEditText("")
-        
+
     def __typeChanged(self):
         """
         Private slot to handle the change of the shortcuts type.
         """
         self.__clearKeys()
-        
+
     def __setKeyEditText(self, txt):
         """
         Private method to set the text of a key edit.
-        
+
         @param txt text to be set (string)
         """
         if self.primaryButton.isChecked():
             self.keyEdit.setText(txt)
         else:
             self.alternateKeyEdit.setText(txt)
-        
+
     def eventFilter(self, watched, event):
         """
         Public method called to filter the event queue.
-        
+
         @param watched the QObject being watched
         @param event the event that occurred
         @return always False
@@ -139,38 +144,43 @@
         if event.type() == QEvent.Type.KeyPress:
             self.keyPressEvent(event)
             return True
-            
+
         return False
-        
+
     def keyPressEvent(self, evt):
         """
         Protected method to handle a key press event.
-        
+
         @param evt the key event (QKeyEvent)
         """
         if evt.key() in [
-            Qt.Key.Key_Control, Qt.Key.Key_Meta, Qt.Key.Key_Shift,
-            Qt.Key.Key_Alt, Qt.Key.Key_Menu,
-            Qt.Key.Key_Hyper_L, Qt.Key.Key_Hyper_R,
-            Qt.Key.Key_Super_L, Qt.Key.Key_Super_R
+            Qt.Key.Key_Control,
+            Qt.Key.Key_Meta,
+            Qt.Key.Key_Shift,
+            Qt.Key.Key_Alt,
+            Qt.Key.Key_Menu,
+            Qt.Key.Key_Hyper_L,
+            Qt.Key.Key_Hyper_R,
+            Qt.Key.Key_Super_L,
+            Qt.Key.Key_Super_R,
         ]:
             return
-    
+
         if self.keyIndex == 4:
             self.__clearKeys()
-    
+
         if (
-            evt.key() == Qt.Key.Key_Backtab and
-            evt.modifiers() & Qt.KeyboardModifier.ShiftModifier
+            evt.key() == Qt.Key.Key_Backtab
+            and evt.modifiers() & Qt.KeyboardModifier.ShiftModifier
         ):
-            self.keys[self.keyIndex] = QKeyCombination(evt.modifiers(),
-                                                       Qt.Key.Key_Tab)
+            self.keys[self.keyIndex] = QKeyCombination(evt.modifiers(), Qt.Key.Key_Tab)
         else:
-            self.keys[self.keyIndex] = QKeyCombination(evt.modifiers(),
-                                                       Qt.Key(evt.key()))
-        
+            self.keys[self.keyIndex] = QKeyCombination(
+                evt.modifiers(), Qt.Key(evt.key())
+            )
+
         self.keyIndex += 1
-        
+
         if self.keyIndex == 1:
             ks = QKeySequence(self.keys[0])
         elif self.keyIndex == 2:
@@ -178,8 +188,5 @@
         elif self.keyIndex == 3:
             ks = QKeySequence(self.keys[0], self.keys[1], self.keys[2])
         elif self.keyIndex == 4:
-            ks = QKeySequence(
-                self.keys[0], self.keys[1], self.keys[2], self.keys[3])
-        self.__setKeyEditText(
-            ks.toString(QKeySequence.SequenceFormat.NativeText)
-        )
+            ks = QKeySequence(self.keys[0], self.keys[1], self.keys[2], self.keys[3])
+        self.__setKeyEditText(ks.toString(QKeySequence.SequenceFormat.NativeText))

eric ide

mercurial