src/eric7/Preferences/ShortcutsDialog.py

branch
eric7
changeset 10428
a071d4065202
parent 10069
435cc5875135
child 10439
21c28b0f9e41
equal deleted inserted replaced
10427:3733e2b23cf7 10428:a071d4065202
47 """ 47 """
48 super().__init__(parent) 48 super().__init__(parent)
49 self.setupUi(self) 49 self.setupUi(self)
50 self.setWindowFlags(Qt.WindowType.Window) 50 self.setWindowFlags(Qt.WindowType.Window)
51 51
52 self.__helpViewer = None 52 self.__webBrowser = None
53 53
54 self.shortcutsList.headerItem().setText(self.shortcutsList.columnCount(), "") 54 self.shortcutsList.headerItem().setText(self.shortcutsList.columnCount(), "")
55 self.shortcutsList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder) 55 self.shortcutsList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder)
56 56
57 self.shortcutDialog = ShortcutDialog() 57 self.shortcutDialog = ShortcutDialog()
77 77
78 def __generateCategoryItem(self, title): 78 def __generateCategoryItem(self, title):
79 """ 79 """
80 Private method to generate a category item. 80 Private method to generate a category item.
81 81
82 @param title title for the item (string) 82 @param title title for the item
83 @return reference to the category item (QTreeWidgetItem) 83 @type str
84 @return reference to the category item
85 @rtype QTreeWidgetItem
84 """ 86 """
85 itm = QTreeWidgetItem(self.shortcutsList, [title]) 87 itm = QTreeWidgetItem(self.shortcutsList, [title])
86 itm.setExpanded(True) 88 itm.setExpanded(True)
87 return itm 89 return itm
88 90
89 def __generateShortcutItem(self, category, action, noCheck=False, objectType=""): 91 def __generateShortcutItem(self, category, action, noCheck=False, objectType=""):
90 """ 92 """
91 Private method to generate a keyboard shortcut item. 93 Private method to generate a keyboard shortcut item.
92 94
93 @param category reference to the category item (QTreeWidgetItem) 95 @param category reference to the category item
94 @param action reference to the keyboard action (EricAction) 96 @type QTreeWidgetItem
97 @param action reference to the keyboard action
98 @type EricAction
95 @param noCheck flag indicating that no uniqueness check should 99 @param noCheck flag indicating that no uniqueness check should
96 be performed (boolean) 100 be performed
97 @param objectType type of the object (string). Objects of the same 101 @type bool
102 @param objectType type of the object. Objects of the same
98 type are not checked for duplicate shortcuts. 103 type are not checked for duplicate shortcuts.
104 @type str
99 """ 105 """
100 itm = QTreeWidgetItem( 106 itm = QTreeWidgetItem(
101 category, 107 category,
102 [ 108 [
103 action.iconText(), 109 action.iconText(),
111 if objectType: 117 if objectType:
112 itm.setData(0, self.objectTypeRole, objectType) 118 itm.setData(0, self.objectTypeRole, objectType)
113 else: 119 else:
114 itm.setData(0, self.objectTypeRole, None) 120 itm.setData(0, self.objectTypeRole, None)
115 121
116 def populate(self, helpViewer=None): 122 def populate(self, webBrowser=None):
117 """ 123 """
118 Public method to populate the dialog. 124 Public method to populate the dialog.
119 125
120 @param helpViewer reference to the help window object 126 @param webBrowser reference to the web browser window object
127 @type WebBrowserWindow
121 """ 128 """
122 self.searchEdit.clear() 129 self.searchEdit.clear()
123 self.searchEdit.setFocus() 130 self.searchEdit.setFocus()
124 self.shortcutsList.clear() 131 self.shortcutsList.clear()
125 self.actionButton.setChecked(True) 132 self.actionButton.setChecked(True)
126 133
127 self.__helpViewer = helpViewer 134 self.__webBrowser = webBrowser
128 135
129 if helpViewer is None: 136 if webBrowser is None:
130 # let the plugin manager create on demand plugin objects 137 # let the plugin manager create on demand plugin objects
131 pm = ericApp().getObject("PluginManager") 138 pm = ericApp().getObject("PluginManager")
132 pm.initOnDemandPlugins() 139 pm.initOnDemandPlugins()
133 140
134 # populate the various lists 141 # populate the various lists
192 categoryItem, act, objectType=objectType 199 categoryItem, act, objectType=objectType
193 ) 200 )
194 self.pluginCategoryItems.append(categoryItem) 201 self.pluginCategoryItems.append(categoryItem)
195 202
196 else: 203 else:
197 self.helpViewerItem = self.__generateCategoryItem( 204 self.__webBrowserItem = self.__generateCategoryItem(
198 self.tr("eric Web Browser") 205 self.tr("eric Web Browser")
199 ) 206 )
200 for act in helpViewer.getActions(): 207 for act in webBrowser.getActions():
201 self.__generateShortcutItem(self.helpViewerItem, act, True) 208 self.__generateShortcutItem(self.__webBrowserItem, act, True)
202 209
203 self.__resort() 210 self.__resort()
204 self.__resizeColumns() 211 self.__resizeColumns()
205 212
206 self.__editTopItem = None 213 self.__editTopItem = None
208 @pyqtSlot(QTreeWidgetItem, int) 215 @pyqtSlot(QTreeWidgetItem, int)
209 def on_shortcutsList_itemDoubleClicked(self, itm, column): 216 def on_shortcutsList_itemDoubleClicked(self, itm, column):
210 """ 217 """
211 Private slot to handle a double click in the shortcuts list. 218 Private slot to handle a double click in the shortcuts list.
212 219
213 @param itm the list item that was double clicked (QTreeWidgetItem) 220 @param itm the list item that was double clicked
214 @param column the list item was double clicked in (integer) 221 @type QTreeWidgetItem
222 @param column the list item was double clicked in
223 @type int
215 """ 224 """
216 if itm.childCount(): 225 if itm.childCount():
217 return 226 return
218 227
219 self.__editTopItem = itm.parent() 228 self.__editTopItem = itm.parent()
228 237
229 def on_shortcutsList_itemClicked(self, itm, column): 238 def on_shortcutsList_itemClicked(self, itm, column):
230 """ 239 """
231 Private slot to handle a click in the shortcuts list. 240 Private slot to handle a click in the shortcuts list.
232 241
233 @param itm the list item that was clicked (QTreeWidgetItem) 242 @param itm the list item that was clicked
234 @param column the list item was clicked in (integer) 243 @type QTreeWidgetItem
244 @param column the list item was clicked in
245 @type int
235 """ 246 """
236 if itm.childCount() or column not in [1, 2]: 247 if itm.childCount() or column not in [1, 2]:
237 return 248 return
238 249
239 self.shortcutsList.openPersistentEditor(itm, column) 250 self.shortcutsList.openPersistentEditor(itm, column)
240 251
241 def on_shortcutsList_itemChanged(self, itm, column): 252 def on_shortcutsList_itemChanged(self, itm, column):
242 """ 253 """
243 Private slot to handle the edit of a shortcut key. 254 Private slot to handle the edit of a shortcut key.
244 255
245 @param itm reference to the item changed (QTreeWidgetItem) 256 @param itm reference to the item changed
246 @param column column changed (integer) 257 @type QTreeWidgetItem
258 @param column column changed
259 @type int
247 """ 260 """
248 if column != 0: 261 if column != 0:
249 keystr = itm.text(column).title() 262 keystr = itm.text(column).title()
250 if not itm.data(0, self.noCheckRole) and not self.__checkShortcut( 263 if not itm.data(0, self.noCheckRole) and not self.__checkShortcut(
251 QKeySequence(keystr), itm.data(0, self.objectTypeRole), itm.parent() 264 QKeySequence(keystr), itm.data(0, self.objectTypeRole), itm.parent()
258 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, objectType): 271 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, objectType):
259 """ 272 """
260 Private slot to handle the shortcutChanged signal of the shortcut 273 Private slot to handle the shortcutChanged signal of the shortcut
261 dialog. 274 dialog.
262 275
263 @param keysequence the keysequence of the changed action (QKeySequence) 276 @param keysequence the keysequence of the changed action
264 @param altKeysequence the alternative keysequence of the changed 277 @type QKeySequence
265 action (QKeySequence) 278 @param altKeysequence the alternative keysequence of the changed action
266 @param noCheck flag indicating that no uniqueness check should 279 @type QKeySequence
267 be performed (boolean) 280 @param noCheck flag indicating that no uniqueness check should be performed
268 @param objectType type of the object (string). 281 @type bool
282 @param objectType type of the object
283 @type str
269 """ 284 """
270 if not noCheck and ( 285 if not noCheck and (
271 not self.__checkShortcut(keysequence, objectType, self.__editTopItem) 286 not self.__checkShortcut(keysequence, objectType, self.__editTopItem)
272 or not self.__checkShortcut(altKeysequence, objectType, self.__editTopItem) 287 or not self.__checkShortcut(altKeysequence, objectType, self.__editTopItem)
273 ): 288 ):
281 296
282 def __checkShortcut(self, keysequence, objectType, origTopItem): 297 def __checkShortcut(self, keysequence, objectType, origTopItem):
283 """ 298 """
284 Private method to check a keysequence for uniqueness. 299 Private method to check a keysequence for uniqueness.
285 300
286 @param keysequence the keysequence to check (QKeySequence) 301 @param keysequence the keysequence to check
287 @param objectType type of the object (string). Entries with the same 302 @type QKeySequence
303 @param objectType type of the object. Entries with the same
288 object type are not checked for uniqueness. 304 object type are not checked for uniqueness.
305 @type str
289 @param origTopItem refrence to the parent of the item to be checked 306 @param origTopItem refrence to the parent of the item to be checked
290 (QTreeWidgetItem) 307 @type QTreeWidgetItem
291 @return flag indicating uniqueness (boolean) 308 @return flag indicating uniqueness
309 @rtype bool
292 """ 310 """
293 if keysequence.isEmpty(): 311 if keysequence.isEmpty():
294 return True 312 return True
295 313
296 keystr = keysequence.toString() 314 keystr = keysequence.toString()
379 397
380 def __saveCategoryActions(self, category, actions): 398 def __saveCategoryActions(self, category, actions):
381 """ 399 """
382 Private method to save the actions for a category. 400 Private method to save the actions for a category.
383 401
384 @param category reference to the category item (QTreeWidgetItem) 402 @param category reference to the category item
385 @param actions list of actions for the category (list of EricAction) 403 @type QTreeWidgetItem
404 @param actions list of actions for the category
405 @type list of EricAction
386 """ 406 """
387 for index in range(category.childCount()): 407 for index in range(category.childCount()):
388 itm = category.child(index) 408 itm = category.child(index)
389 txt = itm.data(0, self.objectNameRole) 409 txt = itm.data(0, self.objectNameRole)
390 for act in actions: 410 for act in actions:
397 417
398 def on_buttonBox_accepted(self): 418 def on_buttonBox_accepted(self):
399 """ 419 """
400 Private slot to handle the OK button press. 420 Private slot to handle the OK button press.
401 """ 421 """
402 if self.__helpViewer is None: 422 if self.__webBrowser is None:
403 self.__saveCategoryActions( 423 self.__saveCategoryActions(
404 self.projectItem, ericApp().getObject("Project").getActions() 424 self.projectItem, ericApp().getObject("Project").getActions()
405 ) 425 )
406 self.__saveCategoryActions( 426 self.__saveCategoryActions(
407 self.uiItem, ericApp().getObject("UserInterface").getActions("ui") 427 self.uiItem, ericApp().getObject("UserInterface").getActions("ui")
449 469
450 Shortcuts.saveShortcuts() 470 Shortcuts.saveShortcuts()
451 471
452 else: 472 else:
453 self.__saveCategoryActions( 473 self.__saveCategoryActions(
454 self.helpViewerItem, self.__helpViewer.getActions() 474 self.__webBrowserItem, self.__webBrowser.getActions()
455 ) 475 )
456 Shortcuts.saveShortcuts(helpViewer=self.__helpViewer) 476 Shortcuts.saveShortcuts(webBrowser=self.__webBrowser)
457 477
458 Preferences.syncPreferences() 478 Preferences.syncPreferences()
459 479
460 self.updateShortcuts.emit() 480 self.updateShortcuts.emit()
461 self.hide() 481 self.hide()
463 @pyqtSlot(str) 483 @pyqtSlot(str)
464 def on_searchEdit_textChanged(self, txt): 484 def on_searchEdit_textChanged(self, txt):
465 """ 485 """
466 Private slot called, when the text in the search edit changes. 486 Private slot called, when the text in the search edit changes.
467 487
468 @param txt text of the search edit (string) 488 @param txt text of the search edit
489 @type str
469 """ 490 """
470 rx = re.compile(re.escape(txt), re.IGNORECASE) 491 rx = re.compile(re.escape(txt), re.IGNORECASE)
471 for topIndex in range(self.shortcutsList.topLevelItemCount()): 492 for topIndex in range(self.shortcutsList.topLevelItemCount()):
472 topItem = self.shortcutsList.topLevelItem(topIndex) 493 topItem = self.shortcutsList.topLevelItem(topIndex)
473 childHiddenCount = 0 494 childHiddenCount = 0
490 @pyqtSlot(bool) 511 @pyqtSlot(bool)
491 def on_actionButton_toggled(self, checked): 512 def on_actionButton_toggled(self, checked):
492 """ 513 """
493 Private slot called, when the action radio button is toggled. 514 Private slot called, when the action radio button is toggled.
494 515
495 @param checked state of the action radio button (boolean) 516 @param checked state of the action radio button
517 @type bool
496 """ 518 """
497 if checked: 519 if checked:
498 self.on_searchEdit_textChanged(self.searchEdit.text()) 520 self.on_searchEdit_textChanged(self.searchEdit.text())
499 521
500 @pyqtSlot(bool) 522 @pyqtSlot(bool)
501 def on_shortcutButton_toggled(self, checked): 523 def on_shortcutButton_toggled(self, checked):
502 """ 524 """
503 Private slot called, when the shortcuts radio button is toggled. 525 Private slot called, when the shortcuts radio button is toggled.
504 526
505 @param checked state of the shortcuts radio button (boolean) 527 @param checked state of the shortcuts radio button
528 @type bool
506 """ 529 """
507 if checked: 530 if checked:
508 self.on_searchEdit_textChanged(self.searchEdit.text()) 531 self.on_searchEdit_textChanged(self.searchEdit.text())

eric ide

mercurial