addThreads
This commit is contained in:
parent
58f6c81562
commit
7f66b1cdbd
@ -7,7 +7,6 @@ from threading import Thread
|
||||
class Controller():
|
||||
|
||||
def __init__(self):
|
||||
self.model = Modell(self)
|
||||
self.view = viewTkinter.View(self)
|
||||
|
||||
self.commands = {
|
||||
@ -23,8 +22,6 @@ class Controller():
|
||||
"freeSpelling": "WorkingPage",
|
||||
"test": "WorkingPage"
|
||||
}
|
||||
|
||||
|
||||
self.view.mainloop()
|
||||
|
||||
def actionPerformed(self, action):
|
||||
@ -38,20 +35,44 @@ class Controller():
|
||||
|
||||
|
||||
def test(self):
|
||||
self.thread = Thread(target=self.model.trainXDawn)
|
||||
self.thread.start()
|
||||
#self.model.trainXDawn()
|
||||
self.model = Modell(self)
|
||||
self.model.setFunktion(self.model.trainXDawn)
|
||||
self.model.start()
|
||||
|
||||
#wird durch Btn gestartet -> startet copyspelling als thread
|
||||
def commandoCopySpelling(self):
|
||||
self.model.startCopySpelling()
|
||||
self.model.trainXDawn()
|
||||
self.model.rainClassifier()
|
||||
self.model = 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.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):
|
||||
self.model.freeSpelling()
|
||||
|
||||
def commandStop(self):
|
||||
self.model.stop()
|
||||
self.model.join()
|
||||
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.
@ -1,12 +1,33 @@
|
||||
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_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/'
|
||||
|
||||
def __init__(self, c):
|
||||
def __init__(self,c):
|
||||
Thread.__init__(self)
|
||||
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):
|
||||
@ -25,14 +46,18 @@ class Modell():
|
||||
break
|
||||
|
||||
self.killProzess()
|
||||
self.controller.filterXdawn()
|
||||
|
||||
def trainXDawn(self):
|
||||
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'
|
||||
process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
|
||||
stdout=PIPE,
|
||||
universal_newlines=True)
|
||||
while True:
|
||||
while self.aktiv:
|
||||
output = process.stdout.readline()
|
||||
print(output.strip())
|
||||
x = output.find("Training finished and saved")
|
||||
@ -41,7 +66,9 @@ class Modell():
|
||||
process.terminate()
|
||||
break
|
||||
|
||||
self.controller.setInfos("finished Training with xDawn")
|
||||
self.killProzess()
|
||||
#self.controller.filterClassic()
|
||||
|
||||
|
||||
def trainClassifier(self):
|
||||
|
Binary file not shown.
@ -49,12 +49,15 @@ class View(Tk):
|
||||
|
||||
def createTopFrame(self):
|
||||
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_propagate(0)
|
||||
self.topFrame.pack_propagate(0)
|
||||
l.pack()
|
||||
self.toplabel.grid()
|
||||
|
||||
def createMainFrame(self):
|
||||
|
||||
@ -81,10 +84,14 @@ class View(Tk):
|
||||
self.bottomFrame.grid(column=0, row=2)
|
||||
self.bottomFrame.pack_propagate(0)
|
||||
|
||||
label = Label(self.bottomFrame, text="Hier stehen Infos")
|
||||
label.pack()
|
||||
self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos")
|
||||
self.bottomlabel.pack()
|
||||
|
||||
def setInfoText(self, text):
|
||||
self.bottomlabel['text'] = text
|
||||
|
||||
def setTitleText(self,text):
|
||||
self.toplabel['text'] = text
|
||||
class StartPage(Frame):
|
||||
def __init__(self, parent, controller):
|
||||
Frame.__init__(self, parent, height=250, width=500, bg="red")
|
||||
|
Binary file not shown.
@ -1,42 +1,22 @@
|
||||
from threading import Thread
|
||||
import time
|
||||
from itertools import count
|
||||
try:
|
||||
from Tkinter import *
|
||||
except ImportError:
|
||||
from tkinter import *
|
||||
|
||||
class Modell(Thread):
|
||||
def __init__(self):
|
||||
Thread.__init__(self)
|
||||
self.running = True
|
||||
|
||||
def stop(self):
|
||||
self.running = False
|
||||
root = Tk()
|
||||
root.geometry('300x200')
|
||||
root.columnconfigure(0, weight=1) # Set weight to row and
|
||||
root.rowconfigure(0, weight=1) # column where the widget is
|
||||
|
||||
def setFunktion(self, func, args=None, kwargs=None):
|
||||
self.func = func
|
||||
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)
|
||||
|
||||
container = Frame(root, bg='tan') # bg color to show extent
|
||||
container.grid(row=0, column=0) # Grid cell with weight
|
||||
|
||||
def worker(self):
|
||||
i= 0
|
||||
while True:
|
||||
i = i+1
|
||||
print(i)
|
||||
time.sleep(0.05)
|
||||
|
||||
c = Modell()
|
||||
c.setFunktion(c.worker)
|
||||
c.start()
|
||||
# A couple of widgets to illustrate the principle.
|
||||
b1 = Button(container, text='First', width=10)
|
||||
b1.grid()
|
||||
b2 = Button(container, text='second', width=10)
|
||||
b2.grid()
|
||||
|
||||
root.mainloop()
|
||||
|
||||
|
||||
t = time.time()
|
||||
time.sleep(3)
|
||||
|
||||
c.stop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user