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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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.4
  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", "lightgreen", self.btn_tacCal)
  34. self.BvisCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_visCal)
  35. self.Bp300 = makeBtn(self, "P300 Klassifizierung", "orange", self.btn_p300)
  36. self.BtacCopy = makeBtn(self, "Freies Buchstabieren:\nTest", "lightblue", self.btn_tacCopy)
  37. self.BtacCopyNested = makeBtn(self, "Freies Buchstabieren:\nKategorien", "lightyellow", self.btn_tacCopyNested)
  38. self.BvisCopy = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_visCopy)
  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. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.prm'])
  46. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  47. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  48. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  49. # TODO Lock einführen und bei Returnwert Lock öffnen mit tkinter.Button.config(state = tkinter.DISABLED)
  50. def btn_visCal(self):
  51. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_copySpeller.prm'])
  52. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  53. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  54. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  55. # P300 Classifier #########################
  56. def btn_p300(self):
  57. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  58. # FREESPELL ###############################
  59. def btn_tacCopy(self):
  60. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFree.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. def btn_tacCopyNested(self):
  65. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFreeNested.prm'])
  66. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  67. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  68. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  69. def btn_visCopy(self):
  70. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_freeSpeller.prm'])
  71. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  72. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  73. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  74. # This Function packs all the Buttons into the Layout
  75. def pack_layout(self):
  76. if config['SETTINGS']['paradigm'] == 'Tactile':
  77. self.BtacFilter.pack()
  78. self.BtacCal.pack()
  79. self.Bp300.pack()
  80. self.BtacCopy.pack()
  81. self.BtacCopyNested.pack()
  82. elif config['SETTINGS']['paradigm'] == 'Visual':
  83. self.BvisCal.pack()
  84. self.Bp300.pack()
  85. self.BvisCopy.pack()
  86. # This Function removes all the Buttons from the Layout
  87. def unpack_layout(self):
  88. # Add ALL your Buttons here
  89. self.BtacFilter.pack_forget()
  90. self.BtacCal.pack_forget()
  91. self.BvisCal.pack_forget()
  92. self.Bp300.pack_forget()
  93. self.BtacCopy.pack_forget()
  94. self.BtacCopyNested.pack_forget()
  95. self.BvisCopy.pack_forget()
  96. # set paths
  97. pathOrigin = os.path.dirname(os.path.realpath(__file__)) # set pathOrigin to directory of this file
  98. os.chdir(pathOrigin)
  99. config = configparser.ConfigParser()
  100. configPath = pathOrigin + '/config.ini'
  101. config.read(configPath)
  102. # This Function sets the Paradigm to 'Visual'
  103. def setVisual():
  104. if config['SETTINGS']['paradigm'] == 'Visual':
  105. return
  106. else:
  107. config['SETTINGS']['paradigm'] = 'Visual'
  108. config.write(open(configPath,'w'))
  109. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  110. app.unpack_layout()
  111. app.pack_layout()
  112. # This Function sets the Paradigm to 'Tactile'
  113. def setTactile():
  114. if config['SETTINGS']['paradigm'] == 'Tactile':
  115. return
  116. else:
  117. config['SETTINGS']['paradigm'] = 'Tactile'
  118. config.write(open(configPath,'w'))
  119. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  120. app.unpack_layout()
  121. app.pack_layout()
  122. root = tkinter.Tk()
  123. root.title('PythonBCIgui v' + str(__version__))
  124. # This Function sets the BCI2000 Path
  125. def setPathBci2000():
  126. 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.')
  127. tmpPath = tkinter.filedialog.askdirectory()
  128. if not tmpPath:
  129. pass
  130. else:
  131. config['PATH']['bci2000'] = tmpPath
  132. config.write(open(configPath,'w'))
  133. # This Function sets the TactileBCIFilter Path
  134. def setPathTactileBCIFilter():
  135. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
  136. tmpPath = tkinter.filedialog.askdirectory()
  137. if not tmpPath:
  138. pass
  139. else:
  140. config['PATH']['tactilebcifilter'] = tmpPath
  141. config.write(open(configPath,'w'))
  142. # This Function resets the config
  143. def setConfigDefault():
  144. # config['PATH']['tactilebcifilter'] = r'C:/Users/bci/Desktop/Qt Filter Program/build-TactileBCIFilter-Desktop_Qt_5_15_0_MinGW_32_bit-Release/release'
  145. # config['PATH']['bci2000'] = r'C:/BCI2000/BCI2000 v3.6.beta.R5570/BCI2000.x64'
  146. config['PATH']['tactilebcifilter'] = r'C:\Users\EEG-Gruppe\Desktop\Arduino\Qt Tactile BCI Filter App\Executable'
  147. config['PATH']['bci2000'] = r'C:\Users\EEG-Gruppe\Desktop\BCI Paket\Paradigmen\Tactile\BCI2000\BCI2000-06-13\BCI2000src'
  148. config['SETTINGS']['paradigm'] = r'Visual'
  149. config['SETTINGS']['hardware'] = r'gUSBamp' # TODO Add gNautilus parameters
  150. config.write(open(configPath,'w'))
  151. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  152. app.unpack_layout()
  153. app.pack_layout()
  154. def on_closing():
  155. #self.global_close(root)
  156. root.destroy()
  157. # root.quit()
  158. root.protocol("WM_DELETE_WINDOW", on_closing)
  159. leistenMenu = tkinter.Menu(root)
  160. fileMenu = tkinter.Menu(leistenMenu)
  161. leistenMenu.add_cascade(label="Datei", menu=fileMenu)
  162. fileMenu.add_command(label="Einstellungen Zurücksetzen", command=setConfigDefault)
  163. fileMenu.add_command(label="Beenden", command=on_closing)
  164. paradigmMenu = tkinter.Menu(leistenMenu)
  165. leistenMenu.add_cascade(label="Paradigmen", menu=paradigmMenu)
  166. paradigmMenu.add_command(label="Visual", command=setVisual)
  167. paradigmMenu.add_separator()
  168. paradigmMenu.add_command(label="Tactile", command=setTactile)
  169. pathMenu = tkinter.Menu(leistenMenu)
  170. leistenMenu.add_cascade(label="Pfade", menu=pathMenu)
  171. pathMenu.add_command(label="BCI2000", command=setPathBci2000)
  172. pathMenu.add_separator()
  173. pathMenu.add_command(label="TactileBCIFilter", command=setPathTactileBCIFilter)
  174. root.config(menu = leistenMenu)
  175. app = PythonBCIgui(root)
  176. root.mainloop()
  177. #root.destroy() # optional;