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

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