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.7KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.positionWindow()
  76. self.model.setFunktion(self.model.trainXDawn)
  77. self.model.start()
  78. #wird durch Btn gestartet -> startet copyspelling als thread
  79. def commandoCopySpelling(self):
  80. self.file = self.view.savefiledialog()
  81. if(self.modi == "taktilesBCI"):
  82. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  83. elif(self.modi == "visuellesBCI"):
  84. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  85. self.model.setFunktion(self.model.startCopySpelling)
  86. self.model.start()
  87. #wird durch Copy-Speller Thread copystelling gestartet -> startete filtern als thread
  88. def filterXdawn(self):
  89. if(self.modi == "taktilesBCI"):
  90. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  91. elif(self.modi == "visuellesBCI"):
  92. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  93. self.model.setFunktion(self.model.trainXDawn)
  94. self.model.start()
  95. #wird durch XDawn-Thread copystelling gestartet -> startete filtern als thread
  96. def filterClassic(self):
  97. if(self.modi == "taktilesBCI"):
  98. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  99. elif(self.modi == "visuellesBCI"):
  100. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  101. self.model.setFunktion(self.model.trainClassifier)
  102. self.model.start()
  103. def commandFreeSpelling(self):
  104. print("freespelling")
  105. if(self.modi == "taktilesBCI"):
  106. self.model = ModellTaktil(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  107. elif(self.modi == "visuellesBCI"):
  108. self.model = ModellVisuell(self, path_files= self.PATH_FILES, path_ov= self.PATH_OV)
  109. self.model.setFunktion(self.model.freeSpelling)
  110. self.model.start()
  111. def commandStop(self):
  112. if(self.model is not None):
  113. self.addInfoText("Action: STOP-Command")
  114. self.model.stop()
  115. self.model.join()
  116. self.model.killProzess()
  117. self.mode = None
  118. def stop(self, next=None):
  119. print("Stop aus Modell")
  120. self.model.stop()
  121. self.model.join()
  122. self.model.killProzess()
  123. self.mode = None
  124. if(next is not None):
  125. func = self.nexts.get(next)
  126. func()
  127. def addInfoText(self,text):
  128. self.infotext = self.infotext + text
  129. self.view.setInfoText(self.infotext)
  130. def resetInfo(self):
  131. self.infotext = ""
  132. def setTitle(self,text):
  133. self.view.setTitleText(text)
  134. def changeScreen(self, pageName):
  135. self.view.changeFrame(pageName=pageName)
  136. def getModi(self):
  137. return self.modi
  138. def getWindowSize(self):
  139. return self.view.getWindowSize()