# OpenViBE_visual_BCI | |||||
import UIModellVisuell as modelVisuell | import UIModellVisuell as modelVisuell | ||||
import UIModellTaktil as modelsTaktil | import UIModellTaktil as modelsTaktil | ||||
import UIViewTKinter as viewTkinter | import UIViewTKinter as viewTkinter | ||||
from shutil import copyfile | |||||
def __init__(self): | def __init__(self): | ||||
self.view = viewTkinter.View(self) | self.view = viewTkinter.View(self) | ||||
self.modi = "visuellesBCI" | self.modi = "visuellesBCI" | ||||
self.pathOVFile = "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/signals/p300-xdawn-train2.ov" | |||||
self.infotext = "" | |||||
self.commands = { | self.commands = { | ||||
"copySpelling": self.commandoCopySpelling, | "copySpelling": self.commandoCopySpelling, | ||||
"freeSpelling": self.commandFreeSpelling, | "freeSpelling": self.commandFreeSpelling, | ||||
"test": self.test, | "test": self.test, | ||||
"wechsel": self.wechsel, | "wechsel": self.wechsel, | ||||
"speicherort": self.speicherort | |||||
"speicherort": self.setDataset | |||||
} | } | ||||
self.nexts = { | self.nexts = { | ||||
"filterXdawn" : self.filterXdawn, | "filterXdawn" : self.filterXdawn, | ||||
"filterClassic": self.filterClassic | |||||
"filterClassic": self.filterClassic, | |||||
"save": self.speichern | |||||
} | } | ||||
self.pagesTaktil = { | self.pagesTaktil = { | ||||
self.view.setChangeBtnText("Wechsel zu visuellen BCI") | self.view.setChangeBtnText("Wechsel zu visuellen BCI") | ||||
self.modi = "taktilesBCI" | self.modi = "taktilesBCI" | ||||
def speicherort(self): | |||||
pass | |||||
def speichern(self): | |||||
print("saveFile") | |||||
copyfile(self.pathOVFile, self.file) | |||||
def setDataset(self): | |||||
file = self.view.openfiledialog() | |||||
copyfile(file, self.pathOVFile) | |||||
def test(self): | def test(self): | ||||
self.file = self.view.savefiledialog() | |||||
if(self.modi == "taktilesBCI"): | if(self.modi == "taktilesBCI"): | ||||
self.model = modelsTaktil.Modell(self) | self.model = modelsTaktil.Modell(self) | ||||
elif(self.modi == "visuellesBCI"): | elif(self.modi == "visuellesBCI"): | ||||
#wird durch Btn gestartet -> startet copyspelling als thread | #wird durch Btn gestartet -> startet copyspelling als thread | ||||
def commandoCopySpelling(self): | def commandoCopySpelling(self): | ||||
self.file = self.view.savefiledialog() | |||||
if(self.modi == "taktilesBCI"): | if(self.modi == "taktilesBCI"): | ||||
self.model = modelsTaktil.Modell(self) | self.model = modelsTaktil.Modell(self) | ||||
elif(self.modi == "visuellesBCI"): | elif(self.modi == "visuellesBCI"): | ||||
def commandStop(self): | def commandStop(self): | ||||
if(self.model is not None): | if(self.model is not None): | ||||
self.setInfos("Action: STOP-Command") | |||||
self.addInfoText("Action: STOP-Command") | |||||
self.model.stop() | self.model.stop() | ||||
self.model.join() | self.model.join() | ||||
self.model.killProzess() | self.model.killProzess() | ||||
func = self.nexts.get(next) | func = self.nexts.get(next) | ||||
func() | func() | ||||
def setInfos(self,text): | |||||
self.view.setInfoText(text) | |||||
def addInfoText(self,text): | |||||
self.infotext = self.infotext + text | |||||
self.view.setInfoText(self.infotext) | |||||
def resetInfo(self): | |||||
self.infotext = "" | |||||
def setTitle(self,text): | def setTitle(self,text): | ||||
self.view.setTitleText(text) | self.view.setTitleText(text) |
self.controller = c | self.controller = c | ||||
self.aktiv= True | self.aktiv= True | ||||
self.openVibeAktiv = False | self.openVibeAktiv = False | ||||
self.infoText = '' | |||||
def stop(self): | def stop(self): | ||||
print("stop thread") | print("stop thread") | ||||
def startCopySpelling(self): | def startCopySpelling(self): | ||||
print("start copySpelling") | print("start copySpelling") | ||||
self.infoText = 'start copyspelling -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.resetInfo() | |||||
self.controller.addInfoText('start copyspelling -- ') | |||||
self.controller.setTitle("Copy Spelling") | self.controller.setTitle("Copy Spelling") | ||||
path = self.PATH_FILES + 'p300-visual-1-acquisition.xml' | path = self.PATH_FILES + 'p300-visual-1-acquisition.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
if(x != -1): | if(x != -1): | ||||
print("Training finished") | print("Training finished") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished Copyspelling\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished Copyspelling\n') | |||||
self.controller.stop("filterXdawn") | self.controller.stop("filterXdawn") | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Copyspelling aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Copyspelling aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break | ||||
def trainXDawn(self): | def trainXDawn(self): | ||||
print("start training Xdawn") | print("start training Xdawn") | ||||
self.infoText = self.infoText + 'start training XDawn -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('start training XDawn -- ') | |||||
path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' | path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' | ||||
#path = 'Projekte/test.xml' | #path = 'Projekte/test.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
if(x != -1): | if(x != -1): | ||||
print("Training finished") | print("Training finished") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished Training\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished Training\n') | |||||
self.controller.stop("filterClassic") | self.controller.stop("filterClassic") | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim XDawn Training aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim XDawn Training aufgetaucht\n") | |||||
self.controller.stop() | self.controller.stop() | ||||
process.terminate() | process.terminate() | ||||
break | break | ||||
def trainClassifier(self): | def trainClassifier(self): | ||||
print("start training Classifier") | print("start training Classifier") | ||||
self.infoText = self.infoText + "start training with Classifier -- " | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText("start training with Classifier -- ") | |||||
path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml' | path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
#counter = 18 | #counter = 18 | ||||
if(counter >= 17): | if(counter >= 17): | ||||
print("Training finished") | print("Training finished") | ||||
self.infoText = self.infoText + 'finished Training\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished Training\n') | |||||
process.terminate() | process.terminate() | ||||
self.controller.stop("save") | |||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Classifier Training aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Classifier Training aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
break | break | ||||
elif(accuracy != -1): | elif(accuracy != -1): | ||||
def freeSpelling(self): | def freeSpelling(self): | ||||
#bei error auch abrechen? | #bei error auch abrechen? | ||||
print("start freeSpelling") | print("start freeSpelling") | ||||
self.infoText = 'start free spelling -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.resetInfo() | |||||
self.controller.addInfoText('start free spelling -- ') | |||||
path = self.PATH_FILES + 'p300-visual-4-online.xml' | path = self.PATH_FILES + 'p300-visual-4-online.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
stdout=PIPE, | stdout=PIPE, | ||||
if(x != -1): | if(x != -1): | ||||
print("End Spelling") | print("End Spelling") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished freespelling\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished freespelling\n') | |||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Freespelling aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Freespelling aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break |
self.controller = c | self.controller = c | ||||
self.aktiv= True | self.aktiv= True | ||||
self.openVibeAktiv = False | self.openVibeAktiv = False | ||||
self.infoText = '' | |||||
def stop(self): | def stop(self): | ||||
print("stop thread") | print("stop thread") | ||||
def startCopySpelling(self): | def startCopySpelling(self): | ||||
print("start copySpelling") | print("start copySpelling") | ||||
self.infoText = 'start copyspelling -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.resetInfo() | |||||
self.controller.addInfoText('start copyspelling -- ') | |||||
self.controller.setTitle("Copy Spelling") | self.controller.setTitle("Copy Spelling") | ||||
path = self.PATH_FILES + 'p300-visual-1-acquisition.xml' | path = self.PATH_FILES + 'p300-visual-1-acquisition.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
stdout=PIPE, | stdout=PIPE, | ||||
universal_newlines=True) | universal_newlines=True) | ||||
self.openVibeAktiv = True | |||||
self.openVibeAktiv = True | |||||
while True: | while True: | ||||
output = process.stdout.readline() | output = process.stdout.readline() | ||||
print(output.strip()) | print(output.strip()) | ||||
if(x != -1): | if(x != -1): | ||||
print("Training finished") | print("Training finished") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished Copyspelling\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished Copyspelling\n') | |||||
self.controller.stop("filterXdawn") | self.controller.stop("filterXdawn") | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Copyspelling aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Copyspelling aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break | ||||
self.controller.stop() | self.controller.stop() | ||||
#self.killProzess() | #self.killProzess() | ||||
def trainXDawn(self): | def trainXDawn(self): | ||||
print("start training Xdawn") | print("start training Xdawn") | ||||
self.infoText = self.infoText + 'start training XDawn -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('start training XDawn -- ') | |||||
path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' | path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' | ||||
#path = 'Projekte/test.xml' | |||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
stdout=PIPE, | stdout=PIPE, | ||||
universal_newlines=True) | universal_newlines=True) | ||||
if(x != -1): | if(x != -1): | ||||
print("Training finished") | print("Training finished") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished Training\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished Training\n') | |||||
self.controller.stop("filterClassic") | self.controller.stop("filterClassic") | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim XDawn Training aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim XDawn Training aufgetaucht\n") | |||||
self.controller.stop() | self.controller.stop() | ||||
process.terminate() | process.terminate() | ||||
break | break | ||||
def trainClassifier(self): | def trainClassifier(self): | ||||
print("start training Classifier") | print("start training Classifier") | ||||
self.infoText = self.infoText + "start training with Classifier -- " | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText("start training with Classifier -- ") | |||||
path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml' | path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
stdout=PIPE, | stdout=PIPE, | ||||
universal_newlines=True) | universal_newlines=True) | ||||
self.openVibeAktiv = True | |||||
self.openVibeAktiv = True | |||||
counter = 0 | |||||
while True: | while True: | ||||
output = process.stdout.readline() | output = process.stdout.readline() | ||||
print(output.strip()) | print(output.strip()) | ||||
x = output.find("schlagwort?") | |||||
x = output.find("aka Classifier trainer") | |||||
accuracy = output.find("Training set accuracy is") | |||||
y = output.find("Error") | y = output.find("Error") | ||||
if(x != -1): | if(x != -1): | ||||
print("Training finished") | |||||
self.infoText = self.infoText + 'finished Training\n' | |||||
self.controller.setInfos(self.infoText) | |||||
process.terminate() | |||||
break | |||||
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 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Classifier Training aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Classifier Training aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
break | break | ||||
elif(accuracy != -1): | |||||
print("ACCURACY" + output) | |||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.stop() | self.controller.stop() | ||||
def freeSpelling(self): | def freeSpelling(self): | ||||
#bei error auch abrechen? | #bei error auch abrechen? | ||||
print("start freeSpelling") | print("start freeSpelling") | ||||
self.infoText = 'start free spelling -- ' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.resetInfo() | |||||
self.controller.addInfoText('start free spelling -- ') | |||||
path = self.PATH_FILES + 'p300-visual-4-online.xml' | path = self.PATH_FILES + 'p300-visual-4-online.xml' | ||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'], | ||||
stdout=PIPE, | stdout=PIPE, | ||||
if(x != -1): | if(x != -1): | ||||
print("End Spelling") | print("End Spelling") | ||||
process.terminate() | process.terminate() | ||||
self.infoText = self.infoText + 'finished freespelling\n' | |||||
self.controller.setInfos(self.infoText) | |||||
self.controller.addInfoText('finished freespelling\n') | |||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break | ||||
elif(y != -1 ): | elif(y != -1 ): | ||||
print("Error occured") | print("Error occured") | ||||
self.controller.changeScreen("StartPage") | self.controller.changeScreen("StartPage") | ||||
self.controller.setInfos(self.infoText + "Fehler beim Freespelling aufgetaucht\n") | |||||
self.controller.addInfoText("Fehler beim Freespelling aufgetaucht\n") | |||||
process.terminate() | process.terminate() | ||||
self.controller.stop() | self.controller.stop() | ||||
break | break | ||||
Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate() | Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate() | ||||
print("killed openvibe-designer") | |||||
print("killed openvibe-designer") |
try: | try: | ||||
from Tkinter import * | from Tkinter import * | ||||
import tkFileDialog as fd | |||||
except ImportError: | except ImportError: | ||||
from tkinter import * | from tkinter import * | ||||
from tkinter import filedialog as fd | |||||
#from tkinter import font | #from tkinter import font | ||||
from UIController import * | from UIController import * | ||||
def createTopFrame(self): | def createTopFrame(self): | ||||
self.topFrame = Frame(self, bg=self.layout["backgroundBar"], height=50, width=500) | self.topFrame = Frame(self, bg=self.layout["backgroundBar"], height=50, width=500) | ||||
self.changeBtn = Button(self.topFrame, text="Wechsel zu taktilen BCI", command=lambda: self.controller.actionPerformed("wechsel"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) | self.changeBtn = Button(self.topFrame, text="Wechsel zu taktilen BCI", command=lambda: self.controller.actionPerformed("wechsel"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) | ||||
self.saveBtn = Button(self.topFrame, text="Aenderung des Speicherorts", command=lambda: self.controller.actionPerformed("speicherort"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) | |||||
self.toplabel = Label(self.topFrame, text="visuelles Buchstabieren", font=self.layout["font"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"], ) | |||||
self.saveBtn = Button(self.topFrame, text="Auswaehlen der Datei", command=lambda: self.controller.actionPerformed("speicherort"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) | |||||
#self.setBtn = Button(self.topFrame, text="Auswaehlen der Datei", command=lambda: self.controller.actionPerformed("setFile"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) | |||||
self.toplabel = Label(self.topFrame, text="visuelles BCI", font=self.layout["font"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"], ) | |||||
self.topFrame.grid(column=0, row=0) | self.topFrame.grid(column=0, row=0) | ||||
self.topFrame.grid_propagate(0) | self.topFrame.grid_propagate(0) | ||||
self.changeBtn.grid(column=0, row=0, padx=10,pady=5) | self.changeBtn.grid(column=0, row=0, padx=10,pady=5) | ||||
self.saveBtn.grid(column=1, row=0, padx=10, pady=5) | self.saveBtn.grid(column=1, row=0, padx=10, pady=5) | ||||
#self.setBtn.grid(column=2, row=0, padx=10, pady=5) | |||||
self.toplabel.grid(column=2, row=0, padx=100, pady=2) | self.toplabel.grid(column=2, row=0, padx=100, pady=2) | ||||
def createMainFrame(self): | def createMainFrame(self): | ||||
def setChangeBtnText(self,text): | def setChangeBtnText(self,text): | ||||
self.changeBtn["text"] = text | self.changeBtn["text"] = text | ||||
def openfiledialog(self): | |||||
path = "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/datasets" | |||||
file = fd.askopenfilename(initialdir=path) | |||||
return file | |||||
def savefiledialog(self): | |||||
path = "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/datasets" | |||||
file = fd.asksaveasfilename(initialdir=path) | |||||
return file | |||||
class StartPage(Frame): | class StartPage(Frame): | ||||
def __init__(self, parent, controller, layout): | def __init__(self, parent, controller, layout): |