diff --git a/Masterarbeit/UIController.py b/Masterarbeit/UIController.py index 1bd8d4e..1ced5ac 100644 --- a/Masterarbeit/UIController.py +++ b/Masterarbeit/UIController.py @@ -1,14 +1,14 @@ -from UIModell import * +import UIModellVisuell as modelVisuell +import UIModellTaktil as modelsTaktil import UIViewTKinter as viewTkinter -import UIViewPySide as viewPySide -from threading import Thread + class Controller(): def __init__(self): self.view = viewTkinter.View(self) - self.modi = "taktilesBCI" + self.modi = "visuellesBCI" self.commands = { "copySpelling": self.commandoCopySpelling, @@ -52,7 +52,7 @@ class Controller(): elif(self.modi == "visuellesBCI"): page = self.pagesVisuell.get(action) if(page is not None): - self.view.changeFrame(self.pages.get(action)) + self.view.changeFrame(page) def wechsel(self): if(self.modi == "taktilesBCI"): @@ -69,31 +69,46 @@ class Controller(): def test(self): - self.model = Modell(self) + if(self.modi == "taktilesBCI"): + self.model = modelsTaktil.Modell(self) + elif(self.modi == "visuellesBCI"): + self.model = modelVisuell.Modell(self) self.model.setFunktion(self.model.trainXDawn) self.model.start() #wird durch Btn gestartet -> startet copyspelling als thread def commandoCopySpelling(self): - self.model = Modell(self) + if(self.modi == "taktilesBCI"): + self.model = modelsTaktil.Modell(self) + elif(self.modi == "visuellesBCI"): + self.model = modelVisuell.Modell(self) self.model.setFunktion(self.model.startCopySpelling) self.model.start() #wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread def filterXdawn(self): - self.model = Modell(self) + if(self.modi == "taktilesBCI"): + self.model = modelsTaktil.Modell(self) + elif(self.modi == "visuellesBCI"): + self.model = modelVisuell.Modell(self) self.model.setFunktion(self.model.trainXDawn) self.model.start() #wird durch XDawn-Thread copystelling gestartet -> startete filtern als thread def filterClassic(self): - self.model = Modell(self) + if(self.modi == "taktilesBCI"): + self.model = modelsTaktil.Modell(self) + elif(self.modi == "visuellesBCI"): + self.model = modelVisuell.Modell(self) self.model.setFunktion(self.model.trainClassifier) self.model.start() def commandFreeSpelling(self): print("freespelling") - self.model = Modell(self) + if(self.modi == "taktilesBCI"): + self.model = modelsTaktil.Modell(self) + elif(self.modi == "visuellesBCI"): + self.model = modelVisuell.Modell(self) self.model.setFunktion(self.model.freeSpelling) self.model.start() diff --git a/Masterarbeit/UIModell.py b/Masterarbeit/UIModellTaktil.py similarity index 100% rename from Masterarbeit/UIModell.py rename to Masterarbeit/UIModellTaktil.py diff --git a/Masterarbeit/UIModellVisuell.py b/Masterarbeit/UIModellVisuell.py new file mode 100644 index 0000000..83847b6 --- /dev/null +++ b/Masterarbeit/UIModellVisuell.py @@ -0,0 +1,191 @@ +from subprocess import * +from threading import Thread +import time + +class Modell(Thread): + PATH_OV = 'meta/dist/designer-Release/openvibe-designer.sh' + PATH_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/' + + def __init__(self,c): + Thread.__init__(self) + self.controller = c + self.aktiv= True + self.openVibeAktiv = False + self.infoText = '' + + 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.infoText = 'start copyspelling -- ' + self.controller.setInfos(self.infoText) + 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.infoText = self.infoText + 'finished Copyspelling\n' + self.controller.setInfos(self.infoText) + self.controller.stop("filterXdawn") + break + elif(y != -1 ): + print("Error occured") + self.controller.changeScreen("StartPage") + self.controller.setInfos(self.infoText + "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.infoText = self.infoText + 'start training XDawn -- ' + self.controller.setInfos(self.infoText) + path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.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.infoText = self.infoText + 'finished Training\n' + self.controller.setInfos(self.infoText) + self.controller.stop("filterClassic") + break + elif(y != -1 ): + print("Error occured") + self.controller.changeScreen("StartPage") + self.controller.setInfos(self.infoText + "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.infoText = self.infoText + "start training with Classifier -- " + self.controller.setInfos(self.infoText) + + 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 + while True: + output = process.stdout.readline() + print(output.strip()) + x = output.find("schlagwort?") + y = output.find("Error") + if(x != -1): + print("Training finished") + self.infoText = self.infoText + 'finished Training\n' + self.controller.setInfos(self.infoText) + process.terminate() + break + elif(y != -1 ): + print("Error occured") + self.controller.changeScreen("StartPage") + self.controller.setInfos(self.infoText + "Fehler beim Classifier Training aufgetaucht\n") + process.terminate() + break + + self.controller.changeScreen("StartPage") + self.controller.stop() + + def freeSpelling(self): + #bei error auch abrechen? + print("start freeSpelling") + self.infoText = 'start free spelling -- ' + self.controller.setInfos(self.infoText) + 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.infoText = self.infoText + 'finished freespelling\n' + self.controller.setInfos(self.infoText) + self.controller.changeScreen("StartPage") + self.controller.stop() + break + elif(y != -1 ): + print("Error occured") + self.controller.changeScreen("StartPage") + self.controller.setInfos(self.infoText + "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") + + + diff --git a/Masterarbeit/UIViewPySide.py b/Masterarbeit/UIViewPySide.py deleted file mode 100644 index 842b740..0000000 --- a/Masterarbeit/UIViewPySide.py +++ /dev/null @@ -1,7 +0,0 @@ -#from PySide import * - - -class View(): - def __init__(self): - pass - diff --git a/Masterarbeit/UIViewPySide.pyc b/Masterarbeit/UIViewPySide.pyc deleted file mode 100644 index 902e4e3..0000000 Binary files a/Masterarbeit/UIViewPySide.pyc and /dev/null differ diff --git a/Masterarbeit/UIViewTKinter.py b/Masterarbeit/UIViewTKinter.py index 1f35d77..bf30133 100644 --- a/Masterarbeit/UIViewTKinter.py +++ b/Masterarbeit/UIViewTKinter.py @@ -12,7 +12,7 @@ class View(Tk): def __init__(self, c, *args, **kwargs): Tk.__init__(self, *args, **kwargs) self.controller = c - self.title("Taktiles Spelling") + self.title("Visuelles Spelling") self.h = 800 self.w = 1000 self.geometry('{}x{}'.format(self.w,self.h)) @@ -58,20 +58,18 @@ class View(Tk): def createTopFrame(self): - self.topFrame = Frame(self, bg=self.layout["backgroundBar"], height=50, width=500) #, padx=460, pady=10) - #self.toplabel = Label(self.topFrame, text="taktilles Buchstabieren") - self.changeBtn = Button(self.topFrame, text="Wechsel zu visuellen BCI", command=lambda: self.controller.actionPerformed("wechsel"), height=3, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) + 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=3, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) self.saveBtn = Button(self.topFrame, text="Ă„nderung des Speicherorts", command=lambda: self.controller.actionPerformed("speicherort"), height=3, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) - - #self.topFrame.columnconfigure(0, weight=1) # Set weight to row and - #self.topFrame.rowconfigure(0, weight=1) # column where the widget is + self.toplabel = Label(self.topFrame, text="visuelles Buchstabieren", font=self.layout["font"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"]) self.topFrame.grid(column=0, row=0) self.topFrame.grid_propagate(0) self.topFrame.pack_propagate(0) - #self.toplabel.grid() + self.changeBtn.grid(column=0, row=0, padx=10,pady=5) self.saveBtn.grid(column=1, row=0, padx=10, pady=5) + self.toplabel.grid(column=2, row=0, padx=100, pady=2) def createMainFrame(self): @@ -97,9 +95,6 @@ class View(Tk): self.bottomFrame = Frame(self, bg=self.layout["backgroundBar"], height=100, width=500) self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos\nGanz viele", justify='left', font=self.layout["font"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"]) - #self.bottomFrame.columnconfigure(0, weight=1) # Set weight to row and - #self.bottomFrame.rowconfigure(0, weight=1) # column where the widget is - self.bottomFrame.grid(column=0, row=2) self.bottomFrame.pack_propagate(0) self.bottomFrame.grid_propagate(0) @@ -111,6 +106,7 @@ class View(Tk): def setTitleText(self,text): self.title(text) + self.toplabel["text"] = text def setChangeBtnText(self,text): self.changeBtn["text"] = text @@ -127,23 +123,14 @@ class StartPage(Frame): self.container = Frame(self, bg=self.layout["background"], height=250, width=500) self.btnFrame = Frame(self.container, bg=self.layout["background"], height=250, width=250) - #self.rightFrame = Frame(self, bg=self.layout["background"], height=250, width=250) self.container.columnconfigure(0, weight=1) # Set weight to row and self.container.rowconfigure(0, weight=1) # column where the widget is self.container.grid_propagate(0) self.container.pack_propagate(0) - - - #self.rightFrame.columnconfigure(0, weight=1) # Set weight to row and - #self.rightFrame.rowconfigure(0, weight=1) # column where the widget is - #self.rightFrame.grid_propagate(0) - #self.rightFrame.pack_propagate(0) - self.container.pack() self.btnFrame.grid() - #self.rightFrame.grid(column=1, row=0) testBtn = Button(self.btnFrame, text="copySpelling", command=lambda: self.controller.actionPerformed("test"), height=6, width = 20, font=self.layout["font"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"]) testBtn.grid(row=0,column=0, padx=25,pady=25) diff --git a/Masterarbeit/__pycache__/UIController.cpython-39.pyc b/Masterarbeit/__pycache__/UIController.cpython-39.pyc index 3e02522..9986c40 100644 Binary files a/Masterarbeit/__pycache__/UIController.cpython-39.pyc and b/Masterarbeit/__pycache__/UIController.cpython-39.pyc differ diff --git a/Masterarbeit/__pycache__/UIModellTaktil.cpython-39.pyc b/Masterarbeit/__pycache__/UIModellTaktil.cpython-39.pyc new file mode 100644 index 0000000..fb02369 Binary files /dev/null and b/Masterarbeit/__pycache__/UIModellTaktil.cpython-39.pyc differ diff --git a/Masterarbeit/__pycache__/UIModellVisuell.cpython-39.pyc b/Masterarbeit/__pycache__/UIModellVisuell.cpython-39.pyc new file mode 100644 index 0000000..a889cb5 Binary files /dev/null and b/Masterarbeit/__pycache__/UIModellVisuell.cpython-39.pyc differ diff --git a/Masterarbeit/__pycache__/UIViewTKinter.cpython-39.pyc b/Masterarbeit/__pycache__/UIViewTKinter.cpython-39.pyc index 072b6cc..5d2e5e4 100644 Binary files a/Masterarbeit/__pycache__/UIViewTKinter.cpython-39.pyc and b/Masterarbeit/__pycache__/UIViewTKinter.cpython-39.pyc differ