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.

UIModellVisuell.py 7.3KB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. from subprocess import *
  2. from threading import Thread
  3. import time
  4. from UIModell import Modell
  5. class ModellVisuell(Modell):
  6. def __init__(self,c, path_ov, path_files):
  7. Thread.__init__(self)
  8. Modell.__init__(self, c)
  9. self.PATH_FILES = path_files
  10. self.PATH_OV = path_ov
  11. self.aktiv= True
  12. self.openVibeAktiv = False
  13. def stop(self):
  14. print("stop thread")
  15. self.aktiv = False
  16. def setFunktion(self, func, args=None, kwargs=None):
  17. self.func = func
  18. self.args = args or []
  19. self.kwargs = kwargs or {}
  20. def run(self):
  21. print("start thread")
  22. #self.aktiv = True
  23. t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
  24. t.setDaemon(True)
  25. t.start()
  26. while self.aktiv:
  27. time.sleep(0.1)
  28. def startCopySpelling(self):
  29. print("start copySpelling")
  30. self.controller.resetInfo()
  31. self.controller.addInfoText('start copyspelling -- ')
  32. self.controller.setTitle("Copy Spelling")
  33. path = self.PATH_FILES + 'p300-visual-1-acquisition.xml'
  34. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  35. stdout=PIPE,
  36. universal_newlines=True)
  37. self.openVibeAktiv = True
  38. while True:
  39. output = process.stdout.readline()
  40. print(output.strip())
  41. x = output.find("schlagwort?")
  42. y = output.find("Error")
  43. if(x != -1):
  44. print("Training finished")
  45. process.terminate()
  46. self.controller.addInfoText('finished Copyspelling\n')
  47. self.controller.stop("filterXdawn")
  48. break
  49. elif(y != -1 ):
  50. print("Error occured")
  51. self.controller.changeScreen("StartPage")
  52. self.controller.addInfoText("Fehler beim Copyspelling aufgetaucht\n")
  53. process.terminate()
  54. self.controller.stop()
  55. break
  56. self.controller.stop()
  57. #self.killProzess()
  58. #self.controller.filterXdawn()
  59. def trainXDawn(self):
  60. print("start training Xdawn")
  61. self.controller.addInfoText('start training XDawn -- ')
  62. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  63. #path = 'Projekte/test.xml'
  64. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  65. stdout=PIPE,
  66. universal_newlines=True)
  67. self.openVibeAktiv = True
  68. self.positionWindow()
  69. while self.aktiv:
  70. output = process.stdout.readline()
  71. print(output.strip())
  72. x = output.find("Training finished and saved")
  73. y = output.find("Error")
  74. if(x != -1):
  75. print("Training finished")
  76. process.terminate()
  77. self.controller.addInfoText('finished Training\n')
  78. self.controller.stop("filterClassic")
  79. break
  80. elif(y != -1 ):
  81. print("Error occured")
  82. self.controller.changeScreen("StartPage")
  83. self.controller.addInfoText("Fehler beim XDawn Training aufgetaucht\n")
  84. self.controller.stop()
  85. process.terminate()
  86. break
  87. self.controller.stop()
  88. #self.controller.filterClassic()
  89. def trainClassifier(self):
  90. print("start training Classifier")
  91. self.controller.addInfoText("start training with Classifier -- ")
  92. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  93. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  94. stdout=PIPE,
  95. universal_newlines=True)
  96. self.openVibeAktiv = True
  97. counter = 0
  98. while True:
  99. output = process.stdout.readline()
  100. print(output.strip())
  101. x = output.find("aka Classifier trainer")
  102. accuracy = output.find("Training set accuracy is")
  103. y = output.find("Error")
  104. if(x != -1):
  105. counter = counter +1
  106. #counter = 18
  107. if(counter >= 17):
  108. print("Training finished")
  109. self.controller.addInfoText('finished Training\n')
  110. process.terminate()
  111. self.controller.stop("save")
  112. break
  113. elif(y != -1 ):
  114. print("Error occured")
  115. self.controller.changeScreen("StartPage")
  116. self.controller.addInfoText("Fehler beim Classifier Training aufgetaucht\n")
  117. process.terminate()
  118. break
  119. elif(accuracy != -1):
  120. print("ACCURACY" + output)
  121. self.controller.changeScreen("StartPage")
  122. self.controller.stop()
  123. def freeSpelling(self):
  124. #bei error auch abrechen?
  125. print("start freeSpelling")
  126. self.controller.resetInfo()
  127. self.controller.addInfoText('start free spelling -- ')
  128. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  129. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  130. stdout=PIPE,
  131. universal_newlines=True)
  132. self.openVibeAktiv = True
  133. while True:
  134. output = process.stdout.readline()
  135. print(output.strip())
  136. y = output.find("Error")
  137. x = output.find("Schlagwort")
  138. if(x != -1):
  139. print("End Spelling")
  140. process.terminate()
  141. self.controller.addInfoText('finished freespelling\n')
  142. self.controller.changeScreen("StartPage")
  143. self.controller.stop()
  144. break
  145. elif(y != -1 ):
  146. print("Error occured")
  147. self.controller.changeScreen("StartPage")
  148. self.controller.addInfoText("Fehler beim Freespelling aufgetaucht\n")
  149. process.terminate()
  150. self.controller.stop()
  151. break
  152. self.controller.changeScreen("StartPage")
  153. self.controller.stop()
  154. def killProzess(self):
  155. if(self.openVibeAktiv):
  156. self.openVibeAktiv = False
  157. self.killProzessParent()
  158. def positionWindow(self):
  159. print("calles positionWindow")
  160. name = "firefox"
  161. parameter = self.controller.getWindowSize()
  162. positionX = int(parameter[0]+ int(parameter[3] * 0.05))
  163. positionY = int(parameter[1]) + int(parameter[2]*0.08)
  164. height = int(parameter[2])*0.55
  165. width = int(parameter[3])*0.9
  166. windowID = Popen(["xdotool", "search", "--onlyvisible", "--name", name], stdout=PIPE).communicate()[0].strip()
  167. Popen(["xdotool", "windowsize", windowID, str(width), str(height)], stdout=PIPE).communicate()
  168. Popen(["xdotool", "windowmove", windowID, str(positionX), str(positionY)], stdout=PIPE).communicate()
  169. Popen(["xdotool", "windowactivate", windowID], stdout=PIPE).communicate()[0].strip()
  170. #windowminimize ums ein fenster klein zu machen