from UIModellVisuell import * from UIModellTaktil import * import UIViewTKinter as viewTkinter from shutil import copyfile class Controller(): def __init__(self, pathOVFile, path_ov, path_files, path_default): self.view = viewTkinter.View(self, path_default) self.modi = "visuellesBCI" self.pathOVFile = pathOVFile self.PATH_OV = path_ov self.PATH_FILES = path_files self.infotext = "" self.commands = { "copySpelling": self.commandoCopySpelling, "stop": self.commandStop, "freeSpelling": self.commandFreeSpelling, "test": self.test, "wechsel": self.wechsel, "speicherort": self.setDataset } self.nexts = { "filterXdawn" : self.filterXdawn, "filterClassic": self.filterClassic, "save": self.speichern } self.pagesTaktil = { "stop": "StartPage", "copySpelling": "WorkingPageTaktil", "freeSpelling": "WorkingPageTaktil", "test": "WorkingPageTaktil" } self.pagesVisuell = { "stop": "StartPage", "copySpelling": "WorkingPageVisuell", "freeSpelling": "WorkingPageVisuell", "test": "WorkingPageVisuell" } self.model = None self.view.mainloop() def actionPerformed(self, action): self.changePage(action) func = self.commands.get(action) if(func is not None): func() else: print("Kommado existiert nicht") def changePage(self,action): if(self.modi == "taktilesBCI"): page = self.pagesTaktil.get(action) elif(self.modi == "visuellesBCI"): page = self.pagesVisuell.get(action) if(page is not None): self.view.changeFrame(page) def wechsel(self): if(self.modi == "taktilesBCI"): self.view.setChangeBtnText("Wechsel zu taktilen BCI") self.view.setTitleText("visuelles BCI") self.modi = "visuellesBCI" elif(self.modi == "visuellesBCI"): self.setTitle("taktiles BCI") self.view.setChangeBtnText("Wechsel zu visuellen BCI") self.modi = "taktilesBCI" def speichern(self): print("saveFile") copyfile(self.pathOVFile, self.file) def setDataset(self): file = self.view.openfiledialog() copyfile(file, self.pathOVFile) def test(self): self.file = self.view.savefiledialog() if(self.modi == "taktilesBCI"): self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) elif(self.modi == "visuellesBCI"): self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) self.model.positionWindow() self.model.setFunktion(self.model.trainXDawn) self.model.start() #wird durch Btn gestartet -> startet copyspelling als thread def commandoCopySpelling(self): self.file = self.view.savefiledialog() if(self.modi == "taktilesBCI"): self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) elif(self.modi == "visuellesBCI"): self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) self.model.setFunktion(self.model.startCopySpelling) self.model.start() #wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread def filterXdawn(self): if(self.modi == "taktilesBCI"): self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) elif(self.modi == "visuellesBCI"): self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) self.model.setFunktion(self.model.trainXDawn) self.model.start() #wird durch XDawn-Thread copystelling gestartet -> startete filtern als thread def filterClassic(self): if(self.modi == "taktilesBCI"): self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) elif(self.modi == "visuellesBCI"): self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) self.model.setFunktion(self.model.trainClassifier) self.model.start() def commandFreeSpelling(self): print("freespelling") if(self.modi == "taktilesBCI"): self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) elif(self.modi == "visuellesBCI"): self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV) self.model.setFunktion(self.model.freeSpelling) self.model.start() def commandStop(self): if(self.model is not None): self.addInfoText("Action: STOP-Command") self.model.stop() self.model.join() self.model.killProzess() 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 addInfoText(self,text): self.infotext = self.infotext + text self.view.setInfoText(self.infotext) def resetInfo(self): self.infotext = "" def setTitle(self,text): self.view.setTitleText(text) def changeScreen(self, pageName): self.view.changeFrame(pageName=pageName) def getModi(self): return self.modi def getWindowSize(self): return self.view.getWindowSize()