feherbehebung

This commit is contained in:
Nicole Weber 2021-10-22 13:04:33 +02:00
parent 7f66b1cdbd
commit 249fa25357
6 changed files with 158 additions and 42 deletions

View File

@ -16,6 +16,11 @@ class Controller():
"test": self.test "test": self.test
} }
self.nexts = {
"filterXdawn" : self.filterXdawn,
"filterClassic": self.filterClassic
}
self.pages = { self.pages = {
"stop": "StartPage", "stop": "StartPage",
"copySpelling": "WorkingPage", "copySpelling": "WorkingPage",
@ -47,8 +52,6 @@ class Controller():
#wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread #wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread
def filterXdawn(self): def filterXdawn(self):
#self.setTitle("start training Xdawn")
#self.setInfos("start training Xdawn")
self.model = Modell(self) self.model = Modell(self)
self.model.setFunktion(self.model.trainXDawn) self.model.setFunktion(self.model.trainXDawn)
self.model.start() self.model.start()
@ -60,19 +63,37 @@ class Controller():
self.model.start() self.model.start()
def commandFreeSpelling(self): def commandFreeSpelling(self):
self.model.freeSpelling() print("freespelling")
self.model = Modell(self)
self.model.setFunktion(self.model.freeSpelling)
self.model.start()
def commandStop(self): def commandStop(self):
self.setInfos("Action: STOP-Command")
self.model.stop() self.model.stop()
self.model.join() self.model.join()
self.model.killProzess() self.model.killProzess()
self.mode = None self.mode = None
def stop(self, next=None):
print("Stop aus Modell")
self.model.stop()
self.model.join()
self.model.killProzess()
self.mode = None
if(next is not None):
func = self.nexts.get(next)
func()
def setInfos(self,text): def setInfos(self,text):
self.view.setInfoText(text) self.view.setInfoText(text)
def setTitle(self,text): def setTitle(self,text):
self.view.setTitleText(text) self.view.setTitleText(text)
def changeScreen(self, pageName):
self.view.changeFrame(pageName=pageName)

Binary file not shown.

View File

@ -10,9 +10,11 @@ class Modell(Thread):
Thread.__init__(self) Thread.__init__(self)
self.controller = c self.controller = c
self.aktiv= True self.aktiv= True
self.openVibeAktiv = False
self.infoText = ''
def stop(self): def stop(self):
print("stop") print("stop thread")
self.aktiv = False self.aktiv = False
def setFunktion(self, func, args=None, kwargs=None): def setFunktion(self, func, args=None, kwargs=None):
@ -21,6 +23,7 @@ class Modell(Thread):
self.kwargs = kwargs or {} self.kwargs = kwargs or {}
def run(self): def run(self):
print("start thread")
#self.aktiv = True #self.aktiv = True
t = Thread(target=self.func, args=self.args, kwargs=self.kwargs) t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
t.setDaemon(True) t.setDaemon(True)
@ -32,98 +35,157 @@ class Modell(Thread):
def startCopySpelling(self): def startCopySpelling(self):
print("start copySpelling") 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' 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
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("schlagwort?")
y = output.find("Error")
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.stop("filterXdawn")
break break
elif(y != -1 ):
self.killProzess() print("Error occured")
self.controller.filterXdawn() 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): def trainXDawn(self):
print("start training Xdawn") print("start training Xdawn")
self.controller.setTitle("start training with Xdawn") self.infoText = self.infoText + 'start training XDawn -- '
self.controller.setInfos("This may take a while") self.controller.setInfos(self.infoText)
print("test")
path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml' path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.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
while self.aktiv: while self.aktiv:
output = process.stdout.readline() output = process.stdout.readline()
print(output.strip()) print(output.strip())
x = output.find("Training finished and saved") x = output.find("Training finished and saved")
y = output.find("Error")
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.stop("filterClassic")
break 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.setInfos("finished Training with xDawn")
self.killProzess()
#self.controller.filterClassic() #self.controller.filterClassic()
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)
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
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("schlagwort?")
y = output.find("Error")
if(x != -1): if(x != -1):
print("Training finished") 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() process.terminate()
break break
self.killProzess() self.controller.changeScreen("StartPage")
self.controller.stop()
def freeSpelling(self): def freeSpelling(self):
#bei error auch abrechen?
print("start freeSpelling") print("start freeSpelling")
self.infoText = 'start free spelling -- '
self.controller.setInfos(self.infoText)
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,
universal_newlines=True) universal_newlines=True)
self.openVibeAktiv = True
while True: while True:
output = process.stdout.readline() output = process.stdout.readline()
print(output.strip()) print(output.strip())
x = output.find("schlagwort?") y = output.find("Error")
x = output.find("Schlagwort")
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.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 break
self.killProzess() self.controller.changeScreen("StartPage")
self.controller.stop()
def killProzess(self): def killProzess(self):
print('start killing') if(self.openVibeAktiv):
pidOV = 0 self.openVibeAktiv = False
pidP = 0 print('start killing')
items = [] pidOV = 0
items = []
prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip() prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
zeilen = prozesse.split('\n') zeilen = prozesse.split('\n')
for z in zeilen: for z in zeilen:
if(z.find("openvibe-design") != -1): if(z.find("openvibe-design") != -1):
z = z.strip() z = z.strip()
items = z.split(' ') items = z.split(' ')
pidOV = items[0] pidOV = items[0]
#kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen) #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
Popen(["kill", "-TERM", pidOV], stdout=PIPE).communicate() Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate()
print("killed openvibe-designer") print("killed openvibe-designer")

