From 3a56bacebe8c36f539cebf3a55ad75be7d71db80 Mon Sep 17 00:00:00 2001 From: seyffejn <55194230+seyffejn@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:51:12 +0200 Subject: [PATCH] GUI upate Feedback Funktion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unterer rechter Labelframe hinzugefügt Die feedback Hilfsfunktion implemnentiert Mehrere Funktionen mit Feedback aufrufen versehen um dem Patienten zu erklären was abgeht (quasi ein Sprachroch für uns als Entwickler zum Benutzer) --- .gitignore | 5 + TinnitusAnalyse/.idea/dictionaries/Julian.xml | 4 + TinnitusAnalyse/.idea/workspace.xml | 85 +++++--------- TinnitusAnalyse/SoundGenerator.py | 3 +- TinnitusAnalyse/TinnitusAnalyse_GUI.py | 109 ++++++++++++------ TinnitusAnalyse/TinnitusDaten.csv | 8 +- .../__pycache__/SoundGenerator.cpython-35.pyc | Bin 4192 -> 4199 bytes 7 files changed, 121 insertions(+), 93 deletions(-) diff --git a/.gitignore b/.gitignore index eb8ebaa..3d486d3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ TinnitusAnalyse/sound.wav *.xml TinnitusAnalyse/.idea/workspace.xml TinnitusAnalyse/__pycache__/SoundGenerator.cpython-35.pyc +TinnitusAnalyse/MeinTinnitus.wav +*.xml +*.pyc +TinnitusAnalyse/.idea/dictionaries/Julian.xml +*.csv diff --git a/TinnitusAnalyse/.idea/dictionaries/Julian.xml b/TinnitusAnalyse/.idea/dictionaries/Julian.xml index 4a62725..6836398 100644 --- a/TinnitusAnalyse/.idea/dictionaries/Julian.xml +++ b/TinnitusAnalyse/.idea/dictionaries/Julian.xml @@ -2,11 +2,14 @@ audioausgabe + backgroundcolor bandbreite beide beiden definieren + fontcolor frequenz + kommentar kommentare lautstaerke lautstärke @@ -25,6 +28,7 @@ rechter rechtes rechts + speichere speicherversuch variablen vorname diff --git a/TinnitusAnalyse/.idea/workspace.xml b/TinnitusAnalyse/.idea/workspace.xml index 67546c9..c84cd3e 100644 --- a/TinnitusAnalyse/.idea/workspace.xml +++ b/TinnitusAnalyse/.idea/workspace.xml @@ -2,9 +2,8 @@ - + - @@ -17,11 +16,11 @@ - + - - + + @@ -32,17 +31,17 @@ - + - + - - + + @@ -93,6 +92,10 @@ Sound( 700 nachname + 400 + 500 + Text + name C:\Users\Julian\PycharmProjects\TinnitusAnalyse @@ -287,8 +290,8 @@ - - + + @@ -325,13 +328,9 @@ - - - - - - - + + + @@ -346,52 +345,32 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/TinnitusAnalyse/SoundGenerator.py b/TinnitusAnalyse/SoundGenerator.py index 4e6d132..d0d6a9f 100644 --- a/TinnitusAnalyse/SoundGenerator.py +++ b/TinnitusAnalyse/SoundGenerator.py @@ -49,7 +49,7 @@ Sound beinhaltet alle Variablen, die zum erstellen einer .wav-Datei benötigt we class Sound: - def __init__(self, tinnitus, name="sound.wav", audio=None, nchannels=1, sampwidth=2, framerate=44100, + def __init__(self, tinnitus, name="MeinTinnitus.wav", audio=None, nchannels=1, sampwidth=2, framerate=44100, comptype="NONE", compname="not compressed", mute=True): if audio is None: audio = [] @@ -70,7 +70,6 @@ class Sound: def wav_speichern(self): # ezeugt/aktuallisiert die .wav-Datei wav_file = wave.open(self.name, "w") print("Sound wird als .wav-Datei gespeichert. Bitte warten...\nDer Vorgang kann ca. 30 Sekunden dauern") - # zuerst muss ein Array mit Audiodaten gefüllt werden audio = [] freq = self.tinnitus.linksFrequenz diff --git a/TinnitusAnalyse/TinnitusAnalyse_GUI.py b/TinnitusAnalyse/TinnitusAnalyse_GUI.py index 0a33b5a..f7be87d 100644 --- a/TinnitusAnalyse/TinnitusAnalyse_GUI.py +++ b/TinnitusAnalyse/TinnitusAnalyse_GUI.py @@ -2,7 +2,7 @@ from tkinter.ttk import Frame, Label, Button, LabelFrame, Combobox, Style, Check from tkinter import * from SoundGenerator import * import csv - +import time """--------------------------FUNKTIONEN DIE DURCH GUI KLICKS AUSGEFÃœHRT WERDEN---------------------------------------""" """-------Funktionen links-------------""" @@ -75,7 +75,7 @@ def rechts_scale_rauschen_bandbreite_change(self): def unten_button_ohren_synchro(): - auswahl = untenComboOhrenSynchro.get() # holt die momentane Auswahl aus combobox + auswahl = untenComboOhrenSynchro.get() # holt die momentane Auswahl aus combobox print("Einstellungen von:" + auswahl + " das auf das jeweils andere Ohr setzen") if auswahl == "Linkes Ohr": # linkes --> rechts @@ -84,6 +84,7 @@ def unten_button_ohren_synchro(): rechtsScaleRauschenLautstärke.set(linksScaleRauschenLautstärke.get()) rechtsScaleRauschenMittelFrequenz.set(linksScaleRauschenMittelFrequenz.get()) rechtsScaleRauschenBandbreite.set(linksScaleRauschenBandbreite.get()) + feedback("Einstellungen vom linken Ohr auf beide Ohren übertragen", "white", "blue") if auswahl == "Rechtes Ohr": # rechts --> links linksScaleLautstärke.set(rechtsScaleLautstärke.get()) @@ -91,6 +92,7 @@ def unten_button_ohren_synchro(): linksScaleRauschenLautstärke.set(rechtsScaleRauschenLautstärke.get()) linksScaleRauschenMittelFrequenz.set(rechtsScaleRauschenMittelFrequenz.get()) linksScaleRauschenBandbreite.set(rechtsScaleRauschenBandbreite.get()) + feedback("Einstellungen vom rechten Ohr auf beide Ohren übertragen", "white", "blue") def unten_button_speichern_press(): @@ -101,40 +103,68 @@ def unten_button_speichern_press(): nachname.set("Erst Namen..") vorname.set("..eintragen bitte") print("fehlgeschlagener Speicherversuch - Keine Eingaben gemacht") + feedback("Fehlgeschlagener Speicherversuch! Mögliche Gründe: Erst Namen links eintragen.", "yellow", "red") + feedback("Falls es danach immer noch nicht geht, bitte Microsoft Excel schließen.", "yellow", "red") else: - tinnitus.vorname = untenEntryVorname.get() - tinnitus.nachname = untenEntryNachname.get() - tinnitus.kommentar = untenTextKommentar.get("1.0", END) - print("Speichere Patientendaten, siehe TinnitusDaten.csv") - tinnitus.speichern() - sound.wav_speichern() + try: + feedback("Speichere Sound als .wav Datei . Kann bis zu 30 Sekunden dauern. Bitte warten...", "white", "blue") + # todo: warum auch immer, aber irgendwie wird feedback nach wav_speichern ausgeführt + tinnitus.vorname = untenEntryVorname.get() + tinnitus.nachname = untenEntryNachname.get() + tinnitus.kommentar = untenTextKommentar.get("1.0", END) + tinnitus.speichern() + sound.wav_speichern() + feedback("Daten erfolgreich gespeichert. Siehe: 'MeinTinnitus.wav' ", "white", "blue") + except: + feedback("Fehlgeschlagener Speicherversuch! Mögliche Gründe: Erst Namen links eintragen.", "yellow", "red") + feedback("Falls es danach immer noch nicht geht, bitte Microsoft Excel schließen.", "yellow", "red") def unten_button_play_press(): - print("button play pressed -> mute=false") - sound.mute = False + print("button play pressed") + feedback("Starte Audioausgabe...", "white", "green") + sound.mute = False # when this boolean is set to false no audio can ever play (it`s like a savety switch) sound.play() + def unten_button_stop_press(): - print("button stop press -> mute=true") + print("button stop press") + feedback("Stoppe Audioausgabe", "white", "red") # place text in feedback field, fontcololor, backgroundcolor sound.mute = True sound.stop() -"""""" -tinnitus = Tinnitus() -sound = Sound(tinnitus) -print("test") +def feedback(text, fontcolor, backgroundcolor): + """ This is a helper function. You can give it a string text and it will display it in the feedback frame (bottom + right of the GUI) in the text widget. The parameter color is also a string and defines the font color. Same with + background. Honestly this function is way too complicated, but Tkinter has no nicer/easier builtin way of doing the + coloring nicely """ + feedback.lineCounter += 1 # in order to color the texts nicely we need to count the lines of text we add + untenFeedbackText.config(state=NORMAL) # activate text field (otherwise it is readonly) + + if feedback.lineCounter == 12: # if we reached the end of the text box + untenFeedbackText.delete("1.0", END) # just delete everything + feedback.lineCounter = 1 # and start at line 1 again + + untenFeedbackText.insert(INSERT, text + "\n") # insert the text + # these 2 lines just color the text nicely, but Tkinter forces your to first "tag_add" mark it and specify the + # line number and char number you want to mark. And then "tag_config" change the color of this marked region + untenFeedbackText.tag_add("Line"+str(feedback.lineCounter), str(feedback.lineCounter)+".0", str(float(len(text)))) + untenFeedbackText.tag_config("Line"+str(feedback.lineCounter), foreground=fontcolor, background=backgroundcolor) + + untenFeedbackText.config(state=DISABLED) # set the text field back to readonly + + +""" Initialisierungen """ +tinnitus = Tinnitus() # siehe SoundGenerator.py +sound = Sound(tinnitus) # siehe SoundGenerator.py +feedback.lineCounter = 0 # Funktionsvariable der Feedback funktion. Ein Funktionsaufruf Counter """------------------------------------------ AUFBAU DES ROOT WINDOWS -----------------------------------------------""" root = Tk() # build the main window root.title("Tinnitus Analyse") -#root.iconbitmap('headphones.ico') #todo: fix icon -root.minsize(width=800, height=500) -root.resizable(True, True) -root.columnconfigure(0, weight=1) -root.columnconfigure(1, weight=1) -root.rowconfigure(0, weight=1) +root.minsize(width=800, height=500) # set windowsize (width an height in pixels) +root.resizable(False, False) # window not resizable (x and y) """------------------------------------------LINKER FRAME------------------------------------------------------------""" @@ -150,14 +180,14 @@ linksRauschenFrequenzband = DoubleVar() # ------------------ LAUTSTÄRKE ------------------ linksLabelLautstärke = Label(linkerFrame, text="Lautstärke [%]:") linksLabelLautstärke.grid(column=0, row=0, sticky=W) -linksScaleLautstärke = Scale(linkerFrame, from_=0, to=100, orient=HORIZONTAL, length=400, +linksScaleLautstärke = Scale(linkerFrame, from_=0, to=100, orient=HORIZONTAL, length=600, command=links_scale_lautstärke_change) linksScaleLautstärke.grid(column=1, row=0, sticky=N+S+W+E) # -------- FREQUENZ ------------------------ linksLabelFrequenz = Label(linkerFrame, text="Frequenz [kHz]") linksLabelFrequenz.grid(column=0, row=1, sticky=W) # sticky = w(est) makes the text left aligned -linksScaleFrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +linksScaleFrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=links_scale_frequenz_change) linksScaleFrequenz.grid(column=1, row=1, sticky=(W+E)) @@ -168,26 +198,26 @@ linksSeparator.grid(column=0, row=2, sticky=(W + E), columnspan=3) # ----------- RAUSCHEN -------------------- linksLabelRauschenLautstärke = Label(linkerFrame, text="Rauschen Lautstärke %", anchor="w") linksLabelRauschenLautstärke.grid(column=0, row=3, sticky=W) -linksScaleRauschenLautstärke = Scale(linkerFrame, from_=0, to=100, orient=HORIZONTAL, length=400, +linksScaleRauschenLautstärke = Scale(linkerFrame, from_=0, to=100, orient=HORIZONTAL, length=600, command=links_scale_rauschen_lautstärke_change) linksScaleRauschenLautstärke.grid(column=1, row=3, sticky=(W+E)) linksLabelRauschenMittelFrequenz = Label(linkerFrame, text="Rauschen Mittelfrequenz [kHz]", anchor="w") linksLabelRauschenMittelFrequenz .grid(column=0, row=4, sticky=(W+E)) -linksScaleRauschenMittelFrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +linksScaleRauschenMittelFrequenz = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=links_scale_rauschen_mittelfrequenz_change) linksScaleRauschenMittelFrequenz.grid(column=1, row=4, sticky=(W+E)) linksLabelRauschenBandbreite= Label(linkerFrame, text="Rauschen Bandbreite [kHz]", anchor="w") linksLabelRauschenBandbreite.grid(column=0, row=5, sticky=W) -linksScaleRauschenBandbreite = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +linksScaleRauschenBandbreite = Scale(linkerFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=links_scale_rauschen_bandbreite_change) linksScaleRauschenBandbreite.grid(column=1, row=5, sticky=(W+E)) """----------------------------------------------RECHTER FRAME-------------------------------------------------------""" rechterFrame = LabelFrame(root, text="Rechtes Ohr", font="bold") -rechterFrame.grid(column=2, row=0, sticky=(N+E+W+S)) +rechterFrame.grid(column=1, row=0, sticky=(N+E+W+S)) # Variablen Rechts @@ -199,14 +229,14 @@ rechtsLautstärke = DoubleVar() # ------------------ LAUTSTÄRKE ------------------ rechtsLabelLautstärke = Label(rechterFrame, text="Lautstärke [%]:") rechtsLabelLautstärke.grid(column=0, row=0, sticky=W) -rechtsScaleLautstärke = Scale(rechterFrame, from_=0, to=100, orient=HORIZONTAL, length=400, +rechtsScaleLautstärke = Scale(rechterFrame, from_=0, to=100, orient=HORIZONTAL, length=600, command=rechts_scale_lautstärke_change) rechtsScaleLautstärke.grid(column=1, row=0, columnspan=10, sticky=W) # -------- FREQUENZ ------------------------ rechtsLabelFrequenz = Label(rechterFrame, text="Frequenz [kHz]") rechtsLabelFrequenz.grid(column=0, row=1, sticky=W) # sticky = w(est) makes the text left aligned -rechtsScaleFrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +rechtsScaleFrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=rechts_scale_frequenz_change) rechtsScaleFrequenz.grid(column=1, row=1, columnspan=10, sticky=(W+E)) @@ -217,26 +247,26 @@ rechtsSeparator.grid(column=0, row=2, columnspan=10, sticky=(W + E)) # ----------- RAUSCHEN -------------------- rechtsLabelRauschenLautstärke = Label(rechterFrame, text="Rauschen Lautstärke %", anchor="w") rechtsLabelRauschenLautstärke.grid(column=0, row=3, sticky=W) -rechtsScaleRauschenLautstärke = Scale(rechterFrame, from_=0, to=100, orient=HORIZONTAL, length=400, +rechtsScaleRauschenLautstärke = Scale(rechterFrame, from_=0, to=100, orient=HORIZONTAL, length=600, command=rechts_scale_rauschen_lautstärke_change) rechtsScaleRauschenLautstärke.grid(column=1, row=3, sticky=(W+E)) rechtsLabelRauschenMittelFrequenz = Label(rechterFrame, text="Rauschen Mittelfrequenz [kHz]", anchor="w") rechtsLabelRauschenMittelFrequenz .grid(column=0, row=4) -rechtsScaleRauschenMittelFrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +rechtsScaleRauschenMittelFrequenz = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=rechts_scale_rauschen_mittelfrequenz_change) rechtsScaleRauschenMittelFrequenz.grid(column=1, row=4) rechtsLabelRauschenBandbreite = Label(rechterFrame, text="Rauschen Bandbreite [kHz]", anchor="w") rechtsLabelRauschenBandbreite.grid(column=0, row=5, sticky=W) -rechtsScaleRauschenBandbreite = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=400, resolution=-1.0, +rechtsScaleRauschenBandbreite = Scale(rechterFrame, from_=0, to=20, orient=HORIZONTAL, length=600, resolution=-1.0, command=rechts_scale_rauschen_bandbreite_change) rechtsScaleRauschenBandbreite.grid(column=1, row=5, sticky=(W+E)) -"""------------------------------------------------ UNTERER FRAME----------------------------------------------------""" +"""------------------------------------------------ UNTERER LINKER FRAME---------------------------------------------""" untererFrame = LabelFrame(root, text="Generelles", border=10) -untererFrame.grid(column=0, row=1, sticky=(N + W + S), columnspan=2) +untererFrame.grid(column=0, row=1, sticky=(N + W + S + E)) vorname = StringVar() # Name des Patienten als String um den generierten Tinnitus später zuordnen zu können nachname = StringVar() @@ -293,6 +323,17 @@ untenButtonSpeichern = Button(untererFrame, text="Speichern", font="bold", untenButtonSpeichern.grid(column=4, row=6, sticky=S) +"""--------------------------------------UNTERER RECHTER FRAME-------------------------------------------------------""" + +untererRechterFrame = LabelFrame(root, text="Programm Feedback") +untererRechterFrame.grid(row=1, column=1, sticky=(N+S+E+W)) + + +# ------------ PROGRAMM OUTPUT ------------ +untenFeedbackText = Text(untererRechterFrame, height=13, width=85, bg="lightblue") # write feedback to patient here +#untenFeedbackText.config(state=DISABLED) # make the text widget readonly +untenFeedbackText.place(relx=.5, rely=.5, anchor="center") # the only time I used .place instead of grid, because it +# lets me place the widget in the middle of the frame diff --git a/TinnitusAnalyse/TinnitusDaten.csv b/TinnitusAnalyse/TinnitusDaten.csv index 13b0f2c..797cfa5 100644 --- a/TinnitusAnalyse/TinnitusDaten.csv +++ b/TinnitusAnalyse/TinnitusDaten.csv @@ -1,7 +1,7 @@ -Vorname;asdas -Nachname;asda -linke Frequenz;1410.0 -linke Lautstärke;0.03 +Vorname;asdad +Nachname;sada +linke Frequenz;0.0 +linke Lautstärke;0.0 linkes Rauschen;0.0 rechte Frequenz;0.0 rechte Lautstärke;0.0 diff --git a/TinnitusAnalyse/__pycache__/SoundGenerator.cpython-35.pyc b/TinnitusAnalyse/__pycache__/SoundGenerator.cpython-35.pyc index 1af9cd58767427b35bcdfe666375469de824513e..436feb66a95875820efc1d8c924e57f72110be19 100644 GIT binary patch delta 68 zcmaE$@LYjYoR^pDP5bLO;f0*60ao_W8vf&{&q&i$xrxe02VzKP5=M^ delta 61 zcmV-D0K)(0AmAVg7Yz*x{U7RH4zUS)1_lXpZ*^{Dvyldj1pxz-9t@iSXp_1OZUJnw TDGfOS0dkXL4~GFFlj{$BT`m(;