eric6/Preferences/Shortcuts.py

changeset 8243
cc717c2ae956
parent 8143
2c730d5fd177
child 8273
698ae46f40a4
equal deleted inserted replaced
8242:aa713ac50c0d 8243:cc717c2ae956
4 # 4 #
5 5
6 """ 6 """
7 Module implementing functions dealing with keyboard shortcuts. 7 Module implementing functions dealing with keyboard shortcuts.
8 """ 8 """
9
10 import contextlib
9 11
10 from PyQt5.QtCore import QFile, QIODevice, QCoreApplication 12 from PyQt5.QtCore import QFile, QIODevice, QCoreApplication
11 from PyQt5.QtGui import QKeySequence 13 from PyQt5.QtGui import QKeySequence
12 14
13 from E5Gui.E5Application import e5App 15 from E5Gui.E5Application import e5App
93 helpViewerCategory = helpViewer.getActionsCategory() 95 helpViewerCategory = helpViewer.getActionsCategory()
94 for act in helpViewer.getActions(): 96 for act in helpViewer.getActions():
95 __readShortcut(act, helpViewerCategory, prefClass) 97 __readShortcut(act, helpViewerCategory, prefClass)
96 98
97 if pluginName is not None: 99 if pluginName is not None:
98 try: 100 with contextlib.suppress(KeyError):
99 ref = e5App().getPluginObject(pluginName) 101 ref = e5App().getPluginObject(pluginName)
100 if hasattr(ref, "getActions"): 102 if hasattr(ref, "getActions"):
101 actions = ref.getActions() 103 actions = ref.getActions()
102 for act in actions: 104 for act in actions:
103 __readShortcut(act, pluginName, prefClass) 105 __readShortcut(act, pluginName, prefClass)
104 except KeyError:
105 # silently ignore non available plugins
106 pass
107 106
108 107
109 def __saveShortcut(act, category, prefClass): 108 def __saveShortcut(act, category, prefClass):
110 """ 109 """
111 Private function to write a single keyboard shortcut to the settings. 110 Private function to write a single keyboard shortcut to the settings.
290 one category 289 one category
291 @type dict 290 @type dict
292 """ 291 """
293 for act in actions: 292 for act in actions:
294 if act.objectName(): 293 if act.objectName():
295 try: 294 with contextlib.suppress(KeyError):
296 accel, altAccel = shortcutsDict[act.objectName()] 295 accel, altAccel = shortcutsDict[act.objectName()]
297 act.setShortcut(QKeySequence(accel)) 296 act.setShortcut(QKeySequence(accel))
298 act.setAlternateShortcut(QKeySequence(altAccel), 297 act.setAlternateShortcut(QKeySequence(altAccel),
299 removeEmpty=True) 298 removeEmpty=True)
300 except KeyError:
301 pass
302 299
303 300
304 def setActions(shortcuts, helpViewer=None): 301 def setActions(shortcuts, helpViewer=None):
305 """ 302 """
306 Module function to set actions based on the imported shortcuts file. 303 Module function to set actions based on the imported shortcuts file.

eric ide

mercurial