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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. '''--------------------------------------------------------------------------------------------------
  2. Das Model steuert stellt die Modi unabhaengigen Funktionen bereit
  3. '''
  4. from subprocess import *
  5. from threading import Thread
  6. import time
  7. class Modell(Thread):
  8. def __init__(self,c, dll):
  9. Thread.__init__(self)
  10. self.controller = c
  11. self.dll = dll
  12. self.aktiv= True
  13. def setFunktion(self, func, args=None, kwargs=None):
  14. pass
  15. def startCopySpelling(self):
  16. pass
  17. def trainXDawn(self):
  18. pass
  19. def trainClassifier(self):
  20. pass
  21. def freeSpelling(self):
  22. pass
  23. def stop(self):
  24. '''--------------------------------------------------------------------------------------------------
  25. Die Funktion stop stopt den ablaufenden Thread
  26. '''
  27. print("stop thread")
  28. self.aktiv = False
  29. def run(self):
  30. '''--------------------------------------------------------------------------------------------------
  31. Wird bei Thread.start() aus dem Controller aufgerufen und laeuft ab sobald der Thread destartet wurde
  32. '''
  33. print("start thread")
  34. #self.aktiv = True
  35. t = Thread(target=self.startAquisitionServer)
  36. t.setDaemon(True)
  37. t.start()
  38. while self.aktiv:
  39. time.sleep(0.1)
  40. def killProzessParent(self):
  41. '''--------------------------------------------------------------------------------------------------
  42. schliesst OpenVibe-Designer
  43. '''
  44. print('Parent start killing')
  45. pidOV = 0
  46. items = []
  47. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  48. zeilen = prozesse.split('\n')
  49. for z in zeilen:
  50. if(z.find("openvibe-design") != -1):
  51. z = z.strip()
  52. items = z.split(' ')
  53. pidOV = items[0]
  54. print(pidOV)
  55. if pidOV is not 0:
  56. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  57. try:
  58. Popen(["kill", "-TERM", str(pidOV)], stdout=PIPE).communicate()
  59. except:
  60. print("kein killing")
  61. print("killed openvibe-designer")
  62. def killAcquisitionServer(self):
  63. '''--------------------------------------------------------------------------------------------------
  64. schliesst den Acquisitionserver
  65. '''
  66. print('start killing AS')
  67. pid = 0
  68. items = []
  69. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  70. zeilen = prozesse.split('\n')
  71. for z in zeilen:
  72. if(z.find("openvibe-acquis") != -1):
  73. z = z.strip()
  74. items = z.split(' ')
  75. pid = items[0]
  76. if pid is not 0:
  77. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  78. Popen(["kill", "-TERM", str(pid)], stdout=PIPE).communicate()
  79. print("killed openvibe-acquisitionserver")
  80. def startAquisitionServer(self):
  81. '''--------------------------------------------------------------------------------------------------
  82. startet den Acquisitionserver und steuert die Benutzerausgabe
  83. '''
  84. print("start Aquisitionserver")
  85. self.controller.resetInfo()
  86. self.controller.addInfoText('Aquisitionserver -- Bitte starten sie den Server\n')
  87. command = self.dll.getCommandStartAquisitionServer().split(" ")
  88. process = Popen(command, stdout=PIPE, universal_newlines=True)
  89. self.openVibeAktiv = True
  90. while True:
  91. output = process.stdout.readline()
  92. print(output.strip())
  93. x1 = output.find("Connection succeeded")
  94. x2 = output.find("Now acquiring")
  95. x3 = output.find("Stopping the acquisition")
  96. x4 = output.find("Disconnecting")
  97. init = output.find("Loading plugin: Fiddler")
  98. y = output.find("Error")
  99. if(x1 != -1):
  100. self.controller.addInfoText('Aquisitionserver ist verbunden -- Bitte starten Sie den Server\n')
  101. elif(x2 != -1 ):
  102. self.controller.resetInfo()
  103. self.controller.addInfoText("Aquisitionserver gestartet\n")
  104. self.minimizeWindow("server")
  105. elif(x3 != -1 ):
  106. self.controller.addInfoText("AquisitionServer gestoppt -- Bitte starten Sie den Server\n")
  107. self.positionWindow("server")
  108. elif(x4 != -1 ):
  109. self.controller.addInfoText("Verbindung vom Aquisitionserver getrennt!\n")
  110. self.positionWindow("server")
  111. elif(init != -1 ):
  112. time.sleep(1)
  113. self.positionWindow("server")
  114. elif(y != -1 ):
  115. self.controller.addInfoText("Fehler beim Auisitionserver aufgetaucht\n")
  116. if not self.aktiv:
  117. print("stop")
  118. break
  119. def positionWindow(self, name):
  120. '''--------------------------------------------------------------------------------------------------
  121. positioniert das Fenster auf der GUI
  122. '''
  123. print("calls positionWindow")
  124. parameter = self.controller.getWindowSize()
  125. positionX = int(parameter[0]+ int(parameter[3] * 0.05))
  126. positionY = int(parameter[1]) + int(parameter[2]*0.08)
  127. height = int(parameter[2])*0.55
  128. width = int(parameter[3])*0.9
  129. windowID = Popen(["xdotool", "search", "--onlyvisible", "--name", name], stdout=PIPE).communicate()[0].strip()
  130. try:
  131. print(int(windowID))
  132. Popen(["xdotool", "windowsize", windowID, str(width), str(height)], stdout=PIPE).communicate()
  133. Popen(["xdotool", "windowmove", windowID, str(positionX), str(positionY)], stdout=PIPE).communicate()
  134. Popen(["xdotool", "windowactivate", windowID], stdout=PIPE).communicate()[0].strip()
  135. except:
  136. print("no window")
  137. print(windowID)
  138. self.controller.addInfoText("Fehler: kein Fenster gefunden!")
  139. def minimizeWindow(self, name):
  140. '''--------------------------------------------------------------------------------------------------
  141. minimiert das Fenster
  142. '''
  143. windowID = Popen(["xdotool", "search", "--onlyvisible", "--name", name], stdout=PIPE).communicate()[0].strip()
  144. try:
  145. print(int(windowID))
  146. Popen(["xdotool", "windowminimize", windowID], stdout=PIPE).communicate()
  147. except:
  148. print("no window")
  149. print(windowID)
  150. self.controller.addInfoText("Fehler: kein Fenster gefunden!")