Binary file not shown.

View File

@ -40,6 +40,7 @@ class View(Tk):
self.container.configure(height=(self.h*self.faktor[1]), width=self.w) self.container.configure(height=(self.h*self.faktor[1]), width=self.w)
for f in self.frames: for f in self.frames:
self.frames[f].configure(height=(self.h*self.faktor[1]), width=self.w) self.frames[f].configure(height=(self.h*self.faktor[1]), width=self.w)
self.frames[f].adjustSize(height=(self.h*self.faktor[1]), width=self.w/2)
def onClosing(self): def onClosing(self):
@ -81,11 +82,16 @@ class View(Tk):
def createBottomFrame(self): def createBottomFrame(self):
self.bottomFrame = Frame(self, bg="green", height=100, width=500) self.bottomFrame = Frame(self, bg="green", height=100, width=500)
self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos\nGanz viele", justify='left')
#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.grid(column=0, row=2)
self.bottomFrame.pack_propagate(0) self.bottomFrame.pack_propagate(0)
self.bottomFrame.grid_propagate(0)
self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos") self.bottomlabel.grid(padx=5,pady=5)
self.bottomlabel.pack()
def setInfoText(self, text): def setInfoText(self, text):
self.bottomlabel['text'] = text self.bottomlabel['text'] = text
@ -99,15 +105,42 @@ class StartPage(Frame):
self.pack_propagate(0) self.pack_propagate(0)
self.controller = controller self.controller = controller
testBtn = Button(self, text="test", command=lambda: self.controller.actionPerformed("test"), height=6, width = 10) self.leftFrame = Frame(self, bg="cyan", height=250, width=250)
testBtn.grid(row=0, column=0) self.rightFrame = Frame(self, bg="blue", height=250, width=250)
freeSpellingBtn = Button(self, text="freeSpelling", command=lambda: self.controller.actionPerformed("freeSpelling"), height=6, width = 10) self.leftFrame.columnconfigure(0, weight=1) # Set weight to row and
freeSpellingBtn.grid(row=0, column=1) self.leftFrame.rowconfigure(0, weight=1) # column where the widget is
self.leftFrame.grid_propagate(0)
self.leftFrame.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.leftFrame.grid(column=0, row=0)
self.rightFrame.grid(column=1, row=0)
testBtn = Button(self.leftFrame, text="test", command=lambda: self.controller.actionPerformed("test"), height=6, width = 10)
testBtn.grid()
freeSpellingBtn = Button(self.rightFrame, text="freeSpelling", command=lambda: self.controller.actionPerformed("freeSpelling"), height=6, width = 10)
freeSpellingBtn.grid()
def adjustSize(self, height, width):
self.leftFrame.configure(height=height, width= width)
self.rightFrame.configure(height=height, width= width)
class WorkingPage(Frame): class WorkingPage(Frame):
def __init__(self, parent, controller): def __init__(self, parent, controller):
Frame.__init__(self, parent) Frame.__init__(self, parent)
self.controller = controller self.controller = controller
self.columnconfigure(0, weight=1) # Set weight to row and
self.rowconfigure(0, weight=1) # column where the widget is
stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=6, width = 10) stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=6, width = 10)
stopBtn.pack() stopBtn.grid()
def adjustSize(self, height, width):
pass

Binary file not shown.