Preferences/Shortcuts.py

changeset 12
1d8dd9706f46
parent 7
c679fb30c8f3
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
5 5
6 """ 6 """
7 Module implementing functions dealing with keyboard shortcuts. 7 Module implementing functions dealing with keyboard shortcuts.
8 """ 8 """
9 9
10 import cStringIO 10 import io
11 11
12 from PyQt4.QtCore import * 12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import * 13 from PyQt4.QtGui import *
14 14
15 from E4Gui.E4Application import e4App 15 from E4Gui.E4Application import e4App
199 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), 199 QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"),
200 QApplication.translate("Shortcuts", 200 QApplication.translate("Shortcuts",
201 """Compressed keyboard shortcut files""" 201 """Compressed keyboard shortcut files"""
202 """ not supported. The compression library is missing.""")) 202 """ not supported. The compression library is missing."""))
203 return 0 203 return 0
204 f = gzip.open(fn, "wb") 204 f = gzip.open(fn, "w")
205 else: 205 else:
206 f = open(fn, "wb") 206 f = open(fn, "w")
207 207
208 ShortcutsWriter(f).writeXML() 208 ShortcutsWriter(f).writeXML()
209 209
210 f.close() 210 f.close()
211 return True 211 return True
228 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), 228 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
229 QApplication.translate("Shortcuts", 229 QApplication.translate("Shortcuts",
230 """Compressed keyboard shortcut files""" 230 """Compressed keyboard shortcut files"""
231 """ not supported. The compression library is missing.""")) 231 """ not supported. The compression library is missing."""))
232 return False 232 return False
233 f = gzip.open(fn, "rb") 233 f = gzip.open(fn, "r")
234 else: 234 else:
235 f = open(fn, "rb") 235 f = open(fn, "r")
236 try: 236 try:
237 line = f.readline() 237 line = f.readline()
238 dtdLine = f.readline() 238 dtdLine = f.readline()
239 finally: 239 finally:
240 f.close() 240 f.close()
269 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"), 269 QApplication.translate("Shortcuts", "Import Keyboard Shortcuts"),
270 QApplication.translate("Shortcuts", 270 QApplication.translate("Shortcuts",
271 """Compressed keyboard shortcut files""" 271 """Compressed keyboard shortcut files"""
272 """ not supported. The compression library is missing.""")) 272 """ not supported. The compression library is missing."""))
273 return False 273 return False
274 f = gzip.open(fn, "rb") 274 f = gzip.open(fn, "r")
275 else: 275 else:
276 f = open(fn, "rb") 276 f = open(fn, "r")
277 try: 277 try:
278 try: 278 try:
279 parser.parse(f) 279 parser.parse(f)
280 except UnicodeEncodeError: 280 except UnicodeEncodeError:
281 f.seek(0) 281 f.seek(0)
282 buf = cStringIO.StringIO(f.read()) 282 buf = io.StringIO(f.read())
283 parser.parse(buf) 283 parser.parse(buf)
284 finally: 284 finally:
285 f.close() 285 f.close()
286 except IOError: 286 except IOError:
287 QMessageBox.critical(None, 287 QMessageBox.critical(None,
332 Module function to set actions based on new format shortcuts file. 332 Module function to set actions based on new format shortcuts file.
333 333
334 @param shortcuts dictionary containing the accelerator information 334 @param shortcuts dictionary containing the accelerator information
335 read from a XML file 335 read from a XML file
336 """ 336 """
337 if shortcuts.has_key("Project"): 337 if "Project" in shortcuts:
338 __setAction(e4App().getObject("Project").getActions(), 338 __setAction(e4App().getObject("Project").getActions(),
339 shortcuts["Project"]) 339 shortcuts["Project"])
340 340
341 if shortcuts.has_key("General"): 341 if "General" in shortcuts:
342 __setAction(e4App().getObject("UserInterface").getActions('ui'), 342 __setAction(e4App().getObject("UserInterface").getActions('ui'),
343 shortcuts["General"]) 343 shortcuts["General"])
344 344
345 if shortcuts.has_key("Wizards"): 345 if "Wizards" in shortcuts:
346 __setAction(e4App().getObject("UserInterface").getActions('wizards'), 346 __setAction(e4App().getObject("UserInterface").getActions('wizards'),
347 shortcuts["Wizards"]) 347 shortcuts["Wizards"])
348 348
349 if shortcuts.has_key("Debug"): 349 if "Debug" in shortcuts:
350 __setAction(e4App().getObject("DebugUI").getActions(), 350 __setAction(e4App().getObject("DebugUI").getActions(),
351 shortcuts["Debug"]) 351 shortcuts["Debug"])
352 352
353 if shortcuts.has_key("Edit"): 353 if "Edit" in shortcuts:
354 __setAction(e4App().getObject("ViewManager").getActions('edit'), 354 __setAction(e4App().getObject("ViewManager").getActions('edit'),
355 shortcuts["Edit"]) 355 shortcuts["Edit"])
356 356
357 if shortcuts.has_key("File"): 357 if "File" in shortcuts:
358 __setAction(e4App().getObject("ViewManager").getActions('file'), 358 __setAction(e4App().getObject("ViewManager").getActions('file'),
359 shortcuts["File"]) 359 shortcuts["File"])
360 360
361 if shortcuts.has_key("Search"): 361 if "Search" in shortcuts:
362 __setAction(e4App().getObject("ViewManager").getActions('search'), 362 __setAction(e4App().getObject("ViewManager").getActions('search'),
363 shortcuts["Search"]) 363 shortcuts["Search"])
364 364
365 if shortcuts.has_key("View"): 365 if "View" in shortcuts:
366 __setAction(e4App().getObject("ViewManager").getActions('view'), 366 __setAction(e4App().getObject("ViewManager").getActions('view'),
367 shortcuts["View"]) 367 shortcuts["View"])
368 368
369 if shortcuts.has_key("Macro"): 369 if "Macro" in shortcuts:
370 __setAction(e4App().getObject("ViewManager").getActions('macro'), 370 __setAction(e4App().getObject("ViewManager").getActions('macro'),
371 shortcuts["Macro"]) 371 shortcuts["Macro"])
372 372
373 if shortcuts.has_key("Bookmarks"): 373 if "Bookmarks" in shortcuts:
374 __setAction(e4App().getObject("ViewManager").getActions('bookmark'), 374 __setAction(e4App().getObject("ViewManager").getActions('bookmark'),
375 shortcuts["Bookmarks"]) 375 shortcuts["Bookmarks"])
376 376
377 if shortcuts.has_key("Spelling"): 377 if "Spelling" in shortcuts:
378 __setAction(e4App().getObject("ViewManager").getActions('spelling'), 378 __setAction(e4App().getObject("ViewManager").getActions('spelling'),
379 shortcuts["Spelling"]) 379 shortcuts["Spelling"])
380 380
381 if shortcuts.has_key("Window"): 381 if "Window" in shortcuts:
382 actions = e4App().getObject("ViewManager").getActions('window') 382 actions = e4App().getObject("ViewManager").getActions('window')
383 if actions: 383 if actions:
384 __setAction(actions, shortcuts["Window"]) 384 __setAction(actions, shortcuts["Window"])
385 385
386 for category, ref in e4App().getPluginObjects(): 386 for category, ref in e4App().getPluginObjects():
387 if shortcuts.has_key(category) and hasattr(ref, "getActions"): 387 if category in shortcuts and hasattr(ref, "getActions"):
388 actions = ref.getActions() 388 actions = ref.getActions()
389 __setAction(actions, shortcuts[category]) 389 __setAction(actions, shortcuts[category])
390 390
391 if shortcuts.has_key("HelpViewer"): 391 if "HelpViewer" in shortcuts:
392 __setAction(e4App().getObject("DummyHelpViewer").getActions(), 392 __setAction(e4App().getObject("DummyHelpViewer").getActions(),
393 shortcuts["HelpViewer"]) 393 shortcuts["HelpViewer"])

eric ide

mercurial