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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 subprocess
  8. import configparser
  9. # own code:
  10. # from questionnaire import quest
  11. # TODO Eventuell updatefunktion über git pull mit einbauen!
  12. __version__ = 0.3
  13. class App:
  14. def __init__(self, master):
  15. self.paradigmText = tkinter.sys.argv[1]
  16. # App.paradigmText = sys.argv[1]
  17. # pathOrigin = os.path.dirname(os.path.realpath(__file__))
  18. # TODO current working directory auf root von dieser file setzen
  19. # global pathSave
  20. # pathSave = "\\questions\\" + self.paradigmText
  21. # pathSave = os.getcwd() + pathSave
  22. config.read('config.ini')
  23. # Einstellung der GUI Größe
  24. textH = 4
  25. textHsmall = 2
  26. textW = 20
  27. def makeBtn(self, text, bg, command, side):
  28. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  29. self.button.config( height = textH, width = textW )
  30. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  31. self.button.pack(side=side)
  32. return self.button
  33. def makeBtnSmall(self, text, bg, command, side):
  34. self.button = tkinter.Button(frame, text=text, bg=bg, command=command)
  35. self.button.config( height = textHsmall, width = textW )
  36. self.button['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  37. self.button.pack(side=side)
  38. return self.button
  39. frame = tkinter.Frame(master)
  40. frame.pack()
  41. # label generation
  42. headerText = 'PythonBCIgui V' + str(__version__) + '\n\n' + self.paradigmText + ' BCI'
  43. self.Lparadigm = tkinter.Label(frame, text = headerText, height = 4, width = 20)
  44. self.Lparadigm['font'] = tkinter.font.Font(family='Helvetica', size=16, weight='bold')
  45. self.Lparadigm.pack()
  46. # button generation
  47. if self.paradigmText == 'Tactile':
  48. self.Bfilter = makeBtn(self, "1. Filter", "lightyellow", self.btn_filter, tkinter.TOP)
  49. self.BtacCal = makeBtn(self, "2. Kalibrierung", "lightgreen", self.btn_tacCal, tkinter.TOP)
  50. self.Bp300 = makeBtn(self, "3. P300 Klassifizierung", "orange", self.btn_p300, tkinter.TOP)
  51. self.BtacCopy = makeBtn(self, "4. Freies Buchstabieren", "lightblue", self.btn_tacCopy, tkinter.TOP)
  52. self.BtacSimul = makeBtn(self, "5. Rollstuhlsimulator", "pink", self.btn_tacSimul, tkinter.TOP)
  53. elif self.paradigmText == 'Visual':
  54. self.Bfilter = makeBtn(self, "1. Filter", "lightyellow", self.btn_filter, tkinter.TOP)
  55. self.BvisCal = makeBtn(self, "2. Kalibrierung", "lightgreen", self.btn_visCal, tkinter.TOP)
  56. self.Bp300 = makeBtn(self, "3. P300 Klassifizierung", "orange", self.btn_p300, tkinter.TOP)
  57. self.BvisCopy = makeBtn(self, "4. Freies Buchstabieren", "lightblue", self.btn_visCopy, tkinter.TOP)
  58. elif self.paradigmText == 'Test': # TODO Remove
  59. self.Bfilter = makeBtn(self, "1. Filter", "lightyellow", self.btn_filter, tkinter.TOP)
  60. self.BvisCal = makeBtn(self, "2. Kalibrierung", "lightgreen", self.btn_visCal, tkinter.TOP)
  61. self.Bp300 = makeBtn(self, "3. P300 Klassifizierung", "orange", self.btn_p300, tkinter.TOP)
  62. self.BvisCopy = makeBtn(self, "4. Freies Buchstabieren", "lightblue", self.btn_visCopy, tkinter.TOP)
  63. self.Btest = makeBtnSmall(self, "TEST", "green", self.btn_test, tkinter.TOP) # TODO Remove
  64. else:
  65. print('Fehler: Bitte wählen Sie "Tactile" oder "Visual" als Argument')
  66. raise ValueError
  67. # self.Bquest = makeBtnSmall(self, "6. Fragebogen", "green", self.btn_quest, TOP)
  68. self.BtacConfig = makeBtnSmall(self, "Konfiguration", "gray", self.btn_config, tkinter.TOP)
  69. frame.rowconfigure((0,1), weight=1) # make buttons stretch when
  70. frame.columnconfigure((0,2), weight=1) # when window is resized
  71. # TODO Hilfestellung nach jedem Button aufploppen lassen:
  72. # Was tun? Wo klicken? Welche File wo laden?
  73. # 1. FILTER ##################################
  74. def btn_filter(self):
  75. print('Starte TactileBCIFilter.exe')
  76. subprocess.Popen(config['PATH']['tactilebcifilter'] + '\TactileBCIFilter.exe')
  77. # 2. KALIBIERUNGEN ###########################
  78. def btn_tacCal(self):
  79. print('starte taktile Kalibrierung')
  80. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.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. # TODO Lock einführen und bei Returnwert Lock öffnen
  85. def btn_visCal(self):
  86. print('starte visuelle Kalibrierung')
  87. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_copySpeller.prm'])
  88. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  89. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  90. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  91. # 3. P300 Classifier #########################
  92. def btn_p300(self):
  93. print('Starte P300Classifier.exe')
  94. subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
  95. # 4. COPYSPELL ###########################
  96. def btn_tacCopy(self):
  97. print('Starte taktilen Speller')
  98. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCopy.prm'])
  99. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  100. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  101. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  102. def btn_visCopy(self):
  103. print('Starte visuellen Speller')
  104. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE gUSBamp_visual_freeSpeller.prm'])
  105. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
  106. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
  107. subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
  108. # 5. WHEELCHAIR SIMULATOR ###########################
  109. def btn_tacSimul(self):
  110. print('Starte Wheelchair Simulator')
  111. # TODO Starte Wheelchair Simulator Programm
  112. # subprocess.Popen([pathBci2000 + '\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileDrive.prm'])
  113. # subprocess.Popen([pathBci2000 + '\prog\gUSBampSource.exe', '127.0.0.1'])
  114. # subprocess.Popen([pathBci2000 + '\prog\P3SignalProcessing.exe', '127.0.0.1'])
  115. # subprocess.Popen([pathBci2000 + '\prog\P3Speller.exe', '127.0.0.1'])
  116. # QUESTIONNAIRE PROMPT ###########################
  117. # def btn_quest(self):
  118. #root.destroy()
  119. # self.startQuestions(self.paradigmText)
  120. # def startQuestions(self, para):
  121. # print('Starte Fragebogen')
  122. # q = quest(para)
  123. # q.qSatisfaction()
  124. # q.qExhaustion()
  125. # q.qSubjControl()
  126. # q.qCtrlChange()
  127. # q.save()
  128. # X. Settings #########################
  129. def btn_config(self):
  130. print('Konfiguration')
  131. 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.')
  132. config['PATH']['bci2000'] = tkinter.filedialog.askdirectory()
  133. tkinter.messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
  134. config['PATH']['tactilebcifilter'] = tkinter.filedialog.askdirectory()
  135. config.write(open('config.ini','w'))
  136. # TODO Catch errors falls falsche Ordner gewählt wurden
  137. def btn_test(self): # TODO Remove
  138. print('TEST')
  139. print(self.paradigmText)
  140. def global_close(self, window):
  141. print('Beenden')
  142. window.destroy()
  143. config = configparser.ConfigParser()
  144. root = tkinter.Tk()
  145. def on_closing():
  146. #self.global_close(root)
  147. print('Beenden')
  148. root.destroy()
  149. root.protocol("WM_DELETE_WINDOW", on_closing)
  150. app = App(root)
  151. root.mainloop()
  152. #root.destroy() # optional;