From 139b511a4124540a2d5f51c4d83a66d30ff6cbce Mon Sep 17 00:00:00 2001 From: greninja Date: Fri, 18 Oct 2024 23:08:20 +0530 Subject: [PATCH 1/2] 1st draft --- src/main.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index a8d8349..fc4b25e 100644 --- a/src/main.py +++ b/src/main.py @@ -136,8 +136,7 @@ def plot_graph(self): def main_menu(self): self.clear() - - results_label = Label(self.window, text=self.wpm + " " + self.accuracy, font=("roboto", 50, "bold"), background="gray25", fg="#ebc934") + results_label = Label(self.window, text=str(self.wpm) + " WPM " + str(self.accuracy) + "% 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") @@ -190,6 +189,80 @@ def countdown_thread(self): self.stop_threads = True self.main_menu() + def difficult_mode_zen(self): + self.clear() + self.word_difficulty = 3 # Assuming word difficulty is set to hard or you can set custom logic + self.write_able = True + self.start_time = time.time() + self.stop_threads = False + self.setup_zen_mode() + + def setup_zen_mode(self): + self.x = [] + self.y = [] + + self.misspelled = 0 + self.spelled = 0 + self.accuracy = 0 + self.wpm = 0 + self.write_able = True + + if self.word_difficulty == 3: + text = text_module.hard # Example text source + else: + text = text_module.freestyle # Freestyle or hard mode, adjust as needed + + self.untyped_text = Label(self.window, text=text, font=("roboto condensed", 61), background="gray25", fg="gray60") + self.untyped_text.place(relx=0.5, rely=0.5, anchor=W) + + self.typed_text = Label(self.window, text="", font=("roboto condensed", 61), fg="#ebc934", background="gray25") + self.typed_text.place(relx=0.5, rely=0.5, anchor=E) + + self.accuracy_label = Label(self.window, text=self.accuracy, font=("roboto condensed", 30), fg="#ebc934", background="gray25") + self.accuracy_label.grid(row=1, column=3, sticky=S) + + self.wpm_label = Label(self.window, text=self.wpm, font=("roboto condensed", 30), fg="#ebc934", background="gray25") + self.wpm_label.grid(row=1, column=4, sticky=S) + + self.cursor_label = Label(self.window, text="||", background="gray25", fg="gray60", font=("roboto", 20), wraplength=1) + self.cursor_label.place(relx=0.499, rely=0.51, anchor=CENTER) + + self.cursor_blinking() + + self.window.bind('', self.key_press_zen) + + def key_press_zen(self, event): + if not self.write_able: + return None + if event.keysym == "Shift_L" or event.keysym == "Shift_R": + return None + if event.keysym == "Return" and event.state & 0x0001: # Shift + Enter detection + self.write_able = False + self.calculate_final_wpm() + self.main_menu() + return + try: + if event.char == self.untyped_text.cget('text')[:1]: + self.typed_text.configure(text=self.typed_text.cget('text') + event.char) + self.untyped_text.configure(text=self.untyped_text.cget('text')[1:]) + self.spelled += 1 + if len(self.untyped_text.cget('text')) < 1: + self.clear() + self.main_menu() + else: + self.misspelled += 1 + self.calculate_accuracy() + except TclError: + pass + + def calculate_final_wpm(self): + end_time = time.time() + elapsed_time = end_time - self.start_time + words_typed = len(self.typed_text.cget('text').split()) + self.wpm = int((words_typed / elapsed_time) * 60) + self.wpm_label.configure(text=str(self.wpm) + " WPM") + self.calculate_accuracy() + def calculate_accuracy(self): self.accuracy = str(int((self.spelled / (self.spelled + self.misspelled)) * 100)) + "%" try: @@ -209,11 +282,13 @@ def calculate_wpm(self): except TclError: pass self.window.after(1000, self.calculate_wpm) + def modes(self): self.clear() Button(self.window, text="Time Difficulty", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.choose_td).place(rely=0.4, relx=0.5, anchor=CENTER) Button(self.window, text="Word Difficulty", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.choose_wd).place(rely=0.6, relx=0.5, anchor=CENTER) + Button(self.window, text="Difficult Mode Zen", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.difficult_mode_zen).place(rely=0.7, relx=0.5, anchor=CENTER) def cursor_blinking(self): if self.cursor_blink: From 44a75a0cbb8adab8ab01e39847eba8bca57fc8bc Mon Sep 17 00:00:00 2001 From: greninja Date: Sat, 19 Oct 2024 00:22:38 +0530 Subject: [PATCH 2/2] 2nd draft I have the graph left --- src/main.py | 143 +++++++++++++++++++++------------------------------- 1 file changed, 58 insertions(+), 85 deletions(-) diff --git a/src/main.py b/src/main.py index fc4b25e..bf4d10f 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,3 @@ -# Creating a typing test tool that measures users typing speed and accuracy, providing an entertaining way to improve keyboard skills. -# author: PES2UG23CS368 Nathan Matthew Paul -# author: PES2UG23CS371 Navneet Nayak -# author: PES2UG23CS381 Nevin Mathew Thomas -# author: PES2UG23CS390 Nilay Srivastava -# SPDX-License-Identifier: GPL-3.0-or-later -# Copyright (C) 2023 - import time import threading import text_module @@ -136,17 +128,65 @@ def plot_graph(self): def main_menu(self): self.clear() - results_label = Label(self.window, text=str(self.wpm) + " WPM " + str(self.accuracy) + "% Accuracy", font=("roboto", 50, "bold"), background="gray25", fg="#ebc934") + + 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) + zen_button = Button(self.window, text="Zen Mode", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.zen_mode) + zen_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 zen_mode(self): + self.clear() # Clear previous UI elements + + self.write_able = True + self.spelled = 0 + self.misspelled = 0 + self.time_label = Label(self.window, text="Zen Mode: Type!", font=("roboto condensed", 30), fg="#ebc934", background="gray25") + self.time_label.place(relx=0.5, rely=0.2, anchor=CENTER) + + # Create a text entry area for the user + self.typed_text = Label(self.window, text="", font=("roboto condensed", 30), fg="#ebc934", background="gray25") + self.typed_text.place(relx=0.5, rely=0.5, anchor=CENTER) + + # Initialize WPM tracking + self.x = [] # Reset the x data for plotting + self.y = [] # Reset the y data for plotting + self.start_time = time.time() # Start time for WPM calculation + self.window.bind('', self.zen_key_press) + # Bind Shift + Enter to exit Zen Mode + self.window.bind('', self.exit_zen_mode) + self.window.after(1000, self.calculate_zen_wpm) # Start calculating WPM after 1 second + + def calculate_zen_wpm(self): + if self.write_able: + elapsed_time = time.time() - self.start_time # Calculate elapsed time + words_typed = len(self.typed_text.cget('text').split()) + wpm = int((words_typed / elapsed_time) * 60) if elapsed_time > 0 else 0 + + self.x.append(elapsed_time) # Append elapsed time to x + self.y.append(wpm) # Append WPM to y + + self.window.after(1000, self.calculate_zen_wpm) # Recalculate every second + + def zen_key_press(self, event): + if self.write_able and event.char: # Check if a character was pressed + self.typed_text.configure(text=self.typed_text.cget('text') + event.char) + self.spelled += 1 # Increment spelled words (if necessary) + + def exit_zen_mode(self, event): + self.write_able = False # Stop writing + self.main_menu() # Go back to the main menu or wherever you want to go + self.plot_graph() # Call the graph plotting function + + def key_press(self, event): if not self.write_able: return None @@ -168,6 +208,8 @@ def key_press(self, event): self.calculate_accuracy() except TclError: pass + + def start_timer(self): self.timer_thread = threading.Thread(target=self.countdown_thread) self.timer_thread.daemon = True @@ -189,80 +231,6 @@ def countdown_thread(self): self.stop_threads = True self.main_menu() - def difficult_mode_zen(self): - self.clear() - self.word_difficulty = 3 # Assuming word difficulty is set to hard or you can set custom logic - self.write_able = True - self.start_time = time.time() - self.stop_threads = False - self.setup_zen_mode() - - def setup_zen_mode(self): - self.x = [] - self.y = [] - - self.misspelled = 0 - self.spelled = 0 - self.accuracy = 0 - self.wpm = 0 - self.write_able = True - - if self.word_difficulty == 3: - text = text_module.hard # Example text source - else: - text = text_module.freestyle # Freestyle or hard mode, adjust as needed - - self.untyped_text = Label(self.window, text=text, font=("roboto condensed", 61), background="gray25", fg="gray60") - self.untyped_text.place(relx=0.5, rely=0.5, anchor=W) - - self.typed_text = Label(self.window, text="", font=("roboto condensed", 61), fg="#ebc934", background="gray25") - self.typed_text.place(relx=0.5, rely=0.5, anchor=E) - - self.accuracy_label = Label(self.window, text=self.accuracy, font=("roboto condensed", 30), fg="#ebc934", background="gray25") - self.accuracy_label.grid(row=1, column=3, sticky=S) - - self.wpm_label = Label(self.window, text=self.wpm, font=("roboto condensed", 30), fg="#ebc934", background="gray25") - self.wpm_label.grid(row=1, column=4, sticky=S) - - self.cursor_label = Label(self.window, text="||", background="gray25", fg="gray60", font=("roboto", 20), wraplength=1) - self.cursor_label.place(relx=0.499, rely=0.51, anchor=CENTER) - - self.cursor_blinking() - - self.window.bind('', self.key_press_zen) - - def key_press_zen(self, event): - if not self.write_able: - return None - if event.keysym == "Shift_L" or event.keysym == "Shift_R": - return None - if event.keysym == "Return" and event.state & 0x0001: # Shift + Enter detection - self.write_able = False - self.calculate_final_wpm() - self.main_menu() - return - try: - if event.char == self.untyped_text.cget('text')[:1]: - self.typed_text.configure(text=self.typed_text.cget('text') + event.char) - self.untyped_text.configure(text=self.untyped_text.cget('text')[1:]) - self.spelled += 1 - if len(self.untyped_text.cget('text')) < 1: - self.clear() - self.main_menu() - else: - self.misspelled += 1 - self.calculate_accuracy() - except TclError: - pass - - def calculate_final_wpm(self): - end_time = time.time() - elapsed_time = end_time - self.start_time - words_typed = len(self.typed_text.cget('text').split()) - self.wpm = int((words_typed / elapsed_time) * 60) - self.wpm_label.configure(text=str(self.wpm) + " WPM") - self.calculate_accuracy() - def calculate_accuracy(self): self.accuracy = str(int((self.spelled / (self.spelled + self.misspelled)) * 100)) + "%" try: @@ -283,12 +251,17 @@ def calculate_wpm(self): pass self.window.after(1000, self.calculate_wpm) + def end_zen_mode(self, event): + self.write_able = False # Disable typing + self.stop_threads = True # Stop any running threads + self.plot_graph() # Plot graph of WPM vs time after exiting Zen Mode + self.main_menu() # Go back to the main menu def modes(self): self.clear() Button(self.window, text="Time Difficulty", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.choose_td).place(rely=0.4, relx=0.5, anchor=CENTER) Button(self.window, text="Word Difficulty", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.choose_wd).place(rely=0.6, relx=0.5, anchor=CENTER) - Button(self.window, text="Difficult Mode Zen", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.difficult_mode_zen).place(rely=0.7, relx=0.5, anchor=CENTER) + Button(self.window, text="Zen Mode", font=("roboto", 30), highlightbackground="gray25", fg="#ebc934", background="gray25", command=self.start_zen_mode).place(rely=0.8, relx=0.5, anchor=CENTER) def cursor_blinking(self): if self.cursor_blink: @@ -306,4 +279,4 @@ def cursor_blinking(self): self.window.after(500, self.cursor_blinking) window = Window() -window.window.mainloop() +window.window.mainloop() \ No newline at end of file