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

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.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. # TODO Hilfestellung nach jedem Button aufploppen lassen:
  46. # Was tun? Wo klicken? Welche File wo laden?
  47. self.pack_layout()
  48. # FILTER ##################################
  49. def btn_tacFilter(self):
  50. subprocess.Popen(config['PATH']['tactilebcifilter'] + r'\TactileBCIFilter.exe')
  51. # KALIBRIERUNGEN ###########################
  52. def btn_tacCal(self):
  53. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.prm'])
  54. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  55. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  56. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  57. # TODO Lock einführen und bei Returnwert Lock öffnen mit tkinter.Button.config(state = tkinter.DISABLED)
  58. def btn_visCal(self):
  59. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_copySpeller.prm'])
  60. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  61. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  62. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  63. # P300 Classifier #########################
  64. def btn_p300(self):
  65. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  66. # COPYSPELL ###########################
  67. def btn_tacCopy(self):
  68. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFree.prm'])
  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_tacCopyNested(self):
  73. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileFreeNested.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. def btn_visCopy(self):
  78. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_freeSpeller.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. # This Function packs all the Buttons into the Layout
  83. def pack_layout(self):
  84. if config['SETTINGS']['paradigm'] == 'Tactile':
  85. self.BtacFilter.pack()
  86. self.BtacCal.pack()
  87. self.Bp300.pack()
  88. self.BtacCopy.pack()
  89. self.BtacCopyNested.pack()
  90. elif config['SETTINGS']['paradigm'] == 'Visual':
  91. self.BvisCal.pack()
  92. self.Bp300.pack()
  93. self.BvisCopy.pack()
  94. # This Function removes all the Buttons from the Layout
  95. def unpack_layout(self):
  96. # Add ALL your Buttons here
  97. self.BtacFilter.pack_forget()
  98. self.BtacCal.pack_forget()
  99. self.BvisCal.pack_forget()
  100. self.Bp300.pack_forget()
  101. self.BtacCopy.pack_forget()
  102. self.BtacCopyNested.pack_forget()
  103. self.BvisCopy.pack_forget()
  104. def global_close(self, window):
  105. window.destroy()
  106. # set paths
  107. pathOrigin = os.path.dirname(os.path.realpath(__file__)) # set pathOrigin to directory of this file
  108. os.chdir(pathOrigin)
  109. config = configparser.ConfigParser()
  110. configPath = pathOrigin + '/config.ini'
  111. config.read(configPath)
  112. def setVisual():
  113. if config['SETTINGS']['paradigm'] == 'Visual':
  114. return
  115. else:
  116. config['SETTINGS']['paradigm'] = 'Visual'
  117. config.write(open(configPath,'w'))
  118. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  119. app.unpack_layout()
  120. app.pack_layout()
  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. def setPathBci2000():
  133. 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.')
  134. tmpPath = tkinter.filedialog.askdirectory()
  135. if not tmpPath:
  136. pass
  137. else:
  138. config['PATH']['bci2000'] = tmpPath
  139. config.write(open(configPath,'w'))
  140. def setPathTactileBCIFilter():
  141. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
  142. tmpPath = tkinter.filedialog.askdirectory()
  143. if not tmpPath:
  144. pass
  145. else:
  146. config['PATH']['tactilebcifilter'] = tmpPath
  147. config.write(open(configPath,'w'))
  148. def setConfigDefault():
  149. # config['PATH']['tactilebcifilter'] = r'C:/Users/bci/Desktop/Qt Filter Program/build-TactileBCIFilter-Desktop_Qt_5_15_0_MinGW_32_bit-Release/release'
  150. # config['PATH']['bci2000'] = r'C:/BCI2000/BCI2000 v3.6.beta.R5570/BCI2000.x64'
  151. config['PATH']['tactilebcifilter'] = r'C:\Users\EEG-Gruppe\Desktop\Arduino\Qt Tactile BCI Filter App\Executable'
  152. config['PATH']['bci2000'] = r'C:\Users\EEG-Gruppe\Desktop\BCI Paket\Paradigmen\Tactile\BCI2000\BCI2000-06-13\BCI2000src'
  153. config['SETTINGS']['paradigm'] = r'Visual'
  154. config['SETTINGS']['hardware'] = r'gUSBamp' # TODO Add gNautilus parameters
  155. config.write(open(configPath,'w'))
  156. app.Lparadigm.config(text = config['SETTINGS']['paradigm'] + ' BCI')
  157. app.unpack_layout()
  158. app.pack_layout()
  159. def on_closing():
  160. #self.global_close(root)
  161. root.destroy()
  162. # root.quit()
  163. root.protocol("WM_DELETE_WINDOW", on_closing)
  164. leistenMenu = tkinter.Menu(root)
  165. fileMenu = tkinter.Menu(leistenMenu)
  166. leistenMenu.add_cascade(label="Datei", menu=fileMenu)
  167. fileMenu.add_command(label="Einstellungen Zurücksetzen", command=setConfigDefault)
  168. fileMenu.add_command(label="Beenden", command=on_closing)
  169. paradigmMenu = tkinter.Menu(leistenMenu)
  170. leistenMenu.add_cascade(label="Paradigmen", menu=paradigmMenu)
  171. paradigmMenu.add_command(label="Visual", command=setVisual)
  172. paradigmMenu.add_separator()
  173. paradigmMenu.add_command(label="Tactile", command=setTactile)
  174. pathMenu = tkinter.Menu(leistenMenu)
  175. leistenMenu.add_cascade(label="Pfade", menu=pathMenu)
  176. pathMenu.add_command(label="BCI2000", command=setPathBci2000)
  177. pathMenu.add_separator()
  178. pathMenu.add_command(label="TactileBCIFilter", command=setPathTactileBCIFilter)
  179. root.config(menu = leistenMenu)
  180. app = PythonBCIgui(root)
  181. root.mainloop()
  182. #root.destroy() # optional;