pythonbcigui/app.py

152 lines
6.2 KiB
Python
Raw Normal View History

2020-09-04 12:16:57 +02:00
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 4 11:36:24 2020
2020-09-04 14:02:12 +02:00
@author: Igor Beloschapkin
2020-09-04 12:16:57 +02:00
"""
2020-09-04 13:06:21 +02:00
from tkinter import *
import tkinter.font as tkFont
2020-09-04 14:02:12 +02:00
import subprocess
2020-09-04 15:06:04 +02:00
import configparser
2020-09-04 12:16:57 +02:00
# own code:
# from questionnaire import quest
2020-09-04 14:48:10 +02:00
# TODO Eventuell updatefunktion über git pull mit einbauen!
2020-09-04 12:16:57 +02:00
class App:
def __init__(self, master):
2020-09-04 13:06:21 +02:00
# self.paradigmText = sys.argv[1]
# App.paradigmText = sys.argv[1]
# print sys.argv[1]
# pathOrigin = os.path.dirname(os.path.realpath(__file__))
2020-09-04 14:02:12 +02:00
# TODO current working directory auf root von dieser file setzen
2020-09-04 13:06:21 +02:00
# global pathSave
# pathSave = "\\questions\\" + self.paradigmText
# pathSave = os.getcwd() + pathSave
2020-09-04 15:27:03 +02:00
config.read('config.ini')
2020-09-04 12:16:57 +02:00
2020-09-04 14:02:12 +02:00
# Einstellung der GUI Größe
textH = 4
2020-09-04 15:27:03 +02:00
textHsmall = 2
2020-09-04 14:02:12 +02:00
textW = 20
2020-09-04 13:06:21 +02:00
2020-09-04 12:16:57 +02:00
def makeBtn(self, text, bg, command, side):
self.button = Button(frame, text=text, bg=bg, command=command)
self.button.config( height = textH, width = textW )
2020-09-04 15:27:03 +02:00
self.button['font'] = tkFont.Font(family='Helvetica', size=16, weight='bold')
2020-09-04 12:16:57 +02:00
self.button.pack(side=side)
return self.button
def makeBtnSmall(self, text, bg, command, side):
self.button = Button(frame, text=text, bg=bg, command=command)
self.button.config( height = textHsmall, width = textW )
self.button['font'] = tkFont.Font(family='Helvetica', size=16, weight='bold')
2020-09-04 13:06:21 +02:00
self.button.pack(side=side)
return self.button
2020-09-04 12:16:57 +02:00
frame = Frame(master)
2020-09-04 13:06:21 +02:00
frame.pack()
2020-09-04 12:16:57 +02:00
# button generation
2020-09-04 15:27:03 +02:00
self.Bfilter = makeBtn(self, "1. Filter", "lightyellow", self.btn_filter, TOP)
self.BtacCal = makeBtn(self, "2. Kalibrierung", "lightgreen", self.btn_tacCal, TOP)
self.Bp300 = makeBtn(self, "3. P300 Klassifizierung", "orange", self.btn_p300, TOP)
self.BtacCopy = makeBtn(self, "4. Freies Buchstabieren", "lightblue", self.btn_tacCopy, TOP)
self.BtacSimul = makeBtn(self, "5. Rollstuhlsimulator", "pink", self.btn_tacSimul, TOP)
2020-09-04 14:48:10 +02:00
# self.BtacQuest = makeBtnSmall(self, "6. Fragebogen", "green", self.btn_tacQuest, TOP)
2020-09-04 15:59:50 +02:00
self.BtacConfig = makeBtnSmall(self, "Konfiguration", "gray", self.btn_config, TOP)
2020-09-04 12:16:57 +02:00
frame.rowconfigure((0,1), weight=1) # make buttons stretch when
frame.columnconfigure((0,2), weight=1) # when window is resized
2020-09-04 14:02:12 +02:00
# TODO Hilfestellung nach jedem Button aufploppen lassen:
# Was tun? Wo klicken? Welche File wo laden?
2020-09-04 13:06:21 +02:00
2020-09-04 12:16:57 +02:00
# 1. FILTER ##################################
2020-09-04 13:06:21 +02:00
def btn_filter(self):
2020-09-04 12:16:57 +02:00
print('Starte TactileBCIFilter.exe')
2020-09-04 15:59:50 +02:00
subprocess.Popen(config['PATH']['tactilebcifilter'] + '\TactileBCIFilter.exe')
2020-09-04 12:16:57 +02:00
# 2. KALIBIERUNGEN ###########################
def btn_tacCal(self):
2020-09-04 14:02:12 +02:00
print('starte taktile Kalibrierung')
2020-09-04 15:59:50 +02:00
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCalibration.prm'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
2020-09-04 14:02:12 +02:00
# TODO Lock einführen und bei Returnwert Lock öffnen
2020-09-04 12:16:57 +02:00
# 3. P300 Classifier #########################
def btn_p300(self):
2020-09-04 14:02:12 +02:00
print('Starte P300Classifier.exe')
2020-09-04 15:59:50 +02:00
subprocess.Popen(config['PATH']['bci2000'] + r'\tools\P300Classifier\P300Classifier.exe')
2020-09-04 12:16:57 +02:00
2020-09-04 14:48:10 +02:00
# 4. COPYSPELL ###########################
2020-09-04 12:16:57 +02:00
def btn_tacCopy(self):
2020-09-04 14:02:12 +02:00
print('Starte taktilen Copyspeller')
2020-09-04 15:59:50 +02:00
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileCopy.prm'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\gUSBampSource.exe', '127.0.0.1'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3SignalProcessing.exe', '127.0.0.1'])
subprocess.Popen([config['PATH']['bci2000'] + r'\prog\P3Speller.exe', '127.0.0.1'])
2020-09-04 14:48:10 +02:00
# 5. WHEELCHAIR SIMULATOR ###########################
def btn_tacSimul(self):
print('Starte Wheelchair Simulator')
# TODO Starte Wheelchair Simulator Programm
2020-09-04 15:27:03 +02:00
# subprocess.Popen([pathBci2000 + '\prog\Operator.exe', '--OnConnect', '-LOAD PARAMETERFILE TactileDrive.prm'])
# subprocess.Popen([pathBci2000 + '\prog\gUSBampSource.exe', '127.0.0.1'])
# subprocess.Popen([pathBci2000 + '\prog\P3SignalProcessing.exe', '127.0.0.1'])
# subprocess.Popen([pathBci2000 + '\prog\P3Speller.exe', '127.0.0.1'])
2020-09-04 12:16:57 +02:00
# QUESTIONNAIRE PROMPT ###########################
# def btn_visQuest(self):
# #os.system('python .\PythonBCIgui\q-helper.py ' + "Visual")
# root.destroy()
# self.startQuestions("Visual")
2020-09-04 14:02:12 +02:00
# def btn_tacQuest(self):
2020-09-04 14:48:10 +02:00
#root.destroy()
# self.startQuestions("Tactile")
2020-09-04 12:16:57 +02:00
# def btn_audQuest(self):
# root.destroy()
2020-09-04 13:06:21 +02:00
# self.startQuestions("Auditory")
2020-09-04 12:16:57 +02:00
2020-09-04 14:02:12 +02:00
# def startQuestions(self, para):
2020-09-04 14:48:10 +02:00
# print('Starte Fragebogen')
# q = quest(para)
# q.qSatisfaction()
# q.qExhaustion()
# q.qSubjControl()
# q.qCtrlChange()
# q.save()
# X. Settings #########################
2020-09-04 15:27:03 +02:00
def btn_config(self):
2020-09-04 15:59:50 +02:00
print('Konfiguration')
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.')
config['PATH']['bci2000'] = filedialog.askdirectory()
messagebox.showinfo('Konfiguration', 'Bitte wählen Sie nun den Ordner aus, in dem sich die TactileBCIfilter.exe befindet.')
config['PATH']['tactilebcifilter'] = filedialog.askdirectory()
config.write(open('config.ini','w'))
# TODO Catch errors falls falsche Ordner gewählt wurden
2020-09-04 12:16:57 +02:00
def global_close(self, window):
2020-09-04 14:02:12 +02:00
print('Beenden')
2020-09-04 13:06:21 +02:00
window.destroy()
2020-09-04 15:27:03 +02:00
config = configparser.ConfigParser()
2020-09-04 13:06:21 +02:00
root = Tk()
2020-09-04 12:16:57 +02:00
2020-09-04 13:06:21 +02:00
def on_closing():
#self.global_close(root)
2020-09-04 14:02:12 +02:00
print('Beenden')
2020-09-04 13:06:21 +02:00
root.destroy()
2020-09-04 12:16:57 +02:00
root.protocol("WM_DELETE_WINDOW", on_closing)
app = App(root)
root.mainloop()
#root.destroy() # optional;