def main(): pygame.init() myfont = pygame.font.SysFont("freesansbold", 30) #Dette bruges til at køre Sopare process = subprocess.Popen(('./sopare.py -l'), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, close_fds=ON_POSIX, cwd="../sopare") q = Queue() t = threading.Thread(target=enqueue_output, args=(process.stdout, q)) t.daemon = True t.start() while True: #using our enqueue_output thread to find out if sopare has sent anything try: line = q.get_nowait() # or q.get(timeout=.1) except Empty: pass #do nothing else: # got a line from sopare nextline = line if process.poll() is not None: break #decoding from bytes to string currentline = nextline.decode() #This is where our if/elif statements will control the GPIO pins when a specific word is recognized if("ropox" in currentline): table.goUp(5) #Needs all logic and the command tree #optimized layoutcontrol if(currentScreen == "main"): sixButtonLayout(["PROFIL", "BORD", "SKAB", u"LÅS", "OVN", "INDSTILLINGER"], myfont) elif(currentScreen == "table"): sixButtonLayout(["OP", u"HØJDE", u"LÅS", "NED", "PROFIL", "TILBAGE"], myfont) # display headline pygame.display.set_caption('ROPOX') text("ROPOX", myfont, (width/2, height/10)) pygame.display.flip() #managing clicks on buttons keepGoing = sixButtonEventHandler() if not keepGoing: break screen.fill(bg) clock.tick(fps) pygame.quit() if(os.name != "nt"): table.cleanUp() sys.exit
def main(): global screen global currentScreen global listening global tablelistening screen = pygame.display.set_mode(size) pygame.init() pygame.mouse.set_visible(False) myfont = pygame.font.SysFont("freesansbold", 30) #Dette bruges til at køre Sopare process = subprocess.Popen(('./sopare.py -l'), shell = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, close_fds=ON_POSIX, cwd="../sopare") q = Queue() #Maybe little q in queue t = Thread(target=enqueue_output, args=(process.stdout, q)) t.daemon = True t.start() try: while True: #using our enqueue_output thread to find out if sopare has sent anything try: line = q.get_nowait() # or q.get(timeout=.1) except Empty: pass #do nothing else: # got a line from sopare nextline = line if process.poll() is not None: break #decoding from bytes to string currentline = nextline.decode() #This is where our if/elif statements will control the GPIO pins when a specific word is recognized if("result:stop" in currentline): table.stopTable() listening = False tablelistening = False currentScreen = "main" if("result:ropox" in currentline): listening = True tablelistening = False currentScreen = "listening" waitThread = Thread(target = wait, ) waitThread.daemon = False waitThread.start #Lytter skærm if listening: if("result:table" in currentline): tablelistening = True listening = False if tablelistening: if("result:up" in currentline): table.goUp(5) tablelistening = False action = u"Bord hæves..." currentScreen = "stop" # STOP KNAP osv. elif("result:down" in currentline): table.goDown(5) tablelistening = False action = u"Bord kører ned..." currentScreen = "stop" # STOP KNAP osv. #optimized layoutcontrol if(currentScreen == "main"): sixButtonLayout(["PROFIL", "BORD", "SKAB", u"LÅS", "OVN", "INDSTILLINGER"], myfont) # 123Ovn kunne måske ændres til træning elif(currentScreen == "table"): sixButtonLayout(["OP", u"HØJDE", u"LÅS", "NED", "PROFIL", "TILBAGE"], myfont) elif(currentScreen == "settings"): sixButtonLayout(["Sprog", u"Træn", u"Følsomhed", "Udtræk Data", "Ydligere?", "TILBAGE"], myfont) elif(currentScreen == "training"): sixButtonLayout(["Ropox", u"Bord", u"Hæv", "Ned", "Stop", "TILBAGE"], myfont) elif(currentScreen == "stop"): stopButtonLayout("STOP", myfont, action) elif(currentScreen == "listening"): if(listening): listeningLayout("Lytter...") elif(tablelistening): listeningLayout("Bord...") #123 Her kunne laves endnu et elif(): med nogle navne til knapper i træningsscreen, op, ned, ropox, bord tilbage #Currentscreen kunne blive døbt training pygame.display.set_caption('ROPOX') if(currentScreen != "stop"): # display headline text("ROPOX", myfont, (width/2, height/10)) pygame.display.flip() #managing clicks on buttons if(currentScreen == "stop"): keepGoing = stopButtonEventHandler() else: keepGoing = sixButtonEventHandler() if not keepGoing: break screen.fill(bg) clock.tick(fps) except Exception as e: os.killpg(os.getpgid(process.pid), signal.SIGTERM) table.stopTable() table.cleanUp() print(e) os.killpg(os.getpgid(process.pid), signal.SIGTERM) table.stopTable() pygame.quit() if(os.name != "nt"): table.cleanUp() sys.exit