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.

app.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Sep 4 11:36:24 2020
  4. @author: Igor Beloschapkin
  5. """
  6. import tkinter
  7. import tkinter.font
  8. import tkinter.filedialog
  9. import subprocess
  10. import configparser
  11. import os
  12. # import queue
  13. # own code:
  14. # from questionnaire import quest
  15. # from wheelchairAdapter import BCI2000ReceiverThread
  16. # TODO Eventuell updatefunktion über git pull mit einbauen!
  17. __version__ = 0.4
  18. class PythonBCIgui:
  19. def __init__(self, master):
  20. # Einstellung der Button Größe
  21. textH = 4
  22. textHsmall = 2
  23. textW = 20
  24. def makeBtn(self, text, bg, command):
  25. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  26. self.button.config( height = textH, width = textW )
  27. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  28. return self.button
  29. def makeBtnSmall(self, text, bg, command):
  30. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  31. self.button.config( height = textHsmall, width = textW )
  32. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  33. return self.button
  34. frame = tkinter.Frame(master)
  35. frame.pack()
  36. # label generation
  37. headerText = config['SETTINGS']['paradigm'] + ' BCI'
  38. self.Lparadigm = tkinter.Label(frame, text = headerText, height = 4, width = 20)
  39. self.Lparadigm['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  40. self.Lparadigm.pack()
  41. # button generation
  42. self.BtacFilter = makeBtn(self, "Filter", "pink", self.btn_tacFilter)
  43. self.BtacCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_tacCal)
  44. self.BvisCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_visCal)
  45. self.Bp300 = makeBtn(self, "P300 Klassifizierung", "orange", self.btn_p300)
  46. self.BtacCopy = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_tacCopy)
  47. self.BvisCopy = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_visCopy)
  48. self.BtacSimul = makeBtn(self, "Rollstuhlsimulator", "lightyellow", self.btn_tacSimul)
  49. # self.Bquest = makeBtnSmall(self, "Fragebogen", "green", self.btn_quest, TOP)
  50. frame.rowconfigure((0,1), weight=1) # make buttons stretch when
  51. frame.columnconfigure((0,2), weight=1) # when window is resized
  52. # TODO Hilfestellung nach jedem Button aufploppen lassen:
  53. # Was tun? Wo klicken? Welche File wo laden?
  54. self.pack_layout()
  55. # 1. FILTER ##################################
  56. def btn_tacFilter(self):
  57. print('Starte TactileBCIFilter.exe')
  58. subprocess.Popen(config['PATH']['tactilebcifilter'] + r'\TactileBCIFilter.exe')
  59. # 2. KALIBIERUNGEN ###########################
  60. def btn_tacCal(self):
  61. print('starte taktile Kalibrierung')
  62. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.prm'])
  63. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  64. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  65. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  66. # TODO Lock einführen und bei Returnwert Lock öffnen mit tkinter.Button.config(state = tkinter.DISABLED)
  67. def btn_visCal(self):
  68. print('starte visuelle Kalibrierung')
  69. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_copySpeller.prm'])
  70. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  71. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  72. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  73. # 3. P300 Classifier #########################
  74. def btn_p300(self):
  75. print('Starte P300Classifier.exe')
  76. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  77. # 4. COPYSPELL ###########################
  78. def btn_tacCopy(self):
  79. print('Starte taktilen Speller')
  80. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCopy.prm'])
  81. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  82. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  83. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  84. def btn_visCopy(self):
  85. print('Starte visuellen Speller')
  86. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_freeSpeller.prm'])
  87. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  88. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  89. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  90. # 5. WHEELCHAIR SIMULATOR ###########################
  91. def btn_tacSimul(self):
  92. print('Starte Wheelchair Simulator')
  93. # BCI2000ReceiverThread1.start()
  94. subprocess.Popen(config['PATH']['wheelchairsimulator'] + r'\Wheels_Occlusion_AutoLog.exe')
  95. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileDrive.prm'])
  96. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  97. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  98. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  99. # QUESTIONNAIRE PROMPT ###########################
  100. # def btn_quest(self):
  101. #root.destroy()
  102. # self.startQuestions(self.paradigmText)
  103. # def startQuestions(self, para):
  104. # print('Starte Fragebogen')
  105. # q = quest(para)
  106. # q.qSatisfaction()
  107. # q.qExhaustion()
  108. # q.qSubjControl()
  109. # q.qCtrlChange()
  110. # q.save()
  111. def pack_layout(self):
  112. # This Function packs all the Buttons into the Layout
  113. if config['SETTINGS']['paradigm'] == 'Tactile':
  114. self.BtacFilter.pack()
  115. self.BtacCal.pack()
  116. elif config['SETTINGS']['paradigm'] == 'Visual':
  117. self.BvisCal.pack()
  118. self.Bp300.pack()
  119. if config['SETTINGS']['paradigm'] == 'Tactile':
  120. self.BtacCopy.pack()
  121. self.BtacSimul.pack()
  122. elif config['SETTINGS']['paradigm'] == 'Visual':
  123. self.BvisCopy.pack()
  124. def unpack_layout(self):
  125. # This Function removes all the Buttons from the Layout
  126. # Add ALL your Buttons here
  127. self.BtacFilter.pack_forget()
  128. self.BtacCal.pack_forget()
  129. self.BvisCal.pack_forget()
  130. self.Bp300.pack_forget()
  131. self.BtacCopy.pack_forget()
  132. self.BtacSimul.pack_forget()
  133. self.BvisCopy.pack_forget()
  134. def global_close(self, window):
  135. print('Beenden')
  136. window.destroy()
  137. # set paths
  138. pathOrigin = os.path.dirname(os.path.realpath(__file__)) # set pathOrigin to directory of this file
  139. os.chdir(pathOrigin)
  140. config = configparser.ConfigParser()
  141. configPath = pathOrigin + '/config.ini'
  142. config.read(configPath)
  143. def setVisual():
  144. config['SETTINGS']['paradigm'] = 'Visual'
  145. config.write(open(configPath,'w'))
  146. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  147. app.unpack_layout()
  148. app.pack_layout()
  149. def setTactile():
  150. config['SETTINGS']['paradigm'] = 'Tactile'
  151. config.write(open(configPath,'w'))
  152. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  153. app.unpack_layout()
  154. app.pack_layout()
  155. root = tkinter.Tk()
  156. root.title('PythonBCIgui v' + str(__version__))
  157. def setPathBci2000():
  158. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den BCI2000 Ordner aus, in dem sich die Ordner "batch", "data", "icons", "parms", "prog" und "tools" befinden.')
  159. tmpPath = tkinter.filedialog.askdirectory()
  160. if not tmpPath:
  161. pass
  162. else:
  163. config['PATH']['bci2000'] = tmpPath
  164. config.write(open(configPath,'w'))
  165. def setPathTactileBCIFilter():
  166. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
  167. tmpPath = tkinter.filedialog.askdirectory()
  168. if not tmpPath:
  169. pass
  170. else:
  171. config['PATH']['tactilebcifilter'] = tmpPath
  172. config.write(open(configPath,'w'))
  173. def setPathWheelchair():
  174. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die Wheels_Occlusion_AutoLog.exe befindet.')
  175. tmpPath = tkinter.filedialog.askdirectory()
  176. if not tmpPath:
  177. pass
  178. else:
  179. config['PATH']['wheelchairsimulator'] = tmpPath
  180. config.write(open(configPath,'w'))
  181. def setConfigDefault():
  182. # config['PATH']['tactilebcifilter'] = r'C:/Users/bci/Desktop/Qt Filter Program/build-TactileBCIFilter-Desktop_Qt_5_15_0_MinGW_32_bit-Release/release'
  183. # config['PATH']['bci2000'] = r'C:/BCI2000/BCI2000 v3.6.beta.R5570/BCI2000.x64'
  184. # config['PATH']['wheelchairsimulator'] = r'C:\Users\bci\Desktop\Wheelchair'
  185. config['PATH']['tactilebcifilter'] = r'C:\Users\EEG-Gruppe\Desktop\Arduino\Qt Tactile BCI Filter App\Executable'
  186. config['PATH']['bci2000'] = r'C:\Users\EEG-Gruppe\Desktop\BCI Paket\Paradigmen\Tactile\BCI2000\BCI2000-06-13\BCI2000src'
  187. config['PATH']['wheelchairsimulator'] = r'C:\Users\EEG-Gruppe\Desktop\Wheelchair'
  188. config['SETTINGS']['paradigm'] = r'Visual'
  189. config['SETTINGS']['hardware'] = r'gUSBamp'
  190. config.write(open(configPath,'w'))
  191. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  192. app.unpack_layout()
  193. app.pack_layout()
  194. def on_closing():
  195. #self.global_close(root)
  196. print('Beenden')
  197. root.destroy()
  198. # root.quit()
  199. root.protocol("WM_DELETE_WINDOW", on_closing)
  200. leistenMenu = tkinter.Menu(root)
  201. fileMenu = tkinter.Menu(leistenMenu)
  202. leistenMenu.add_cascade(label="Datei", menu=fileMenu)
  203. fileMenu.add_command(label="Einstellungen Zurücksetzen", command=setConfigDefault)
  204. fileMenu.add_command(label="Beenden", command=on_closing)
  205. paradigmMenu = tkinter.Menu(leistenMenu)
  206. leistenMenu.add_cascade(label="Paradigmen", menu=paradigmMenu)
  207. paradigmMenu.add_command(label="Visual", command=setVisual)
  208. paradigmMenu.add_separator()
  209. paradigmMenu.add_command(label="Tactile", command=setTactile)
  210. pathMenu = tkinter.Menu(leistenMenu)
  211. leistenMenu.add_cascade(label="Pfade", menu=pathMenu)
  212. pathMenu.add_command(label="BCI2000", command=setPathBci2000)
  213. pathMenu.add_separator()
  214. pathMenu.add_command(label="TactileBCIFilter", command=setPathTactileBCIFilter)
  215. pathMenu.add_separator()
  216. pathMenu.add_command(label="Wheelchair Simulator", command=setPathWheelchair)
  217. root.config(menu = leistenMenu)
  218. # # initialize queue for wheelchairadapter
  219. # phaseInSequenceQueue = queue.Queue()
  220. # StimulusCodeQueue = queue.Queue()
  221. # RunApplication = True
  222. # # initialize BCI2000ReceiverThread for wheelchairadapter
  223. # BCI2000ReceiverThread1 = BCI2000ReceiverThread(1, phaseInSequenceQueue, StimulusCodeQueue)
  224. app = PythonBCIgui(root)
  225. root.mainloop()
  226. #root.destroy() # optional;
  227. # TODO Remove prints before deployment