61 self.buttonBox.button( |
61 self.buttonBox.button( |
62 QDialogButtonBox.StandardButton.Cancel).installEventFilter(self) |
62 QDialogButtonBox.StandardButton.Cancel).installEventFilter(self) |
63 |
63 |
64 msh = self.minimumSizeHint() |
64 msh = self.minimumSizeHint() |
65 self.resize(max(self.width(), msh.width()), msh.height()) |
65 self.resize(max(self.width(), msh.width()), msh.height()) |
66 |
66 |
|
67 def __clearKeys(self): |
|
68 """ |
|
69 Private method to clear the list of recorded keys. |
|
70 """ |
|
71 self.keyIndex = 0 |
|
72 self.keys = [ |
|
73 QKeyCombination(), |
|
74 QKeyCombination(), |
|
75 QKeyCombination(), |
|
76 QKeyCombination() |
|
77 ] |
|
78 |
67 def setKeys(self, key, alternateKey, noCheck, objectType): |
79 def setKeys(self, key, alternateKey, noCheck, objectType): |
68 """ |
80 """ |
69 Public method to set the key to be configured. |
81 Public method to set the key to be configured. |
70 |
82 |
71 @param key key sequence to be changed (QKeySequence) |
83 @param key key sequence to be changed (QKeySequence) |
72 @param alternateKey alternate key sequence to be changed (QKeySequence) |
84 @param alternateKey alternate key sequence to be changed (QKeySequence) |
73 @param noCheck flag indicating that no uniqueness check should |
85 @param noCheck flag indicating that no uniqueness check should |
74 be performed (boolean) |
86 be performed (boolean) |
75 @param objectType type of the object (string). |
87 @param objectType type of the object (string). |
76 """ |
88 """ |
77 self.keyIndex = 0 |
89 self.__clearKeys() |
78 self.keys = [0, 0, 0, 0] |
90 |
79 self.keyEdit.setText(key.toString()) |
91 self.keyEdit.setText(key.toString()) |
80 self.alternateKeyEdit.setText(alternateKey.toString()) |
92 self.alternateKeyEdit.setText(alternateKey.toString()) |
81 self.primaryButton.setChecked(True) |
93 self.primaryButton.setChecked(True) |
82 self.noCheck = noCheck |
94 self.noCheck = noCheck |
83 self.objectType = objectType |
95 self.objectType = objectType |
94 |
106 |
95 def __clear(self): |
107 def __clear(self): |
96 """ |
108 """ |
97 Private slot to handle the Clear button press. |
109 Private slot to handle the Clear button press. |
98 """ |
110 """ |
99 self.keyIndex = 0 |
111 self.__clearKeys() |
100 self.keys = [0, 0, 0, 0] |
|
101 self.__setKeyEditText("") |
112 self.__setKeyEditText("") |
102 |
113 |
103 def __typeChanged(self): |
114 def __typeChanged(self): |
104 """ |
115 """ |
105 Private slot to handle the change of the shortcuts type. |
116 Private slot to handle the change of the shortcuts type. |
106 """ |
117 """ |
107 self.keyIndex = 0 |
118 self.__clearKeys() |
108 self.keys = [0, 0, 0, 0] |
|
109 |
119 |
110 def __setKeyEditText(self, txt): |
120 def __setKeyEditText(self, txt): |
111 """ |
121 """ |
112 Private method to set the text of a key edit. |
122 Private method to set the text of a key edit. |
113 |
123 |
136 """ |
146 """ |
137 Protected method to handle a key press event. |
147 Protected method to handle a key press event. |
138 |
148 |
139 @param evt the key event (QKeyEvent) |
149 @param evt the key event (QKeyEvent) |
140 """ |
150 """ |
141 # TODO: change code to use QKeyCombination |
|
142 if evt.key() in [ |
151 if evt.key() in [ |
143 Qt.Key.Key_Control, Qt.Key.Key_Meta, Qt.Key.Key_Shift, |
152 Qt.Key.Key_Control, Qt.Key.Key_Meta, Qt.Key.Key_Shift, |
144 Qt.Key.Key_Alt, Qt.Key.Key_Menu, |
153 Qt.Key.Key_Alt, Qt.Key.Key_Menu, |
145 Qt.Key.Key_Hyper_L, Qt.Key.Key_Hyper_R, |
154 Qt.Key.Key_Hyper_L, Qt.Key.Key_Hyper_R, |
146 Qt.Key.Key_Super_L, Qt.Key.Key_Super_R |
155 Qt.Key.Key_Super_L, Qt.Key.Key_Super_R |
147 ]: |
156 ]: |
148 return |
157 return |
149 |
158 |
150 if self.keyIndex == 4: |
159 if self.keyIndex == 4: |
151 self.keyIndex = 0 |
160 self.__clearKeys() |
152 self.keys = [0, 0, 0, 0] |
|
153 |
161 |
154 if ( |
162 if ( |
155 evt.key() == Qt.Key.Key_Backtab and |
163 evt.key() == Qt.Key.Key_Backtab and |
156 evt.modifiers() & Qt.KeyboardModifier.ShiftModifier |
164 evt.modifiers() & Qt.KeyboardModifier.ShiftModifier |
157 ): |
165 ): |
158 self.keys[self.keyIndex] = Qt.Key.Key_Tab |
166 self.keys[self.keyIndex] = QKeyCombination(evt.modifiers(), |
|
167 Qt.Key.Key_Tab) |
159 else: |
168 else: |
160 self.keys[self.keyIndex] = evt.key() |
169 self.keys[self.keyIndex] = QKeyCombination(evt.modifiers(), |
161 |
170 Qt.Key(evt.key())) |
162 if evt.modifiers() & Qt.KeyboardModifier.ShiftModifier: |
|
163 self.keys[self.keyIndex] += Qt.Modifier.SHIFT |
|
164 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
|
165 self.keys[self.keyIndex] += Qt.Modifier.CTRL |
|
166 if evt.modifiers() & Qt.KeyboardModifier.AltModifier: |
|
167 self.keys[self.keyIndex] += Qt.Modifier.ALT |
|
168 if evt.modifiers() & Qt.KeyboardModifier.MetaModifier: |
|
169 self.keys[self.keyIndex] += Qt.Modifier.META |
|
170 |
171 |
171 self.keyIndex += 1 |
172 self.keyIndex += 1 |
172 |
173 |
173 if self.keyIndex == 1: |
174 if self.keyIndex == 1: |
174 self.__setKeyEditText(QKeySequence(self.keys[0]).toString()) |
175 self.__setKeyEditText( |
|
176 QKeySequence( |
|
177 self.keys[0] |
|
178 ).toString(QKeySequence.SequenceFormat.NativeText) |
|
179 ) |
175 elif self.keyIndex == 2: |
180 elif self.keyIndex == 2: |
176 self.__setKeyEditText( |
181 self.__setKeyEditText( |
177 QKeySequence(self.keys[0], self.keys[1]).toString()) |
182 QKeySequence( |
|
183 self.keys[0], self.keys[1] |
|
184 ).toString(QKeySequence.SequenceFormat.NativeText) |
|
185 ) |
178 elif self.keyIndex == 3: |
186 elif self.keyIndex == 3: |
179 self.__setKeyEditText(QKeySequence( |
187 self.__setKeyEditText( |
180 self.keys[0], self.keys[1], |
188 QKeySequence( |
181 self.keys[2]).toString()) |
189 self.keys[0], self.keys[1], self.keys[2] |
|
190 ).toString(QKeySequence.SequenceFormat.NativeText) |
|
191 ) |
182 elif self.keyIndex == 4: |
192 elif self.keyIndex == 4: |
183 self.__setKeyEditText(QKeySequence( |
193 self.__setKeyEditText( |
184 self.keys[0], self.keys[1], |
194 QKeySequence( |
185 self.keys[2], self.keys[3]).toString()) |
195 self.keys[0], self.keys[1], self.keys[2], self.keys[3] |
|
196 ).toString(QKeySequence.SequenceFormat.NativeText) |
|
197 ) |