def parse(): global keyhandles keybindingsdict = {} filehandle, filehandle2, outfilehandle = get_file_handles() parser = Parser(filehandle, filehandle2) defnum = 0 reader = protoconfparser.Read() while parser.nextLine() != "ENDFILE": if outfilehandle: if parser.getLineType() == "GOINGTOINSERTCODE": outfilehandle.write("def radium_generated_keycodedef%d():\n" % defnum) if parser.getLineType() == "INSERTCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "INSERTCODELAST": #outfilehandle.write("\treturn\n") outfilehandle.write("\n") addIt(keyhandles, parser, "keybinding.radium_generated_keycodedef%d()" % defnum) defnum += 1 if parser.getLineType() == "INSERTCLEANCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "ERROR": return False if parser.getLineType() == "NORMAL": commands = parser.getCommands() lokke = 2 while lokke < len(commands): if commands[lokke][0] == "+": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) + add) elif commands[lokke][0] == "-": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) - add) elif commands[lokke][0] == "*": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) * add) elif commands[lokke][0] == "/": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) / add) lokke += 1 command = commands[0] for c in commands[1:]: command += " " + c keybindingsdict[command] = [ map(lambda x: keysub[x], parser.getKeys()), map(lambda x: keysub[x], parser.getQualifiers()) ] #print "commands", commands pythoncall = commands.pop(0) pythoncall += "(" while len(commands) > 1: pythoncall += commands.pop(0) + "," if len(commands) > 0: pythoncall += commands.pop(0) pythoncall += ")" keys = parser.getKeys() + parser.getQualifiers() firstkey = keys.pop(0) #printsak(0,keyhandles,parser,command) addIt(keyhandles, parser, pythoncall) try: radium._keybindingsdict = keybindingsdict except: print sys.exc_info() radium.addMessage("Couldn't create keybindings dict. (" + str(sys.exc_info()) + ")") try: if filehandle: filehandle.close() if filehandle2: filehandle2.close() if outfilehandle: outfilehandle.close() except: print "Could not close file. Out of disk space?" #sys.exit(3) reload(keybinding ) # i.e re-do "import generated_keybinding_code as keybinding" #sys.exit(1) #print "BBBBBB",radium._keybindingsdict return True
def parse(): global keyhandles, radium filehandle, filehandle2, outfilehandle = get_file_handles() parser = Parser(filehandle, filehandle2) defnum = 0 reader = protoconfparser.Read() while parser.nextLine() != "ENDFILE": if outfilehandle: if parser.getLineType() == "GOINGTOINSERTCODE": outfilehandle.write("def radium_generated_keycodedef%d():\n" % defnum) if parser.getLineType() == "INSERTCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "INSERTCODELAST": #outfilehandle.write("\treturn\n") outfilehandle.write("\n") addIt(keyhandles, parser, "keybinding.radium_generated_keycodedef%d()" % defnum) defnum += 1 if parser.getLineType() == "INSERTCLEANCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "ERROR": return False if parser.getLineType() == "NORMAL": commands = parser.getCommands() lokke = 2 while lokke < len(commands): if commands[lokke][0] == "+": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) + add) elif commands[lokke][0] == "-": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) - add) elif commands[lokke][0] == "*": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) * add) elif commands[lokke][0] == "/": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) / add) lokke += 1 command = commands[0] for c in commands[1:]: command += " " + c element = [ map(lambda x: keysub[x], parser.getKeys()), sorted(map(lambda x: keysub[x], parser.getQualifiers())) ] addIt(keyhandles, parser, commands) try: if filehandle: filehandle.close() if filehandle2: filehandle2.close() if outfilehandle: outfilehandle.close() except: print "Could not close file. Out of disk space?" #sys.exit(3) if not is_mocked: reload(keybinding ) # i.e re-do "import generated_keybinding_code as keybinding" #sys.exit(1) return True
def start(keyhandles, filehandle, outfilehandle): keybindingsdict = { } # Note: Latest E-radium version has just removed everything related to keybindingsdict from this function. Could be unnecessary. parser = Parser(filehandle) defnum = 0 reader = protoconfparser.Read() while parser.nextLine() != "ENDFILE": if outfilehandle: if parser.getLineType() == "GOINGTOINSERTCODE": outfilehandle.write("def keycodedef%d():\n" % defnum) if parser.getLineType() == "INSERTCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "INSERTCODELAST": outfilehandle.write("\treturn\n") if putCode( keyhandles, parser, "eventreceiverparser_generated.keycodedef%d()" % defnum) == false: return false defnum += 1 if parser.getLineType() == "INSERTCLEANCODE": outfilehandle.write(parser.getCurrLine() + "\n") if parser.getLineType() == "ERROR": return false if parser.getLineType() == "NORMAL": commands = parser.getCommands() lokke = 2 while lokke < len(commands): if commands[lokke][0] == "+": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) + add) elif commands[lokke][0] == "-": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) - add) elif commands[lokke][0] == "*": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) * add) elif commands[lokke][0] == "/": add = int(commands.pop(lokke)[1:]) commands[lokke - 1] = "%d" % (int(commands[lokke - 1]) / add) lokke += 1 ercommands = commands[:] intercommands = range(len(ercommands)) dascommand = ercommands.pop(0) command = commands.pop(0) command += "(" while len(commands) > 1: command += commands.pop(0) + "," if len(commands) > 0: command += commands.pop(0) command += ")" keys = parser.getKeys() + parser.getQualifiers() firstkey = keys.pop(0) ccommand = false if dascommand[:3] == "ra.": ccommand = true for lokke in range(len(ercommands)): if ercommands[lokke][0] != "\"": intercommands[lokke] = ercommands[lokke] else: ccommand = false break keybindingsdict[command] = [ map(lambda x: keysub[x], parser.getKeys()), map(lambda x: keysub[x], parser.getQualifiers()) ] #printsak(0,keyhandles,parser,command) if ccommand == false: if putCode(keyhandles, parser, command) == false: print "false" return false else: success, intercommands2 = reader.getUnfoldedCall( dascommand[3:], ercommands) if not success: print "Error at line %d: \"%s\"" % ( parser.getCurrLineNum(), parser.getCurrLine()) print "-------------> " + command print "------> " + str(intercommands2[0]) return false else: retstring = radium.ER_keyAdd(firstkey, dascommand[3:], keys, intercommands2) if retstring != "OK": print "Error at line %d: \"%s\"" % ( parser.getCurrLineNum(), parser.getCurrLine()) print "------> " + str(intercommands2[0]) return false import cPickle try: keybindingsfile = open("keybindings.cPickle", "w") keybindingsfile.write(cPickle.dumps(keybindingsdict)) keybindingsfile.close() #print keybindingsdict except: print "Couldn't create keybindings.cPickle. Using default." return true