Preferences/ShortcutsDialog.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
29 @signal updateShortcuts() emitted when the user pressed the dialogs OK button 29 @signal updateShortcuts() emitted when the user pressed the dialogs OK button
30 """ 30 """
31 updateShortcuts = pyqtSignal() 31 updateShortcuts = pyqtSignal()
32 32
33 objectNameRole = Qt.UserRole 33 objectNameRole = Qt.UserRole
34 noCheckRole = Qt.UserRole + 1 34 noCheckRole = Qt.UserRole + 1
35 objectTypeRole = Qt.UserRole + 2 35 objectTypeRole = Qt.UserRole + 2
36 36
37 def __init__(self, parent = None, name = None, modal = False): 37 def __init__(self, parent=None, name=None, modal=False):
38 """ 38 """
39 Constructor 39 Constructor
40 40
41 @param parent The parent widget of this dialog. (QWidget) 41 @param parent The parent widget of this dialog. (QWidget)
42 @param name The name of this dialog. (string) 42 @param name The name of this dialog. (string)
57 57
58 def __resort(self): 58 def __resort(self):
59 """ 59 """
60 Private method to resort the tree. 60 Private method to resort the tree.
61 """ 61 """
62 self.shortcutsList.sortItems(self.shortcutsList.sortColumn(), 62 self.shortcutsList.sortItems(self.shortcutsList.sortColumn(),
63 self.shortcutsList.header().sortIndicatorOrder()) 63 self.shortcutsList.header().sortIndicatorOrder())
64 64
65 def __resizeColumns(self): 65 def __resizeColumns(self):
66 """ 66 """
67 Private method to resize the list columns. 67 Private method to resize the list columns.
78 """ 78 """
79 itm = QTreeWidgetItem(self.shortcutsList, [title]) 79 itm = QTreeWidgetItem(self.shortcutsList, [title])
80 itm.setExpanded(True) 80 itm.setExpanded(True)
81 return itm 81 return itm
82 82
83 def __generateShortcutItem(self, category, action, 83 def __generateShortcutItem(self, category, action,
84 noCheck = False, objectType = ""): 84 noCheck=False, objectType=""):
85 """ 85 """
86 Private method to generate a keyboard shortcut item. 86 Private method to generate a keyboard shortcut item.
87 87
88 @param category reference to the category item (QTreeWidgetItem) 88 @param category reference to the category item (QTreeWidgetItem)
89 @param action reference to the keyboard action (E5Action) 89 @param action reference to the keyboard action (E5Action)
90 @keyparam noCheck flag indicating that no uniqueness check should 90 @keyparam noCheck flag indicating that no uniqueness check should
91 be performed (boolean) 91 be performed (boolean)
92 @keyparam objectType type of the object (string). Objects of the same type 92 @keyparam objectType type of the object (string). Objects of the same type
93 are not checked for duplicate shortcuts. 93 are not checked for duplicate shortcuts.
94 """ 94 """
95 itm = QTreeWidgetItem(category, 95 itm = QTreeWidgetItem(category,
96 [action.iconText(), action.shortcut().toString(), 96 [action.iconText(), action.shortcut().toString(),
97 action.alternateShortcut().toString()]) 97 action.alternateShortcut().toString()])
98 itm.setIcon(0, action.icon()) 98 itm.setIcon(0, action.icon())
99 itm.setData(0, self.objectNameRole, action.objectName()) 99 itm.setData(0, self.objectNameRole, action.objectName())
100 itm.setData(0, self.noCheckRole, noCheck) 100 itm.setData(0, self.noCheckRole, noCheck)
101 if objectType: 101 if objectType:
171 for category, ref in e5App().getPluginObjects(): 171 for category, ref in e5App().getPluginObjects():
172 if hasattr(ref, "getActions"): 172 if hasattr(ref, "getActions"):
173 categoryItem = self.__generateCategoryItem(category) 173 categoryItem = self.__generateCategoryItem(category)
174 objectType = e5App().getPluginObjectType(category) 174 objectType = e5App().getPluginObjectType(category)
175 for act in ref.getActions(): 175 for act in ref.getActions():
176 self.__generateShortcutItem(categoryItem, act, 176 self.__generateShortcutItem(categoryItem, act,
177 objectType = objectType) 177 objectType=objectType)
178 self.pluginCategoryItems.append(categoryItem) 178 self.pluginCategoryItems.append(categoryItem)
179 179
180 self.helpViewerItem = self.__generateCategoryItem(self.trUtf8("Web Browser")) 180 self.helpViewerItem = self.__generateCategoryItem(self.trUtf8("Web Browser"))
181 for act in e5App().getObject("DummyHelpViewer").getActions(): 181 for act in e5App().getObject("DummyHelpViewer").getActions():
182 self.__generateShortcutItem(self.helpViewerItem, act, True) 182 self.__generateShortcutItem(self.helpViewerItem, act, True)
196 if itm.childCount(): 196 if itm.childCount():
197 return 197 return
198 198
199 self.__editTopItem = itm.parent() 199 self.__editTopItem = itm.parent()
200 200
201 self.shortcutDialog.setKeys(QKeySequence(itm.text(1)), QKeySequence(itm.text(2)), 201 self.shortcutDialog.setKeys(QKeySequence(itm.text(1)), QKeySequence(itm.text(2)),
202 itm.data(0, self.noCheckRole), 202 itm.data(0, self.noCheckRole),
203 itm.data(0, self.objectTypeRole)) 203 itm.data(0, self.objectTypeRole))
204 self.shortcutDialog.show() 204 self.shortcutDialog.show()
205 205
206 def on_shortcutsList_itemClicked(self, itm, column): 206 def on_shortcutsList_itemClicked(self, itm, column):
207 """ 207 """
223 @param column column changed (integer) 223 @param column column changed (integer)
224 """ 224 """
225 if column != 0: 225 if column != 0:
226 keystr = itm.text(column).title() 226 keystr = itm.text(column).title()
227 if not itm.data(0, self.noCheckRole) and \ 227 if not itm.data(0, self.noCheckRole) and \
228 not self.__checkShortcut(QKeySequence(keystr), 228 not self.__checkShortcut(QKeySequence(keystr),
229 itm.data(0, self.objectTypeRole), 229 itm.data(0, self.objectTypeRole),
230 itm.parent()): 230 itm.parent()):
231 itm.setText(column, "") 231 itm.setText(column, "")
232 else: 232 else:
233 itm.setText(column, keystr) 233 itm.setText(column, keystr)
234 self.shortcutsList.closePersistentEditor(itm, column) 234 self.shortcutsList.closePersistentEditor(itm, column)
236 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, objectType): 236 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, objectType):
237 """ 237 """
238 Private slot to handle the shortcutChanged signal of the shortcut dialog. 238 Private slot to handle the shortcutChanged signal of the shortcut dialog.
239 239
240 @param keysequence the keysequence of the changed action (QKeySequence) 240 @param keysequence the keysequence of the changed action (QKeySequence)
241 @param altKeysequence the alternative keysequence of the changed 241 @param altKeysequence the alternative keysequence of the changed
242 action (QKeySequence) 242 action (QKeySequence)
243 @param noCheck flag indicating that no uniqueness check should 243 @param noCheck flag indicating that no uniqueness check should
244 be performed (boolean) 244 be performed (boolean)
245 @param objectType type of the object (string). 245 @param objectType type of the object (string).
246 """ 246 """
298 self.trUtf8( 298 self.trUtf8(
299 """<p><b>{0}</b> has already been allocated""" 299 """<p><b>{0}</b> has already been allocated"""
300 """ to the <b>{1}</b> action. """ 300 """ to the <b>{1}</b> action. """
301 """Remove this binding?</p>""") 301 """Remove this binding?</p>""")
302 .format(keystr, itm.text(0)), 302 .format(keystr, itm.text(0)),
303 icon = E5MessageBox.Warning) 303 icon=E5MessageBox.Warning)
304 if res: 304 if res:
305 itm.setText(col, "") 305 itm.setText(col, "")
306 return True 306 return True
307 else: 307 else:
308 return False 308 return False
316 self.trUtf8("Edit shortcuts"), 316 self.trUtf8("Edit shortcuts"),
317 self.trUtf8( 317 self.trUtf8(
318 """<p><b>{0}</b> hides the <b>{1}</b> action. """ 318 """<p><b>{0}</b> hides the <b>{1}</b> action. """
319 """Remove this binding?</p>""") 319 """Remove this binding?</p>""")
320 .format(keystr, itm.text(0)), 320 .format(keystr, itm.text(0)),
321 icon = E5MessageBox.Warning) 321 icon=E5MessageBox.Warning)
322 if res: 322 if res:
323 itm.setText(col, "") 323 itm.setText(col, "")
324 return True 324 return True
325 else: 325 else:
326 return False 326 return False
332 self.trUtf8( 332 self.trUtf8(
333 """<p><b>{0}</b> is hidden by the """ 333 """<p><b>{0}</b> is hidden by the """
334 """<b>{1}</b> action. """ 334 """<b>{1}</b> action. """
335 """Remove this binding?</p>""") 335 """Remove this binding?</p>""")
336 .format(keystr, itm.text(0)), 336 .format(keystr, itm.text(0)),
337 icon = E5MessageBox.Warning) 337 icon=E5MessageBox.Warning)
338 if res: 338 if res:
339 itm.setText(col, "") 339 itm.setText(col, "")
340 return True 340 return True
341 else: 341 else:
342 return False 342 return False
361 361
362 def on_buttonBox_accepted(self): 362 def on_buttonBox_accepted(self):
363 """ 363 """
364 Private slot to handle the OK button press. 364 Private slot to handle the OK button press.
365 """ 365 """
366 self.__saveCategoryActions(self.projectItem, 366 self.__saveCategoryActions(self.projectItem,
367 e5App().getObject("Project").getActions()) 367 e5App().getObject("Project").getActions())
368 self.__saveCategoryActions(self.uiItem, 368 self.__saveCategoryActions(self.uiItem,
369 e5App().getObject("UserInterface").getActions('ui')) 369 e5App().getObject("UserInterface").getActions('ui'))
370 self.__saveCategoryActions(self.wizardsItem, 370 self.__saveCategoryActions(self.wizardsItem,
371 e5App().getObject("UserInterface").getActions('wizards')) 371 e5App().getObject("UserInterface").getActions('wizards'))
372 self.__saveCategoryActions(self.debugItem, 372 self.__saveCategoryActions(self.debugItem,
373 e5App().getObject("DebugUI").getActions()) 373 e5App().getObject("DebugUI").getActions())
374 self.__saveCategoryActions(self.editItem, 374 self.__saveCategoryActions(self.editItem,
375 e5App().getObject("ViewManager").getActions('edit')) 375 e5App().getObject("ViewManager").getActions('edit'))
376 self.__saveCategoryActions(self.fileItem, 376 self.__saveCategoryActions(self.fileItem,
377 e5App().getObject("ViewManager").getActions('file')) 377 e5App().getObject("ViewManager").getActions('file'))
378 self.__saveCategoryActions(self.searchItem, 378 self.__saveCategoryActions(self.searchItem,
379 e5App().getObject("ViewManager").getActions('search')) 379 e5App().getObject("ViewManager").getActions('search'))
380 self.__saveCategoryActions(self.viewItem, 380 self.__saveCategoryActions(self.viewItem,
381 e5App().getObject("ViewManager").getActions('view')) 381 e5App().getObject("ViewManager").getActions('view'))
382 self.__saveCategoryActions(self.macroItem, 382 self.__saveCategoryActions(self.macroItem,
383 e5App().getObject("ViewManager").getActions('macro')) 383 e5App().getObject("ViewManager").getActions('macro'))
384 self.__saveCategoryActions(self.bookmarkItem, 384 self.__saveCategoryActions(self.bookmarkItem,
385 e5App().getObject("ViewManager").getActions('bookmark')) 385 e5App().getObject("ViewManager").getActions('bookmark'))
386 self.__saveCategoryActions(self.spellingItem, 386 self.__saveCategoryActions(self.spellingItem,
387 e5App().getObject("ViewManager").getActions('spelling')) 387 e5App().getObject("ViewManager").getActions('spelling'))
388 388
389 actions = e5App().getObject("ViewManager").getActions('window') 389 actions = e5App().getObject("ViewManager").getActions('window')
390 if actions: 390 if actions:
391 self.__saveCategoryActions(self.windowItem, actions) 391 self.__saveCategoryActions(self.windowItem, actions)
394 category = categoryItem.text(0) 394 category = categoryItem.text(0)
395 ref = e5App().getPluginObject(category) 395 ref = e5App().getPluginObject(category)
396 if ref is not None and hasattr(ref, "getActions"): 396 if ref is not None and hasattr(ref, "getActions"):
397 self.__saveCategoryActions(categoryItem, ref.getActions()) 397 self.__saveCategoryActions(categoryItem, ref.getActions())
398 398
399 self.__saveCategoryActions(self.helpViewerItem, 399 self.__saveCategoryActions(self.helpViewerItem,
400 e5App().getObject("DummyHelpViewer").getActions()) 400 e5App().getObject("DummyHelpViewer").getActions())
401 401
402 Shortcuts.saveShortcuts() 402 Shortcuts.saveShortcuts()
403 Preferences.syncPreferences() 403 Preferences.syncPreferences()
404 404

eric ide

mercurial