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. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  77. Popen(["kill", "-TERM", str(pid)], stdout=PIPE).communicate()
  78. print("killed openvibe-acquisitionserver")
  79. def startAquisitionServer(self):
  80. '''--------------------------------------------------------------------------------------------------
  81. startet den Acquisitionserver und steuert die Benutzerausgabe
  82. '''
  83. print("start Aquisitionserver")
  84. self.controller.resetInfo()
  85. self.controller.addInfoText('Aquisitionserver -- Bitte starten sie den Server\n')
  86. command = self.dll.getCommandStartAquisitionServer().split(" ")
  87. process = Popen(command, stdout=PIPE, universal_newlines=True)
  88. self.openVibeAktiv = True
  89. while True:
  90. output = process.stdout.readline()
  91. print(output.strip())
  92. x1 = output.find("Connection succeeded")
  93. x2 = output.find("Now acquiring")
  94. x3 = output.find("Stopping the acquisition")
  95. x4 = output.find("Disconnecting")
  96. init = output.find("Loading plugin: Fiddler")
  97. y = output.find("Error")
  98. if(x1 != -1):
  99. self.controller.addInfoText('Aquisitionserver ist verbunden -- Bitte starten Sie den Server\n')
  100. elif(x2 != -1 ):
  101. self.controller.resetInfo()
  102. self.controller.addInfoText("Aquisitionserver gestartet\n")
  103. self.minimizeWindow("server")
  104. elif(x3 != -1 ):
  105. self.controller.addInfoText("AquisitionServer gestoppt -- Bitte starten Sie den Server\n")
  106. self.positionWindow("server")
  107. elif(x4 != -1 ):
  108. self.controller.addInfoText("Verbindung vom Aquisitionserver getrennt!\n")
  109. self.positionWindow("server")
  110. elif(init != -1 ):
  111. time.sleep(1)
  112. self.positionWindow("server")
  113. elif(y != -1 ):
  114. self.controller.addInfoText("Fehler beim Auisitionserver aufgetaucht\n")
  115. if not self.aktiv:
  116. print("stop")
  117. break
  118. def positionWindow(self, name):
  119. '''--------------------------------------------------------------------------------------------------
  120. positioniert das Fenster auf der GUI
  121. '''
  122. print("calls positionWindow")
  123. parameter = self.controller.getWindowSize()
  124. positionX = int(parameter[0]+ int(parameter[3] * 0.05))
  125. positionY = int(parameter[1]) + int(parameter[2]*0.08)
  126. height = int(parameter[2])*0.55
  127. width = int(parameter[3])*0.9
  128. windowID = Popen(["xdotool", "search", "--onlyvisible", "--name", name], stdout=PIPE).communicate()[0].strip()
  129. try:
  130. print(int(windowID))
  131. Popen(["xdotool", "windowsize", windowID, str(width), str(height)], stdout=PIPE).communicate()
  132. Popen(["xdotool", "windowmove", windowID, str(positionX), str(positionY)], stdout=PIPE).communicate()
  133. Popen(["xdotool", "windowactivate", windowID], stdout=PIPE).communicate()[0].strip()
  134. except:
  135. print("no window")
  136. print(windowID)
  137. self.controller.addInfoText("Fehler: kein Fenster gefunden!")
  138. def minimizeWindow(self, name):
  139. '''--------------------------------------------------------------------------------------------------
  140. minimiert das Fenster
  141. '''
  142. windowID = Popen(["xdotool", "search", "--onlyvisible", "--name", name], stdout=PIPE).communicate()[0].strip()
  143. try:
  144. print(int(windowID))
  145. Popen(["xdotool", "windowminimize", windowID], stdout=PIPE).communicate()
  146. except:
  147. print("no window")
  148. print(windowID)
  149. self.controller.addInfoText("Fehler: kein Fenster gefunden!")