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.

UIModell.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. def stop(self):
  12. print("stop")
  13. self.aktiv = False
  14. def setFunktion(self, func, args=None, kwargs=None):
  15. self.func = func
  16. self.args = args or []
  17. self.kwargs = kwargs or {}
  18. def run(self):
  19. #self.aktiv = True
  20. t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
  21. t.setDaemon(True)
  22. t.start()
  23. while self.aktiv:
  24. time.sleep(0.1)
  25. def startCopySpelling(self):
  26. print("start copySpelling")
  27. path = self.PATH_FILES + 'p300-visual-1-acquisition.xml'
  28. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  29. stdout=PIPE,
  30. universal_newlines=True)
  31. while True:
  32. output = process.stdout.readline()
  33. print(output.strip())
  34. x = output.find("schlagwort?")
  35. if(x != -1):
  36. print("Training finished")
  37. process.terminate()
  38. break
  39. self.killProzess()
  40. self.controller.filterXdawn()
  41. def trainXDawn(self):
  42. print("start training Xdawn")
  43. self.controller.setTitle("start training with Xdawn")
  44. self.controller.setInfos("This may take a while")
  45. print("test")
  46. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  47. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  48. stdout=PIPE,
  49. universal_newlines=True)
  50. while self.aktiv:
  51. output = process.stdout.readline()
  52. print(output.strip())
  53. x = output.find("Training finished and saved")
  54. if(x != -1):
  55. print("Training finished")
  56. process.terminate()
  57. break
  58. self.controller.setInfos("finished Training with xDawn")
  59. self.killProzess()
  60. #self.controller.filterClassic()
  61. def trainClassifier(self):
  62. print("start training Classifier")
  63. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  64. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  65. stdout=PIPE,
  66. universal_newlines=True)
  67. while True:
  68. output = process.stdout.readline()
  69. print(output.strip())
  70. x = output.find("schlagwort?")
  71. if(x != -1):
  72. print("Training finished")
  73. process.terminate()
  74. break
  75. self.killProzess()
  76. def freeSpelling(self):
  77. print("start freeSpelling")
  78. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  79. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  80. stdout=PIPE,
  81. universal_newlines=True)
  82. while True:
  83. output = process.stdout.readline()
  84. print(output.strip())
  85. x = output.find("schlagwort?")
  86. if(x != -1):
  87. print("End Spelling")
  88. process.terminate()
  89. break
  90. self.killProzess()
  91. def killProzess(self):
  92. print('start killing')
  93. pidOV = 0
  94. pidP = 0
  95. items = []
  96. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  97. zeilen = prozesse.split('\n')
  98. for z in zeilen:
  99. if(z.find("openvibe-design") != -1):
  100. z = z.strip()
  101. items = z.split(' ')
  102. pidOV = items[0]
  103. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  104. Popen(["kill", "-TERM", pidOV], stdout=PIPE).communicate()
  105. print("killed openvibe-designer")