Sun, 02 Jan 2011 10:27:16 +0100
Preparing new release.
# -*- coding: utf-8 -*- # Copyright (c) 2003 - 2011 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the handler class for reading a keyboard shortcuts file. """ from .Config import shortcutsFileFormatVersion from .XMLHandlerBase import XMLHandlerBase class ShortcutsHandler(XMLHandlerBase): """ Class implementing a sax handler to read a keyboard shortcuts file. """ def __init__(self): """ Constructor """ XMLHandlerBase.__init__(self) self.startDocumentSpecific = self.startDocumentShortcuts self.elements.update({ 'Shortcuts' : (self.startShortcuts, self.defaultEndElement), 'Shortcut' : (self.startShortcut, self.endShortcut), 'Name' : (self.defaultStartElement, self.endName), 'Accel' : (self.defaultStartElement, self.endAccel), 'AltAccel' : (self.defaultStartElement, self.endAltAccel), }) def startDocumentShortcuts(self): """ Handler called, when the document parsing is started. """ self.shortcuts = {} # dictionary for storing the shortcuts self.version = '' ################################################### ## below follow the individual handler functions ################################################### def endName(self): """ Handler method for the "Name" end tag. """ self.name = self.buffer def endAccel(self): """ Handler method for the "Accel" end tag. """ self.accel = self.unescape(self.buffer) def endAltAccel(self): """ Handler method for the "AltAccel" end tag. """ self.altAccel = self.unescape(self.buffer) def startShortcut(self, attrs): """ Handler method for the "Shortcut" start tag. @param attrs list of tag attributes """ self.name = '' self.accel = '' self.altAccel = '' self.category = attrs.get('category', '') def endShortcut(self): """ Handler method for the "Shortcut" end tag. """ if self.category: if self.category not in self.shortcuts: self.shortcuts[self.category] = {} self.shortcuts[self.category][self.name] = (self.accel, self.altAccel) def startShortcuts(self, attrs): """ Handler method for the "Shortcuts" start tag. @param attrs list of tag attributes """ self.version = attrs.get('version', shortcutsFileFormatVersion) def getShortcuts(self): """ Public method to retrieve the shortcuts. @return Dictionary of dictionaries of shortcuts. The keys of the dictionary are the categories, the values are dictionaries. These dictionaries have the shortcut name as their key and a tuple of accelerators as their value. """ return self.shortcuts def getVersion(self): """ Public method to retrieve the version of the shortcuts. @return String containing the version number. """ return self.version