34 accel = prefClass.settings.value( |
35 accel = prefClass.settings.value( |
35 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName())) |
36 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName())) |
36 if accel is not None: |
37 if accel is not None: |
37 act.setAlternateShortcut(QKeySequence(accel)) |
38 act.setAlternateShortcut(QKeySequence(accel)) |
38 |
39 |
39 def readShortcuts(prefClass = Prefs, helpViewer = None, pluginName = None): |
40 |
|
41 def readShortcuts(prefClass=Prefs, helpViewer=None, pluginName=None): |
40 """ |
42 """ |
41 Module function to read the keyboard shortcuts for the defined QActions. |
43 Module function to read the keyboard shortcuts for the defined QActions. |
42 |
44 |
43 @keyparam prefClass preferences class used as the storage area |
45 @keyparam prefClass preferences class used as the storage area |
44 @keyparam helpViewer reference to the help window object |
46 @keyparam helpViewer reference to the help window object |
102 __readShortcut(act, pluginName, prefClass) |
104 __readShortcut(act, pluginName, prefClass) |
103 except KeyError: |
105 except KeyError: |
104 # silently ignore non available plugins |
106 # silently ignore non available plugins |
105 pass |
107 pass |
106 |
108 |
|
109 |
107 def __saveShortcut(act, category, prefClass): |
110 def __saveShortcut(act, category, prefClass): |
108 """ |
111 """ |
109 Private function to write a single keyboard shortcut to the settings. |
112 Private function to write a single keyboard shortcut to the settings. |
110 |
113 |
111 @param act reference to the action object (E5Action) |
114 @param act reference to the action object (E5Action) |
112 @param category category the action belongs to (string) |
115 @param category category the action belongs to (string) |
113 @param prefClass preferences class used as the storage area |
116 @param prefClass preferences class used as the storage area |
114 """ |
117 """ |
115 if act.objectName(): |
118 if act.objectName(): |
116 prefClass.settings.setValue( |
119 prefClass.settings.setValue( |
117 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()), |
120 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()), |
118 act.shortcut().toString()) |
121 act.shortcut().toString()) |
119 prefClass.settings.setValue( |
122 prefClass.settings.setValue( |
120 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()), |
123 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()), |
121 act.alternateShortcut().toString()) |
124 act.alternateShortcut().toString()) |
122 |
125 |
123 def saveShortcuts(prefClass = Prefs): |
126 |
|
127 def saveShortcuts(prefClass=Prefs): |
124 """ |
128 """ |
125 Module function to write the keyboard shortcuts for the defined QActions. |
129 Module function to write the keyboard shortcuts for the defined QActions. |
126 |
130 |
127 @param prefClass preferences class used as the storage area |
131 @param prefClass preferences class used as the storage area |
128 """ |
132 """ |
194 ShortcutsWriter(f).writeXML() |
199 ShortcutsWriter(f).writeXML() |
195 f.close() |
200 f.close() |
196 else: |
201 else: |
197 E5MessageBox.critical(None, |
202 E5MessageBox.critical(None, |
198 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), |
203 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), |
199 QApplication.translate("Shortcuts", |
204 QApplication.translate("Shortcuts", |
200 "<p>The keyboard shortcuts could not be written to file <b>{0}</b>.</p>") |
205 "<p>The keyboard shortcuts could not be written to file <b>{0}</b>.</p>") |
201 .format(fn)) |
206 .format(fn)) |
|
207 |
202 |
208 |
203 def importShortcuts(fn): |
209 def importShortcuts(fn): |
204 """ |
210 """ |
205 Module function to import the keyboard shortcuts for the defined E5Actions. |
211 Module function to import the keyboard shortcuts for the defined E5Actions. |
206 |
212 |
221 saveShortcuts() |
227 saveShortcuts() |
222 syncPreferences() |
228 syncPreferences() |
223 else: |
229 else: |
224 E5MessageBox.critical(None, |
230 E5MessageBox.critical(None, |
225 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
231 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), |
226 QApplication.translate("Shortcuts", |
232 QApplication.translate("Shortcuts", |
227 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
233 "<p>The keyboard shortcuts could not be read from file <b>{0}</b>.</p>") |
228 .format(fn)) |
234 .format(fn)) |
229 return |
235 return |
|
236 |
230 |
237 |
231 def __setAction(actions, sdict): |
238 def __setAction(actions, sdict): |
232 """ |
239 """ |
233 Private function to write a single keyboard shortcut to the settings. |
240 Private function to write a single keyboard shortcut to the settings. |
234 |
241 |
242 act.setShortcut(QKeySequence(accel)) |
249 act.setShortcut(QKeySequence(accel)) |
243 act.setAlternateShortcut(QKeySequence(altAccel)) |
250 act.setAlternateShortcut(QKeySequence(altAccel)) |
244 except KeyError: |
251 except KeyError: |
245 pass |
252 pass |
246 |
253 |
|
254 |
247 def setActions(shortcuts): |
255 def setActions(shortcuts): |
248 """ |
256 """ |
249 Module function to set actions based on new format shortcuts file. |
257 Module function to set actions based on new format shortcuts file. |
250 |
258 |
251 @param shortcuts dictionary containing the accelerator information |
259 @param shortcuts dictionary containing the accelerator information |
252 read from a XML file |
260 read from a XML file |
253 """ |
261 """ |
254 if "Project" in shortcuts: |
262 if "Project" in shortcuts: |
255 __setAction(e5App().getObject("Project").getActions(), |
263 __setAction(e5App().getObject("Project").getActions(), |
256 shortcuts["Project"]) |
264 shortcuts["Project"]) |
257 |
265 |
258 if "General" in shortcuts: |
266 if "General" in shortcuts: |
259 __setAction(e5App().getObject("UserInterface").getActions('ui'), |
267 __setAction(e5App().getObject("UserInterface").getActions('ui'), |
260 shortcuts["General"]) |
268 shortcuts["General"]) |
261 |
269 |
262 if "Wizards" in shortcuts: |
270 if "Wizards" in shortcuts: |
263 __setAction(e5App().getObject("UserInterface").getActions('wizards'), |
271 __setAction(e5App().getObject("UserInterface").getActions('wizards'), |
264 shortcuts["Wizards"]) |
272 shortcuts["Wizards"]) |
265 |
273 |
266 if "Debug" in shortcuts: |
274 if "Debug" in shortcuts: |
267 __setAction(e5App().getObject("DebugUI").getActions(), |
275 __setAction(e5App().getObject("DebugUI").getActions(), |
268 shortcuts["Debug"]) |
276 shortcuts["Debug"]) |
269 |
277 |
270 if "Edit" in shortcuts: |
278 if "Edit" in shortcuts: |
271 __setAction(e5App().getObject("ViewManager").getActions('edit'), |
279 __setAction(e5App().getObject("ViewManager").getActions('edit'), |
272 shortcuts["Edit"]) |
280 shortcuts["Edit"]) |
273 |
281 |
274 if "File" in shortcuts: |
282 if "File" in shortcuts: |
275 __setAction(e5App().getObject("ViewManager").getActions('file'), |
283 __setAction(e5App().getObject("ViewManager").getActions('file'), |
276 shortcuts["File"]) |
284 shortcuts["File"]) |
277 |
285 |
278 if "Search" in shortcuts: |
286 if "Search" in shortcuts: |
279 __setAction(e5App().getObject("ViewManager").getActions('search'), |
287 __setAction(e5App().getObject("ViewManager").getActions('search'), |
280 shortcuts["Search"]) |
288 shortcuts["Search"]) |
281 |
289 |
282 if "View" in shortcuts: |
290 if "View" in shortcuts: |
283 __setAction(e5App().getObject("ViewManager").getActions('view'), |
291 __setAction(e5App().getObject("ViewManager").getActions('view'), |
284 shortcuts["View"]) |
292 shortcuts["View"]) |
285 |
293 |
286 if "Macro" in shortcuts: |
294 if "Macro" in shortcuts: |
287 __setAction(e5App().getObject("ViewManager").getActions('macro'), |
295 __setAction(e5App().getObject("ViewManager").getActions('macro'), |
288 shortcuts["Macro"]) |
296 shortcuts["Macro"]) |
289 |
297 |
290 if "Bookmarks" in shortcuts: |
298 if "Bookmarks" in shortcuts: |
291 __setAction(e5App().getObject("ViewManager").getActions('bookmark'), |
299 __setAction(e5App().getObject("ViewManager").getActions('bookmark'), |
292 shortcuts["Bookmarks"]) |
300 shortcuts["Bookmarks"]) |
293 |
301 |
294 if "Spelling" in shortcuts: |
302 if "Spelling" in shortcuts: |
295 __setAction(e5App().getObject("ViewManager").getActions('spelling'), |
303 __setAction(e5App().getObject("ViewManager").getActions('spelling'), |
296 shortcuts["Spelling"]) |
304 shortcuts["Spelling"]) |
297 |
305 |
298 if "Window" in shortcuts: |
306 if "Window" in shortcuts: |
299 actions = e5App().getObject("ViewManager").getActions('window') |
307 actions = e5App().getObject("ViewManager").getActions('window') |
300 if actions: |
308 if actions: |