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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. textHsmall = 2
  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. def makeBtnSmall(self, text, bg, command):
  26. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  27. self.button.config( height = textHsmall, width = textW )
  28. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  29. return self.button
  30. frame = tkinter.Frame(master)
  31. frame.pack()
  32. # label generation
  33. headerText = config['SETTINGS']['paradigm'] + ' BCI'
  34. self.Lparadigm = tkinter.Label(frame, text = headerText, height = 4, width = 20)
  35. self.Lparadigm['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  36. self.Lparadigm.pack()
  37. # button generation
  38. self.BtacFilter = makeBtn(self, "Filter", "pink", self.btn_tacFilter)
  39. self.BtacCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_tacCal)
  40. self.BvisCal = makeBtn(self, "Kalibrierung", "lightgreen", self.btn_visCal)
  41. self.Bp300 = makeBtn(self, "P300 Klassifizierung", "orange", self.btn_p300)
  42. self.BtacCopy = makeBtn(self, "Freies Buchstabieren:\nTest", "lightblue", self.btn_tacCopy)
  43. self.BtacCopyNested = makeBtn(self, "Freies Buchstabieren:\nKategorien", "lightyellow", self.btn_tacCopyNested)
  44. self.BvisCopy = makeBtn(self, "Freies Buchstabieren", "lightblue", self.btn_visCopy)
  45. frame.rowconfigure((0,1), weight=1) # make buttons stretch when # TODO Remove
  46. frame.columnconfigure((0,2), weight=1) # when window is resized
  47. # TODO Hilfestellung nach jedem Button aufploppen lassen:
  48. # Was tun? Wo klicken? Welche File wo laden?
  49. self.pack_layout()
  50. # FILTER ##################################
  51. def btn_tacFilter(self):
  52. subprocess.Popen(config['PATH']['tactilebcifilter'] + r'\TactileBCIFilter.exe')
  53. # KALIBRIERUNGEN ###########################
  54. def btn_tacCal(self):
  55. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.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. # TODO Lock einführen und bei Returnwert Lock öffnen mit tkinter.Button.config(state = tkinter.DISABLED)
  60. def btn_visCal(self):
  61. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_copySpeller.prm'])
  62. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  63. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  64. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  65. # P300 Classifier #########################
  66. def btn_p300(self):
  67. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  68. # COPYSPELL ###########################
  69. def btn_tacCopy(self):
  70. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFree.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. def btn_tacCopyNested(self):
  75. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFreeNested.prm'])
  76. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  77. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  78. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  79. def btn_visCopy(self):
  80. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_freeSpeller.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. # This Function packs all the Buttons into the Layout
  85. def pack_layout(self):
  86. if config['SETTINGS']['paradigm'] == 'Tactile':
  87. self.BtacFilter.pack()
  88. self.BtacCal.pack()
  89. self.Bp300.pack()
  90. self.BtacCopy.pack()
  91. self.BtacCopyNested.pack()
  92. elif config['SETTINGS']['paradigm'] == 'Visual':
  93. self.BvisCal.pack()
  94. self.Bp300.pack()
  95. self.BvisCopy.pack()
  96. # This Function removes all the Buttons from the Layout
  97. def unpack_layout(self):
  98. # Add ALL your Buttons here
  99. self.BtacFilter.pack_forget()
  100. self.BtacCal.pack_forget()
  101. self.BvisCal.pack_forget()
  102. self.Bp300.pack_forget()
  103. self.BtacCopy.pack_forget()
  104. self.BtacCopyNested.pack_forget()
  105. self.BvisCopy.pack_forget()
  106. def global_close(self, window):
  107. window.destroy()
  108. # set paths
  109. pathOrigin = os.path.dirname(os.path.realpath(__file__)) # set pathOrigin to directory of this file
  110. os.chdir(pathOrigin)
  111. config = configparser.ConfigParser()
  112. configPath = pathOrigin + '/config.ini'
  113. config.read(configPath)
  114. def setVisual():
  115. if config['SETTINGS']['paradigm'] == 'Visual':
  116. return
  117. else:
  118. config['SETTINGS']['paradigm'] = 'Visual'
  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 setTactile():
  124. if config['SETTINGS']['paradigm'] == 'Tactile':
  125. return
  126. else:
  127. config['SETTINGS']['paradigm'] = 'Tactile'
  128. config.write(open(configPath,'w'))
  129. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  130. app.unpack_layout()
  131. app.pack_layout()
  132. root = tkinter.Tk()
  133. root.title('PythonBCIgui v' + str(__version__))
  134. def setPathBci2000():
  135. 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.')
  136. tmpPath = tkinter.filedialog.askdirectory()
  137. if not tmpPath:
  138. pass
  139. else:
  140. config['PATH']['bci2000'] = tmpPath
  141. config.write(open(configPath,'w'))
  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. def setConfigDefault():
  151. # config['PATH']['tactilebcifilter'] = r'C:/Users/bci/Desktop/Qt Filter Program/build-TactileBCIFilter-Desktop_Qt_5_15_0_MinGW_32_bit-Release/release'
  152. # config['PATH']['bci2000'] = r'C:/BCI2000/BCI2000 v3.6.beta.R5570/BCI2000.x64'
  153. config['PATH']['tactilebcifilter'] = r'C:\Users\EEG-Gruppe\Desktop\Arduino\Qt Tactile BCI Filter App\Executable'
  154. config['PATH']['bci2000'] = r'C:\Users\EEG-Gruppe\Desktop\BCI Paket\Paradigmen\Tactile\BCI2000\BCI2000-06-13\BCI2000src'
  155. config['SETTINGS']['paradigm'] = r'Visual'
  156. config['SETTINGS']['hardware'] = r'gUSBamp' # TODO Add gNautilus parameters
  157. config.write(open(configPath,'w'))
  158. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  159. app.unpack_layout()
  160. app.pack_layout()
  161. def on_closing():
  162. #self.global_close(root)
  163. root.destroy()
  164. # root.quit()
  165. root.protocol("WM_DELETE_WINDOW", on_closing)
  166. leistenMenu = tkinter.Menu(root)
  167. fileMenu = tkinter.Menu(leistenMenu)
  168. leistenMenu.add_cascade(label="Datei", menu=fileMenu)
  169. fileMenu.add_command(label="Einstellungen Zurücksetzen", command=setConfigDefault)
  170. fileMenu.add_command(label="Beenden", command=on_closing)
  171. paradigmMenu = tkinter.Menu(leistenMenu)
  172. leistenMenu.add_cascade(label="Paradigmen", menu=paradigmMenu)
  173. paradigmMenu.add_command(label="Visual", command=setVisual)
  174. paradigmMenu.add_separator()
  175. paradigmMenu.add_command(label="Tactile", command=setTactile)
  176. pathMenu = tkinter.Menu(leistenMenu)
  177. leistenMenu.add_cascade(label="Pfade", menu=pathMenu)
  178. pathMenu.add_command(label="BCI2000", command=setPathBci2000)
  179. pathMenu.add_separator()
  180. pathMenu.add_command(label="TactileBCIFilter", command=setPathTactileBCIFilter)
  181. root.config(menu = leistenMenu)
  182. app = PythonBCIgui(root)
  183. root.mainloop()
  184. #root.destroy() # optional;