You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIController.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. from UIModellVisuell import *
  2. from UIModellTaktil import *
  3. import UIViewTKinter as viewTkinter
  4. from shutil import copyfile
  5. class Controller():
  6. def __init__(self, pathOVFile, path_ov, path_files, path_default):
  7. self.view = viewTkinter.View(self, path_default)
  8. self.modi = "visuellesBCI"
  9. self.pathOVFile = pathOVFile
  10. self.PATH_OV = path_ov
  11. self.PATH_FILES = path_files
  12. self.infotext = ""
  13. self.commands = {
  14. "copySpelling": self.commandoCopySpelling,
  15. "stop": self.commandStop,
  16. "freeSpelling": self.commandFreeSpelling,
  17. "test": self.test,
  18. "wechsel": self.wechsel,
  19. "speicherort": self.setDataset
  20. }
  21. self.nexts = {
  22. "filterXdawn" : self.filterXdawn,
  23. "filterClassic": self.filterClassic,
  24. "save": self.speichern
  25. }
  26. self.pagesTaktil = {
  27. "stop": "StartPage",
  28. "copySpelling": "WorkingPageTaktil",
  29. "freeSpelling": "WorkingPageTaktil",
  30. "test": "WorkingPageTaktil"
  31. }
  32. self.pagesVisuell = {
  33. "stop": "StartPage",
  34. "copySpelling": "WorkingPageVisuell",
  35. "freeSpelling": "WorkingPageVisuell",
  36. "test": "WorkingPageVisuell"
  37. }
  38. self.model = None
  39. self.view.mainloop()
  40. def actionPerformed(self, action):
  41. self.changePage(action)
  42. func = self.commands.get(action)
  43. if(func is not None):
  44. func()
  45. else:
  46. print("Kommado existiert nicht")
  47. def changePage(self,action):
  48. if(self.modi == "taktilesBCI"):
  49. page = self.pagesTaktil.get(action)
  50. elif(self.modi == "visuellesBCI"):
  51. page = self.pagesVisuell.get(action)
  52. if(page is not None):
  53. self.view.changeFrame(page)
  54. def wechsel(self):
  55. if(self.modi == "taktilesBCI"):
  56. self.view.setChangeBtnText("Wechsel zu taktilen BCI")
  57. self.view.setTitleText("visuelles BCI")
  58. self.modi = "visuellesBCI"
  59. elif(self.modi == "visuellesBCI"):
  60. self.setTitle("taktiles BCI")
  61. self.view.setChangeBtnText("Wechsel zu visuellen BCI")
  62. self.modi = "taktilesBCI"
  63. def speichern(self):
  64. print("saveFile")
  65. copyfile(self.pathOVFile, self.file)
  66. def setDataset(self):
  67. file = self.view.openfiledialog()
  68. copyfile(file, self.pathOVFile)
  69. def test(self):
  70. self.file = self.view.savefiledialog()
  71. if(self.modi == "taktilesBCI"):
  72. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  73. elif(self.modi == "visuellesBCI"):
  74. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  75. self.model.setFunktion(self.model.trainXDawn)
  76. self.model.start()
  77. #wird durch Btn gestartet -> startet copyspelling als thread
  78. def commandoCopySpelling(self):
  79. self.file = self.view.savefiledialog()
  80. if(self.modi == "taktilesBCI"):
  81. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  82. elif(self.modi == "visuellesBCI"):
  83. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  84. self.model.setFunktion(self.model.startCopySpelling)
  85. self.model.start()
  86. #wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread
  87. def filterXdawn(self):
  88. if(self.modi == "taktilesBCI"):
  89. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  90. elif(self.modi == "visuellesBCI"):
  91. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  92. self.model.setFunktion(self.model.trainXDawn)
  93. self.model.start()
  94. #wird durch XDawn-Thread copystelling gestartet -> startete filtern als thread
  95. def filterClassic(self):
  96. if(self.modi == "taktilesBCI"):
  97. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  98. elif(self.modi == "visuellesBCI"):
  99. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  100. self.model.setFunktion(self.model.trainClassifier)
  101. self.model.start()
  102. def commandFreeSpelling(self):
  103. print("freespelling")
  104. if(self.modi == "taktilesBCI"):
  105. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  106. elif(self.modi == "visuellesBCI"):
  107. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  108. self.model.setFunktion(self.model.freeSpelling)
  109. self.model.start()
  110. def commandStop(self):
  111. if(self.model is not None):
  112. self.addInfoText("Action: STOP-Command")
  113. self.model.stop()
  114. self.model.join()
  115. self.model.killProzess()
  116. self.mode = None
  117. def stop(self, next=None):
  118. print("Stop aus Modell")
  119. self.model.stop()
  120. self.model.join()
  121. self.model.killProzess()
  122. self.mode = None
  123. if(next is not None):
  124. func = self.nexts.get(next)
  125. func()
  126. def addInfoText(self,text):
  127. self.infotext = self.infotext + text
  128. self.view.setInfoText(self.infotext)
  129. def resetInfo(self):
  130. self.infotext = ""
  131. def setTitle(self,text):
  132. self.view.setTitleText(text)
  133. def changeScreen(self, pageName):
  134. self.view.changeFrame(pageName=pageName)
  135. def getModi(self):
  136. return self.modi