import msvcrt,math,edata,os from textbuffer import Grid import lcd from hexxi import hexxi running = True height = 8 width = 12 scale = 16 console_theme = "black_and_white" console_themes = { 'black_and_white':{ "bg":(255,255,255), "fg":(0,0,0), "padding":0, "font-data-dir":"edatas/kb" }, 'green':{ "bg":(100,200,100), "fg":(50,100,50), "padding":0, "font-data-dir":"edatas/kb" }, 'sand':{ "bg":(200,150,100), "fg":(75,50,75), "padding":0, "font-data-dir":"edatas/bff" }, 'hacker':{ "bg":(0,0,0), "fg":(0,255,0), "padding":0, "font-data-dir":"edatas/kb" } } console_theme_data = console_themes[console_theme] if not ('font-data-dir' in globals()['console_theme_data']): console_theme_data['font-data-dir'] = "" if console_theme_data["font-data-dir"] == "": console_theme_data["font-data-dir"] = "edatas" g = Grid(20,20,1,",") #Console Text Grid d = lcd.Display([6*width,8*height],scale,[lcd.pygame.Color(console_theme_data["bg"]),lcd.pygame.Color(console_theme_data["fg"])],console_theme_data["padding"]) #LCD Display d.fill() #d.init() letters = edata.read(console_theme_data["font-data-dir"]+"/letter-sprites.edata") numbers = edata.read(console_theme_data["font-data-dir"]+"/number-sprites.edata") symbols = edata.read(console_theme_data["font-data-dir"]+"/symbol-sprites.edata") phrase = "" for i in numbers: letters[i] = numbers[i] for i in symbols: letters[i] = symbols[i] x = 0 def kbfunc(): x = msvcrt.kbhit() #x = 0 if x: ret = ord(msvcrt.getch()) print ret else: ret = 0 return ret def update_key_displays(x): global g,d,letters,phrase g.put(0,0,str(x)) phrase += str(chr(x)) if chr(x) == '\r': d.fill() phrase = "" elif chr(x) == '\x08': phrase = phrase[:-2] d.sprite(((len(phrase)+1)%width)*6,8*((len(phrase)+1)/width),hexxi("0000000000000000")) d.fill(0) g.update() ph = phrase + "|" os.system("cls") print x print(phrase) for i in range(len(ph)): d.sprite((i%width)*6,8*(i/width),hexxi(letters[ph[i]])) d.update() while running: while x == 0: x = kbfunc() try: if x != 0: update_key_displays(x) else: for e in lcd.pygame.event.get(): if e.type == lcd.pygame.QUIT: running = False x = 1 if e.type == lcd.pygame.KEYDOWN: update_key_displays(e.key) except Exception as e: print e x = 0 lcd.pygame.quit()