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