Browse Source

addThreads

dev
Nicole Weber 2 years ago
parent
commit
7f66b1cdbd

+ 31
- 10
Masterarbeit/UIController.py View File

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 = {
"freeSpelling": "WorkingPage", "freeSpelling": "WorkingPage",
"test": "WorkingPage" "test": "WorkingPage"
} }


self.view.mainloop() self.view.mainloop()
def actionPerformed(self, action): def actionPerformed(self, action):




def test(self): 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): 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): 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)






BIN
Masterarbeit/UIController.pyc View File


+ 31
- 4
Masterarbeit/UIModell.py View File

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):
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")
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):

BIN
Masterarbeit/UIModell.pyc View File


+ 11
- 4
Masterarbeit/UIViewTKinter.py View File

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):


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")
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): 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")

BIN
Masterarbeit/UIViewTKinter.pyc View File


+ 16
- 36
Masterarbeit/test.py View File

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…
Cancel
Save