from subprocess import * from threading import Thread import time from UIModell import Modell class ModellVisuell(Modell): def __init__(self,c, path_ov, path_files): Thread.__init__(self) Modell.__init__(self, c) self.PATH_FILES = path_files self.PATH_OV = path_ov self.aktiv= True self.openVibeAktiv = False def stop(self): print("stop thread") self.aktiv = False def setFunktion(self, func, args=None, kwargs=None): self.func = func self.args = args or [] self.kwargs = kwargs or {} def run(self): print("start thread") #self.aktiv = True t = Thread(target=self.func, args=self.args, kwargs=self.kwargs) t.setDaemon(True) t.start() while self.aktiv: time.sleep(0.1) def startCopySpelling(self): print("start copySpelling") self.controller.resetInfo() self.controller.addInfoText('start copyspelling -- ') self.controller.setTitle("Copy Spelling") path = self.PATH_FILES + 'p300-visual-1-acquisition.xml' process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], stdout=PIPE, universal_newlines=True) self.openVibeAktiv = True while True: output = process.stdout.readline() print(output.strip()) x = output.find("schlagwort?") y = output.find("Error") if(x != -1): print("Training finished") process.terminate() self.controller.addInfoText('finished Copyspelling\n') self.controller.stop("filterXdawn") break elif(y != -1 ): print("Error occured") self.controller.changeScreen("StartPage") self.controller.addInfoText("Fehler beim Copyspelling aufgetaucht\n") process.terminate() self.controller.stop() break self.controller.stop() #self.killProzess() #self.controller.filterXdawn() def trainXDawn(self): print("start training Xdawn") self.controller.addInfoText('start training XDawn -- ') path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' #path = 'Projekte/test.xml' process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], stdout=PIPE, universal_newlines=True) self.openVibeAktiv = True while self.aktiv: output = process.stdout.readline() print(output.strip()) x = output.find("Training finished and saved") y = output.find("Error") if(x != -1): print("Training finished") process.terminate() self.controller.addInfoText('finished Training\n') self.controller.stop("filterClassic") break elif(y != -1 ): print("Error occured") self.controller.changeScreen("StartPage") self.controller.addInfoText("Fehler beim XDawn Training aufgetaucht\n") self.controller.stop() process.terminate() break self.controller.stop() #self.controller.filterClassic() def trainClassifier(self): print("start training Classifier") self.controller.addInfoText("start training with Classifier -- ") path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml' process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], stdout=PIPE, universal_newlines=True) self.openVibeAktiv = True counter = 0 while True: output = process.stdout.readline() print(output.strip()) x = output.find("aka Classifier trainer") accuracy = output.find("Training set accuracy is") y = output.find("Error") if(x != -1): counter = counter +1 #counter = 18 if(counter >= 17): print("Training finished") self.controller.addInfoText('finished Training\n') process.terminate() self.controller.stop("save") break elif(y != -1 ): print("Error occured") self.controller.changeScreen("StartPage") self.controller.addInfoText("Fehler beim Classifier Training aufgetaucht\n") process.terminate() break elif(accuracy != -1): print("ACCURACY" + output) self.controller.changeScreen("StartPage") self.controller.stop() def freeSpelling(self): #bei error auch abrechen? print("start freeSpelling") self.controller.resetInfo() self.controller.addInfoText('start free spelling -- ') path = self.PATH_FILES + 'p300-visual-4-online.xml' process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], stdout=PIPE, universal_newlines=True) self.openVibeAktiv = True while True: output = process.stdout.readline() print(output.strip()) y = output.find("Error") x = output.find("Schlagwort") if(x != -1): print("End Spelling") process.terminate() self.controller.addInfoText('finished freespelling\n') self.controller.changeScreen("StartPage") self.controller.stop() break elif(y != -1 ): print("Error occured") self.controller.changeScreen("StartPage") self.controller.addInfoText("Fehler beim Freespelling aufgetaucht\n") process.terminate() self.controller.stop() break self.controller.changeScreen("StartPage") self.controller.stop() def killProzess(self): if(self.openVibeAktiv): self.openVibeAktiv = False print('start killing') pidOV = 0 items = [] prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip() zeilen = prozesse.split('\n') for z in zeilen: if(z.find("openvibe-design") != -1): z = z.strip() items = z.split(' ') pidOV = items[0] #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen) Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate() print("killed openvibe-designer")