class Keymap: """Key bindings.""" def init(self): """Initialize key map. Go through the list of mappings checking for duplicates and adding them to self.bindings. """ self.keys = [ # it's ok to leave '' for either short or long command # short command | long command | description | function ('a', "author", "search by author", books.find_author), ('t', "title", "search by title", books.find_title), ('r', "read", "read last book", last.read), ('l', "last", "list last read books", last.choose), ('q', "quit", "quit pybook", quit), ('', '', '', None), # separator ('b', "browse", "browse booklist", books.browse), ('B', "browse_authors", "browse authors", books.browse_authors), ('R', "random", "read a random book", books.read_random), ('d', "delete", "choose local book to delete", last.delete), ('h', "help", "this help message", help), ] self.bindings = {} for s, l, _, func in self.keys: if not (self.bindings.has_key(s) or self.bindings.has_key(l)): self.bindings[s] = func self.bindings[l] = func else: print "Duplicate key binding. Edit Keymap at the top of %s" % sys.argv[0] # vim: sts=4:ts=8:et:sw=4