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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 tkinter.messagebox
  10. import subprocess
  11. import configparser
  12. import os
  13. # TODO Eventuell updatefunktion über git pull mit einbauen!
  14. __version__ = 0.41
  15. class PythonBCIgui:
  16. def __init__(self, master):
  17. # Einstellung der Button Größe
  18. textH = 4
  19. textW = 20
  20. def makeBtn(self, text, bg, command):
  21. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  22. self.button.config( height = textH, width = textW )
  23. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  24. return self.button
  25. frame = tkinter.Frame(master)
  26. frame.pack()
  27. # label generation
  28. headerText = config['SETTINGS']['paradigm'] + ' BCI'
  29. self.Lparadigm = tkinter.Label(frame, text = headerText, height = 4, width = 20)
  30. self.Lparadigm['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  31. self.Lparadigm.pack()
  32. # button generation
  33. self.BtacFilter = makeBtn(self, "Filter", "pink", self.btn_tacFilter)
  34. self.BtacCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_tacCal)
  35. self.BvisCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_visCal)
  36. self.Bp300 = makeBtn(self, "P300 Klassifizierung", "orange", self.btn_p300)
  37. self.BtacFree = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_tacFree)
  38. self.BvisFree = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_visFree)
  39. self.pack_layout()
  40. # FILTER ###################################
  41. def btn_tacFilter(self):
  42. subprocess.Popen(config['PATH']['tactilebcifilter'] + r'\TactileBCIFilter.exe')
  43. # KALIBRIERUNGEN ###########################
  44. def btn_tacCal(self):
  45. if config['SETTINGS']['tactilemode'] == 'Motors':
  46. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.prm'])
  47. elif config['SETTINGS']['tactilemode'] == 'Nested':
  48. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibrationNested.prm'])
  49. # TODO Throw error if else
  50. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  51. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  52. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  53. # TODO Lock einführen und bei Returnwert Lock öffnen mit tkinter.Button.config(state = tkinter.DISABLED)
  54. def btn_visCal(self):
  55. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBampVisualCalibration.prm'])
  56. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  57. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  58. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  59. # P300 Classifier #########################
  60. def btn_p300(self):
  61. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  62. # FREESPELL ###############################
  63. def btn_tacFree(self):
  64. if config['SETTINGS']['tactilemode'] == 'Motors':
  65. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFree.prm'])
  66. elif config['SETTINGS']['tactilemode'] == 'Nested':
  67. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFreeNested.prm'])
  68. # TODO throw error if else
  69. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  70. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  71. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  72. def btn_visFree(self):
  73. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBampVisualFree.prm'])
  74. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  75. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  76. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  77. # This Function packs all the Buttons into the Layout
  78. def pack_layout(self):
  79. if config['SETTINGS']['paradigm'] == 'Tactile':
  80. self.BtacFilter.pack()
  81. self.BtacCal.pack()
  82. self.Bp300.pack()
  83. self.BtacFree.pack()
  84. elif config['SETTINGS']['paradigm'] == 'Visual':
  85. self.BvisCal.pack()
  86. self.Bp300.pack()
  87. self.BvisFree.pack()
  88. # This Function removes all the Buttons from the Layout
  89. def unpack_layout(self):
  90. # Add ALL your Buttons here
  91. self.BtacFilter.pack_forget()
  92. self.BtacCal.pack_forget()
  93. self.BvisCal.pack_forget()
  94. self.Bp300.pack_forget()
  95. self.BtacFree.pack_forget()
  96. self.BvisFree.pack_forget()
  97. # set paths
  98. pathOrigin = os.path.dirname(os.path.realpath(__file__)) # set pathOrigin to directory of this file
  99. os.chdir(pathOrigin)
  100. config = configparser.ConfigParser()
  101. configPath = pathOrigin + '/config.ini'
  102. config.read(configPath)
  103. # This Function sets the Paradigm to 'Visual'
  104. def setVisual():
  105. if config['SETTINGS']['paradigm'] == 'Visual':
  106. return
  107. else:
  108. config['SETTINGS']['paradigm'] = 'Visual'
  109. config.write(open(configPath,'w'))
  110. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  111. app.unpack_layout()
  112. app.pack_layout()
  113. # This Function sets the Paradigm to 'Tactile'
  114. def setTactile():
  115. if config['SETTINGS']['paradigm'] == 'Tactile':
  116. return
  117. else:
  118. config['SETTINGS']['paradigm'] = 'Tactile'
  119. config.write(open(configPath,'w'))
  120. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  121. app.unpack_layout()
  122. app.pack_layout()
  123. def setTactileModeMotors():
  124. if config['SETTINGS']['tactilemode'] == 'Motors':
  125. return
  126. else:
  127. config['SETTINGS']['tactilemode'] = 'Motors'
  128. config.write(open(configPath,'w'))
  129. def setTactileModeNested():
  130. if config['SETTINGS']['tactilemode'] == 'Nested':
  131. return
  132. else:
  133. config['SETTINGS']['tactilemode'] = 'Nested'
  134. config.write(open(configPath,'w'))
  135. # This Function sets the BCI2000 Path
  136. def setPathBci2000():
  137. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den BCI2000 Ordner aus, in dem sich die Ordner "batch", "data", "parms", "prog" und "tools" befinden.')
  138. tmpPath = tkinter.filedialog.askdirectory()
  139. if not tmpPath:
  140. pass
  141. else:
  142. config['PATH']['bci2000'] = tmpPath
  143. config.write(open(configPath,'w'))
  144. # This Function sets the TactileBCIFilter Path
  145. def setPathTactileBCIFilter():
  146. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
  147. tmpPath = tkinter.filedialog.askdirectory()
  148. if not tmpPath:
  149. pass
  150. else:
  151. config['PATH']['tactilebcifilter'] = tmpPath
  152. config.write(open(configPath,'w'))
  153. # This Function resets the config
  154. def setConfigDefault():
  155. # config['PATH']['tactilebcifilter'] = r'C:/Users/bci/Desktop/Qt Filter Program/build-TactileBCIFilter-Desktop_Qt_5_15_0_MinGW_32_bit-Release/release'
  156. # config['PATH']['bci2000'] = r'C:/BCI2000/BCI2000 v3.6.beta.R5570/BCI2000.x64'
  157. config['PATH']['tactilebcifilter'] = r'C:\Users\EEG-Gruppe\Desktop\Arduino\Qt Tactile BCI Filter App\Executable'
  158. config['PATH']['bci2000'] = r'C:\Users\EEG-Gruppe\Desktop\BCI Paket\Paradigmen\Tactile\BCI2000\BCI2000-06-13\BCI2000src'
  159. config['SETTINGS']['paradigm'] = r'Visual'
  160. config['SETTINGS']['hardware'] = r'gUSBamp' # TODO Add gNautilus parameters
  161. config['SETTINGS']['tactilemode'] = r'Motors'
  162. config.write(open(configPath,'w'))
  163. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  164. app.unpack_layout()
  165. app.pack_layout()
  166. def on_closing():
  167. #self.global_close(root)
  168. root.destroy()
  169. # root.quit()
  170. root = tkinter.Tk()
  171. root.title('PythonBCIgui v' + str(__version__))
  172. root.protocol("WM_DELETE_WINDOW", on_closing)
  173. leistenMenu = tkinter.Menu(root)
  174. fileMenu = tkinter.Menu(leistenMenu)
  175. leistenMenu.add_cascade(label="Datei", menu=fileMenu)
  176. fileMenu.add_command(label="Einstellungen Zurücksetzen", command=setConfigDefault)
  177. fileMenu.add_command(label="Beenden", command=on_closing)
  178. paradigmMenu = tkinter.Menu(leistenMenu)
  179. leistenMenu.add_cascade(label="Paradigmen", menu=paradigmMenu)
  180. paradigmMenu.add_command(label="Visual", command=setVisual)
  181. paradigmMenu.add_separator()
  182. paradigmMenu.add_command(label="Tactile", command=setTactile)
  183. pathMenu = tkinter.Menu(leistenMenu)
  184. leistenMenu.add_cascade(label="Pfade", menu=pathMenu)
  185. pathMenu.add_command(label="BCI2000", command=setPathBci2000)
  186. pathMenu.add_separator()
  187. pathMenu.add_command(label="TactileBCIFilter", command=setPathTactileBCIFilter)
  188. tactileModeMenu = tkinter.Menu(leistenMenu)
  189. leistenMenu.add_cascade(label="Taktiler Modus", menu=tactileModeMenu)
  190. tactileModeMenu.add_command(label="Motoren", command=setTactileModeMotors)
  191. tactileModeMenu.add_command(label="Kategorien", command=setTactileModeNested)
  192. root.config(menu = leistenMenu)
  193. app = PythonBCIgui(root)
  194. root.mainloop()
  195. #root.destroy() # optional;