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

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