diff --git a/sounds/keyboardclick1.mp3 b/sounds/keyboardclick1.mp3 new file mode 100644 index 0000000..9fe2644 Binary files /dev/null and b/sounds/keyboardclick1.mp3 differ diff --git a/sounds/keyboardclick2.wav b/sounds/keyboardclick2.wav new file mode 100644 index 0000000..64aea2a Binary files /dev/null and b/sounds/keyboardclick2.wav differ diff --git a/sounds/keyboardclick3.wav b/sounds/keyboardclick3.wav new file mode 100644 index 0000000..555f000 Binary files /dev/null and b/sounds/keyboardclick3.wav differ diff --git a/src/main.py b/src/main.py index a8d8349..0cd093c 100644 --- a/src/main.py +++ b/src/main.py @@ -13,6 +13,22 @@ from tkinter import ttk from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg) +from pygame import mixer +import os +import platform + +if(platform.system() == "Darwin"): + sounds = [os.path.abspath("sounds/keyboardclick1") + ".mp3", os.path.abspath("sounds/keyboardclick2") + ".wav", os.path.abspath("sounds/keyboardclick3") + ".wav"] +elif(platform.system() == "Windows"): + sounds = [os.path.abspath("sounds\keyboardclick1") + ".mp3", os.path.abspath("sounds\keyboardclick2") + ".wav", os.path.abspath("sounds\keyboardclick3") + ".wav"] +else: + sounds = [os.path.abspath("sounds\keyboardclick1") + ".mp3", os.path.abspath("sounds\keyboardclick2") + ".wav", os.path.abspath("sounds\keyboardclick3") + ".wav"] + +should_play = True +soundID = 0 + +mixer.init() +mixer.music.load(sounds[soundID]) class Window: def td(self, s): @@ -42,6 +58,8 @@ def choose_wd(self): def __init__(self): self.stop_threads = False + self.soundID = soundID + self.window = Tk() self.window.title('py-typer') self.window.configure(background="gray25") @@ -60,11 +78,12 @@ def __init__(self): self.setup() - def clear(self): + def clear(self): for widget in self.window.winfo_children(): widget.destroy() def setup(self): + self.mixer_init() self.x=[] self.y=[] @@ -116,8 +135,11 @@ def restart(self): self.stop_threads = False self.clear() self.setup() + self.mixer_init() def plot_graph(self): + self.mixer_uninit() + self.fig = Figure(figsize = (3, 2), dpi = 100) self.fig.clf() plot1 = self.fig.add_subplot() @@ -136,19 +158,25 @@ def plot_graph(self): def main_menu(self): self.clear() + self.mixer_uninit() results_label = Label(self.window, text=self.wpm + " " + self.accuracy, font=("roboto", 50, "bold"), background="gray25", fg="#ebc934") results_label.grid(row=1, column=0) restart_button = Button(self.window, text="Restart", font=("roboto", 30), background="gray25", command=self.restart, highlightbackground="gray25", fg="#ebc934") restart_button.grid(row=2, column=0) - + + change_sound_button = Button(self.window, text="Sound", font=("roboto", 30), background="gray25", command=self.change_sound, highlightbackground="gray25", fg="#ebc934") + change_sound_button.grid(row=2, column=1) + mode_button = Button(self.window, text="Mode", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", bg="gray25", command=self.modes) mode_button.grid(row=2, column=2) self.plot_graph() def key_press(self, event): + self.play_sound() + if not self.write_able: return None if event.keysym == "Shift_L" or event.keysym == "Shift_R": @@ -169,6 +197,34 @@ def key_press(self, event): self.calculate_accuracy() except TclError: pass + + def mixer_uninit(self): + mixer.quit() + should_play = False + + def mixer_init(self): + mixer.init() + mixer.music.load(sounds[self.soundID]) + should_play = True + + def change_sound(self): + if(self.soundID == len(sounds) - 1): + self.soundID = 0 + else: + self.soundID += 1 + + print(self.soundID) + + mixer.init() + mixer.music.load(sounds[self.soundID]) + + self.play_sound() + + + def play_sound(self): + if(should_play): + mixer.music.play() + def start_timer(self): self.timer_thread = threading.Thread(target=self.countdown_thread) self.timer_thread.daemon = True