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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. from subprocess import *
  2. from threading import Thread
  3. import time
  4. class Modell(Thread):
  5. PATH_OV = 'meta/dist/designer-Release/openvibe-designer.sh'
  6. PATH_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/'
  7. def __init__(self,c):
  8. Thread.__init__(self)
  9. self.controller = c
  10. self.aktiv= True
  11. self.openVibeAktiv = False
  12. self.infoText = ''
  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.infoText = 'start copyspelling -- '
  31. self.controller.setInfos(self.infoText)
  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.infoText = self.infoText + 'finished Copyspelling\n'
  47. self.controller.setInfos(self.infoText)
  48. self.controller.stop("filterXdawn")
  49. break
  50. elif(y != -1 ):
  51. print("Error occured")
  52. self.controller.changeScreen("StartPage")
  53. self.controller.setInfos(self.infoText + "Fehler beim Copyspelling aufgetaucht\n")
  54. process.terminate()
  55. self.controller.stop()
  56. break
  57. self.controller.stop()
  58. #self.killProzess()
  59. #self.controller.filterXdawn()
  60. def trainXDawn(self):
  61. print("start training Xdawn")
  62. self.infoText = self.infoText + 'start training XDawn -- '
  63. self.controller.setInfos(self.infoText)
  64. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  65. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  66. stdout=PIPE,
  67. universal_newlines=True)
  68. self.openVibeAktiv = True
  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.infoText = self.infoText + 'finished Training\n'
  78. self.controller.setInfos(self.infoText)
  79. self.controller.stop("filterClassic")
  80. break
  81. elif(y != -1 ):
  82. print("Error occured")
  83. self.controller.changeScreen("StartPage")
  84. self.controller.setInfos(self.infoText + "Fehler beim XDawn Training aufgetaucht\n")
  85. self.controller.stop()
  86. process.terminate()
  87. break
  88. self.controller.stop()
  89. #self.controller.filterClassic()
  90. def trainClassifier(self):
  91. print("start training Classifier")
  92. self.infoText = self.infoText + "start training with Classifier -- "
  93. self.controller.setInfos(self.infoText)
  94. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  95. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  96. stdout=PIPE,
  97. universal_newlines=True)
  98. self.openVibeAktiv = True
  99. while True:
  100. output = process.stdout.readline()
  101. print(output.strip())
  102. x = output.find("schlagwort?")
  103. y = output.find("Error")
  104. if(x != -1):
  105. print("Training finished")
  106. self.infoText = self.infoText + 'finished Training\n'
  107. self.controller.setInfos(self.infoText)
  108. process.terminate()
  109. break
  110. elif(y != -1 ):
  111. print("Error occured")
  112. self.controller.changeScreen("StartPage")
  113. self.controller.setInfos(self.infoText + "Fehler beim Classifier Training aufgetaucht\n")
  114. process.terminate()
  115. break
  116. self.controller.changeScreen("StartPage")
  117. self.controller.stop()
  118. def freeSpelling(self):
  119. #bei error auch abrechen?
  120. print("start freeSpelling")
  121. self.infoText = 'start free spelling -- '
  122. self.controller.setInfos(self.infoText)
  123. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  124. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  125. stdout=PIPE,
  126. universal_newlines=True)
  127. self.openVibeAktiv = True
  128. while True:
  129. output = process.stdout.readline()
  130. print(output.strip())
  131. y = output.find("Error")
  132. x = output.find("Schlagwort")
  133. if(x != -1):
  134. print("End Spelling")
  135. process.terminate()
  136. self.infoText = self.infoText + 'finished freespelling\n'
  137. self.controller.setInfos(self.infoText)
  138. self.controller.changeScreen("StartPage")
  139. self.controller.stop()
  140. break
  141. elif(y != -1 ):
  142. print("Error occured")
  143. self.controller.changeScreen("StartPage")
  144. self.controller.setInfos(self.infoText + "Fehler beim Freespelling aufgetaucht\n")
  145. process.terminate()
  146. self.controller.stop()
  147. break
  148. self.controller.changeScreen("StartPage")
  149. self.controller.stop()
  150. def killProzess(self):
  151. if(self.openVibeAktiv):
  152. self.openVibeAktiv = False
  153. print('start killing')
  154. pidOV = 0
  155. items = []
  156. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  157. zeilen = prozesse.split('\n')
  158. for z in zeilen:
  159. if(z.find("openvibe-design") != -1):
  160. z = z.strip()
  161. items = z.split(' ')
  162. pidOV = items[0]
  163. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  164. Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate()
  165. print("killed openvibe-designer")