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

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