addThreads

This commit is contained in:
Nicole Weber 2021-10-21 14:12:23 +02:00
parent 58f6c81562
commit 7f66b1cdbd
7 changed files with 90 additions and 55 deletions

View File

@ -7,7 +7,6 @@ from threading import Thread
class Controller(): class Controller():
def __init__(self): def __init__(self):
self.model = Modell(self)
self.view = viewTkinter.View(self) self.view = viewTkinter.View(self)
self.commands = { self.commands = {
@ -23,8 +22,6 @@ class Controller():
"freeSpelling": "WorkingPage", "freeSpelling": "WorkingPage",
"test": "WorkingPage" "test": "WorkingPage"
} }
self.view.mainloop() self.view.mainloop()
def actionPerformed(self, action): def actionPerformed(self, action):
@ -38,20 +35,44 @@ class Controller():
def test(self): def test(self):
self.thread = Thread(target=self.model.trainXDawn) self.model = Modell(self)
self.thread.start() self.model.setFunktion(self.model.trainXDawn)
#self.model.trainXDawn() self.model.start()
#wird durch Btn gestartet -> startet copyspelling als thread
def commandoCopySpelling(self): def commandoCopySpelling(self):
self.model.startCopySpelling() self.model = Modell(self)
self.model.trainXDawn() self.model.setFunktion(self.model.startCopySpelling)
self.model.rainClassifier() self.model.start()
#wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread
def filterXdawn(self):
#self.setTitle("start training Xdawn")
#self.setInfos("start training Xdawn")
self.model = 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)
self.model.setFunktion(self.model.trainClassifier)
self.model.start()
def commandFreeSpelling(self): def commandFreeSpelling(self):
self.model.freeSpelling() self.model.freeSpelling()
def commandStop(self): def commandStop(self):
self.model.stop()
self.model.join()
self.model.killProzess() self.model.killProzess()
self.thread.join() self.mode = None
def setInfos(self,text):
self.view.setInfoText(text)
def setTitle(self,text):
self.view.setTitleText(text)

Binary file not shown.

View File

@ -1,12 +1,33 @@
from subprocess import * from subprocess import *
import os from threading import Thread
import time
class Modell(): class Modell(Thread):
PATH_OV = 'meta/dist/designer-Release/openvibe-designer.sh' PATH_OV = 'meta/dist/designer-Release/openvibe-designer.sh'
PATH_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/' PATH_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/'
def __init__(self, c): def __init__(self,c):
Thread.__init__(self)
self.controller = c self.controller = c
self.aktiv= True
def stop(self):
print("stop")
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):
#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): def startCopySpelling(self):
@ -25,14 +46,18 @@ class Modell():
break break
self.killProzess() 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.controller.setInfos("This may take a while")
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)
while True: 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")
@ -41,7 +66,9 @@ class Modell():
process.terminate() process.terminate()
break break
self.controller.setInfos("finished Training with xDawn")
self.killProzess() self.killProzess()
#self.controller.filterClassic()
def trainClassifier(self): def trainClassifier(self):

Binary file not shown.

View File

@ -49,12 +49,15 @@ class View(Tk):
def createTopFrame(self): def createTopFrame(self):
self.topFrame = Frame(self, bg="blue", height=50, width=500) #, padx=460, pady=10) self.topFrame = Frame(self, bg="blue", height=50, width=500) #, padx=460, pady=10)
l = Label(self.topFrame, text="taktilles Buchstabieren") self.toplabel = Label(self.topFrame, text="taktilles Buchstabieren")
self.topFrame.columnconfigure(0, weight=1) # Set weight to row and
self.topFrame.rowconfigure(0, weight=1) # column where the widget is
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.topFrame.pack_propagate(0) self.topFrame.pack_propagate(0)
l.pack() self.toplabel.grid()
def createMainFrame(self): def createMainFrame(self):
@ -81,10 +84,14 @@ class View(Tk):
self.bottomFrame.grid(column=0, row=2) self.bottomFrame.grid(column=0, row=2)
self.bottomFrame.pack_propagate(0) self.bottomFrame.pack_propagate(0)
label = Label(self.bottomFrame, text="Hier stehen Infos") self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos")
label.pack() self.bottomlabel.pack()
def setInfoText(self, text):
self.bottomlabel['text'] = text
def setTitleText(self,text):
self.toplabel['text'] = text
class StartPage(Frame): class StartPage(Frame):
def __init__(self, parent, controller): def __init__(self, parent, controller):
Frame.__init__(self, parent, height=250, width=500, bg="red") Frame.__init__(self, parent, height=250, width=500, bg="red")

Binary file not shown.

View File

@ -1,42 +1,22 @@
from threading import Thread try:
import time from Tkinter import *
from itertools import count except ImportError:
from tkinter import *
class Modell(Thread): root = Tk()
def __init__(self): root.geometry('300x200')
Thread.__init__(self) root.columnconfigure(0, weight=1) # Set weight to row and
self.running = True root.rowconfigure(0, weight=1) # column where the widget is
def stop(self):
self.running = False
def setFunktion(self, func, args=None, kwargs=None): container = Frame(root, bg='tan') # bg color to show extent
self.func = func container.grid(row=0, column=0) # Grid cell with weight
self.args = args or []
self.kwargs = kwargs or {}
def run(self):
t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
t.setDaemon(True)
t.start()
while self.running:
time.sleep(0.1)
def worker(self): # A couple of widgets to illustrate the principle.
i= 0 b1 = Button(container, text='First', width=10)
while True: b1.grid()
i = i+1 b2 = Button(container, text='second', width=10)
print(i) b2.grid()
time.sleep(0.05)
root.mainloop()
c = Modell()
c.setFunktion(c.worker)
c.start()
t = time.time()
time.sleep(3)
c.stop()