diff --git a/code/diacritics_fix.py b/code/diacritics_fix.py index 7b28edd..5ab461a 100644 --- a/code/diacritics_fix.py +++ b/code/diacritics_fix.py @@ -6,12 +6,18 @@ REMEDIED_CHARS = {ord(c): c for c in 'ĂăÂâÎîȘșTtȚțEeÉéÈèÊêËëIiÍíÌìÎîOoÓóÒòÔôÖöŐőUuÚúÙùÛûÜüŰűNnÑñÇçSsŚśŠšZzŽž'} -def on_key_press(e: tkinter.Event): +# https://stackoverflow.com/questions/75846986/certain-characters-like-%c8%9b-and-%c8%99-become-question-marks-as-i-type-them-in-a-tkin +def on_key_press(e: tkinter.Event) -> str: """ - ... + This function remedies a bug that made it impossible to type certain diacritics by finding those characters in the + input and replacing them properly. + + Returns + ------- + str + 'break'. """ char = REMEDIED_CHARS.get(e.keysym_num) if char: e.widget.insert('insert', e.char[:-1] + char) return 'break' - diff --git a/code/main.py b/code/main.py index 19a0b0b..d61dd3c 100644 --- a/code/main.py +++ b/code/main.py @@ -72,7 +72,7 @@ def __init__(self, master: customtkinter.CTkTabview, **kwargs): i += 1 -def resize(root_window: tk.Tk, event: tk.Event = None): +def resize(root_window: tk.Tk, event: tk.Event = None) -> None: """ This function aims to reduce resizing lag. @@ -82,6 +82,10 @@ def resize(root_window: tk.Tk, event: tk.Event = None): The main window of the app. event: Necessary for executing the function when the user resizes. + + Returns + ------- + None """ root_window.update_idletasks() @@ -108,12 +112,16 @@ def __init__(self): self.bind('', lambda a: resize(self)) -def main(): +def main() -> None: """ Called upon starting the program, this function uses the Tkinter module to create a window, notebook, two frames the user can switch between, and a basic configuration. + + Returns + ------- + None """ root = App() root.mainloop() diff --git a/code/password_generation/diceware_gui.py b/code/password_generation/diceware_gui.py index 101d4bb..585cf84 100644 --- a/code/password_generation/diceware_gui.py +++ b/code/password_generation/diceware_gui.py @@ -91,6 +91,10 @@ def show_copy_menu(event: tk.Event) -> None: ---------- event: tkinter.event Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label. + + Returns + ------- + None """ self.copy_menu.tk_popup(event.x_root, event.y_root - 30) @@ -99,6 +103,10 @@ def show_copy_menu(event: tk.Event) -> None: def clear_window() -> None: """ This function clears the window of any output widgets. + + Returns + ------- + None """ self.widget_text_dict = {} @@ -125,8 +133,11 @@ def insert_text(textbox: customtkinter.CTkTextbox, text: str) -> None: Called when the user 'rolls the dice' from the display_words function, this function aims to take a customtkinter Textbox, insert text into it, and bind it to show a copy pop-up menu when the user right-clicks. - """ + Returns + ------- + None + """ textbox.configure(state='normal') textbox.delete('1.0', 'end') textbox.insert('1.0', text) @@ -143,6 +154,10 @@ def display_words(pair: dict) -> None: ---------- pair: dict Contains the pairs of dice roll numbers and related words according to the dice ware wordlist. + + Returns + ------- + None """ text_height = 1 text_padx = 10 @@ -197,6 +212,10 @@ def show_passwords() -> None: """ Called when the user clicks the show button, this function shows all passwords. + + Returns + ------- + None """ if self.widget_text_dict != {}: for widget, text in self.widget_text_dict.items(): @@ -210,6 +229,10 @@ def hide_passwords() -> None: """ Called when the user clicks the hide button, this function hides all passwords. + + Returns + ------- + None """ for widget, text in self.widget_text_dict.items(): widget.configure(state='normal') @@ -234,6 +257,10 @@ def hide_passwords() -> None: def close_second_window() -> None: """ This function destroys the window when it is closed. + + Returns + ------- + None """ self.destroy() self.master.deiconify() @@ -243,6 +270,10 @@ def close_second_window() -> None: def show_icon(self) -> None: """ This function shows the icon of the toplevel window. + + Returns + ------- + None """ self.deiconify() self.iconbitmap('textures/logo.ico') diff --git a/code/password_generation/diceware_logic.py b/code/password_generation/diceware_logic.py index 7596b85..2e0eade 100644 --- a/code/password_generation/diceware_logic.py +++ b/code/password_generation/diceware_logic.py @@ -13,6 +13,11 @@ def roll_dice() -> dict: Called when the user clicks the 'dice roll' of the diceware frame, this function returns a random pair of the number formed by 5 dice rolls and the associated word with that number, according to the diceware wordlist. + + Returns + ------- + dict + The final pair of 5 dice rolls and the corresponding diceware word. """ final_pairs = {} dice_roll = '' @@ -36,6 +41,10 @@ def copy_selected_text(labels: list) -> None: ---------- labels: list The list of labels containing passwords. + + Returns + ------- + None """ try: for label in labels: @@ -54,6 +63,10 @@ def copy_selections(checkboxes_text_boxes: dict) -> None: ---------- checkboxes_text_boxes: dict The dict chaining together each checkbox to each respective password textbox. + + Returns + ------- + None """ text_to_be_copied = '' for key, value in checkboxes_text_boxes.items(): diff --git a/code/password_generation/generate_password_gui.py b/code/password_generation/generate_password_gui.py index 079f5a8..ca91fdd 100644 --- a/code/password_generation/generate_password_gui.py +++ b/code/password_generation/generate_password_gui.py @@ -27,7 +27,6 @@ class PasswordGenerationFrame(customtkinter.CTkFrame): (length and character sets), and serves as a hub for all other password generation functions. """ - def __init__(self, master: customtkinter.CTkFrame, **kwargs) -> None: super().__init__(master, **kwargs) self.gui_font_name = 'Roboto' @@ -69,6 +68,10 @@ def clear_text_label(textbox: customtkinter.CTkTextbox) -> None: ---------- textbox: customtkinter.CTkTextbox The text label to be cleared. + + Returns + ------- + None """ textbox.configure(state='normal') textbox.delete('1.0', 'end') @@ -86,6 +89,10 @@ def show_password(indicator: int, btn: customtkinter.CTkButton) -> None: The number of the button that was clicked. btn: customtkinter.CTkButton The button that was clicked. + + Returns + ------- + None """ # https://stackoverflow.com/questions/68327/change-command-method-for-tkinter-button-in-python btn.configure(text='HIDE', command=lambda: hide_password(indicator, btn)) @@ -116,6 +123,10 @@ def hide_password(indicator: int, btn: customtkinter.CTkButton) -> None: The number of the button that was clicked. btn: CTKButton The button that was clicked. + + Returns + ------- + None """ btn.configure(text='SHOW', command=lambda: show_password(indicator, btn)) @@ -141,6 +152,10 @@ def run_function_based_on_slider_value(value: float) -> None: ---------- value: float The slider's value + + Returns + ------- + None """ if value == 0: hide_all_passwords() @@ -153,6 +168,10 @@ def show_all_passwords() -> None: this function goes through each password_label, inserts the specific password inside of it through the show_text function, and changes the button into a hide all button. + + Returns + ------- + None """ for indicator, btn in enumerate(self.show_hide_buttons): show_password(indicator, btn) @@ -162,6 +181,10 @@ def hide_all_passwords() -> None: Called when the user clicks the 'hide all' button, this function goes through each password_label, and clears it. + + Returns + ------- + None """ for indicator, btn in enumerate(self.show_hide_buttons): hide_password(indicator, btn) @@ -369,6 +392,10 @@ def show_copy_menu(event: tkinter.Event) -> None: ---------- event: tkinter.Event Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label. + + Returns + ------- + None """ # https://stackoverflow.com/questions/69425865/tkinter-event-x-y-mouse-position-wrong-value-only-when-mouse-movement-up self.copy_menu.tk_popup(event.x_root, event.y_root - 30) # https://youtu.be/Z4zePg2M5H8 @@ -399,6 +426,10 @@ def create_password_labels(event) -> None: ---------- event: tk.Event Necessary for running the function when the user presses the RETURN key. + + Returns + ------- + None """ message = logic.determine_error( logic.validate_character_sets(self.lowercase_letters_var, self.uppercase_letters_var, @@ -503,6 +534,10 @@ def show_text(textbox: customtkinter.CTkTextbox, message: str) -> None: or the first password label if an error is generated. message: str Each password or the error. + + Returns + ------- + None """ textbox.configure(state='normal') textbox.delete('1.0', 'end') @@ -514,6 +549,10 @@ def open_other_methods(self) -> None: """ Called when the user clicks on the 'try other methods' button, this function creates a Toplevel window containing other methods of password generation. + + Returns + ------- + None """ if self.other_methods_window is None or not self.other_methods_window.winfo_exists(): self.other_methods_window = other.OtherMethodsWindow(self) diff --git a/code/password_generation/generate_password_logic.py b/code/password_generation/generate_password_logic.py index a420a70..3c773a9 100644 --- a/code/password_generation/generate_password_logic.py +++ b/code/password_generation/generate_password_logic.py @@ -67,6 +67,11 @@ def determine_error(valid_character_set_bool: bool, requested_password_length: s 'An error occurred. Try again with at least 1 character set and a whole number between 4 and 100.' invalid_input_error: str 'An error occurred. Try again with a whole number between 4 and 100.' + + Returns + ------- + str + The error to be shown to the user. """ if valid_character_set_bool: try: @@ -100,6 +105,11 @@ def validate_character_sets(lowercase_letters_var: tkinter.IntVar, uppercase_let The variable of the digits checkbox. punctuation_var: tkinter.IntVar The variable of the punctuation checkbox. + + Returns + ------- + bool + Whether or not there's at least 1 valid character set. """ # https://www.reddit.com/user/Diapolo10/ return any(var.get() for var in (lowercase_letters_var, uppercase_letters_var, digits_var, punctuation_var)) @@ -124,6 +134,11 @@ def generate_password(requested_password_length: int, lowercase_letters_var: tki The variable used to check if the digits checkbox has been selected or not. punctuation_var: tkinter.IntVar() The variable used to check if the punctuation checkbox has been selected or not. + + Returns + ------- + str + The password. """ # Define all character sets that will be used in the password character_sets = [] @@ -155,12 +170,15 @@ def copy_selected_text(input_box: customtkinter.CTkEntry, labels: list) -> None: The entry box. labels: list The list of password labels. + + Returns + ------- + None """ try: for label in labels: selected_text = str(label.selection_get()) clipboard.copy(selected_text) - input_box.focus_set() except (ValueError, TclError): # There is no need to warn the user when they try to copy nothing as it does not have any effect on the app @@ -178,5 +196,9 @@ def copy_password(index: int, passwords: list) -> None: Which password_label has been selected to copy its password. passwords: list The list of generated password. + + Returns + ------- + None """ clipboard.copy(passwords[index]) diff --git a/code/password_generation/other_methods_gui.py b/code/password_generation/other_methods_gui.py index d619614..4eb447f 100644 --- a/code/password_generation/other_methods_gui.py +++ b/code/password_generation/other_methods_gui.py @@ -19,6 +19,10 @@ def open_link(url: str) -> None: ---------- url: str The URL to be opened. + + Returns + ------- + None """ webbrowser.open_new(url) @@ -34,7 +38,6 @@ class CreateToolTip: Modified to include a delay time by Victor Zaccardo, 25mar16 """ - # https://stackoverflow.com/questions/3221956/how-do-i-display-tooltips-in-tkinter def __init__(self, widget: customtkinter.CTkLabel, text: str = 'widget info') -> None: self.button_hover_color = None @@ -51,6 +54,10 @@ def enter(self, event: tkinter.Event = None) -> None: """ Called when the user hovers over the given widget, this function shows the tooltip. + + Returns + ------- + None """ self.schedule() @@ -58,6 +65,10 @@ def leave(self, event: tkinter.Event = None) -> None: """ Called when the user moves out of the given widget, this function shows the tooltip. + + Returns + ------- + None """ self.unschedule() self.hidetip() @@ -66,6 +77,10 @@ def schedule(self) -> None: """ This function cancels any previously shown tooltips, and defines a unique ID for a new tooltip. + + Returns + ------- + None """ self.unschedule() self.id = self.widget.after(self.waittime, self.showtip) @@ -73,6 +88,10 @@ def schedule(self) -> None: def unschedule(self) -> None: """ This function cancels any previously shown tooltips. + + Returns + ------- + None """ identification = self.id self.id = None @@ -84,6 +103,10 @@ def showtip(self, event: tkinter.Event = None) -> None: This function creates a toplevel at the user's cursor's coordinates, creates a label within it, and removes any other window decorations. + + Returns + ------- + None """ button_border_width = 2 button_fg_color = 'blue' @@ -114,6 +137,10 @@ def showtip(self, event: tkinter.Event = None) -> None: def hidetip(self) -> None: """ This function destroys the toplevel. + + Returns + ------- + None """ tw = self.tw self.tw = None @@ -185,6 +212,10 @@ def __init__(self, *args, **kwargs): def show_icon(self) -> None: """ This function shows the icon of the toplevel window. + + Returns + ------- + None """ self.deiconify() self.iconbitmap('textures/logo.ico') @@ -193,6 +224,10 @@ def open_diceware(self) -> None: """ Called when the user clicks on the 'From the diceware' button, this function opens the diceware Toplevel window. + + Returns + ------- + None """ self.withdraw() if self.diceware_window is None or not self.diceware_window.winfo_exists(): @@ -204,6 +239,10 @@ def open_sentence_input(self) -> None: """ Called when the user clicks on the 'From a sentence' button, this function opens the sentence input Toplevel window. + + Returns + ------- + None """ self.withdraw() if self.sentence_input_window is None or not self.sentence_input_window.winfo_exists(): diff --git a/code/password_generation/sentence_input_gui.py b/code/password_generation/sentence_input_gui.py index 5159f07..7afcfd5 100644 --- a/code/password_generation/sentence_input_gui.py +++ b/code/password_generation/sentence_input_gui.py @@ -16,13 +16,7 @@ class SentenceInputToplevel(customtkinter.CTkToplevel): """ def __init__(self, master: customtkinter.CTkToplevel, **kwargs) -> None: super().__init__(master, **kwargs) - """ - Called upon starting the app, - this function prepares the 'input sentence' frame for when - the user wants to try other methods of password generation - by creating a basic Tkinter configuration, with an instruction, input, - and a way to display the produced password. - """ + self.geometry('900x300') self.title('Sentence input') self.iconbitmap('textures/logo.ico') @@ -56,6 +50,10 @@ def show_copy_menu(event: tk.Event) -> None: ---------- event: tk.Event Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label. + + Returns + ------- + None """ self.copy_menu.tk_popup(event.x_root, event.y_root - 30) @@ -83,7 +81,7 @@ def show_copy_menu(event: tk.Event) -> None: self.copy_menu.add_command(label='Copy', command=lambda: logic.copy_selected_text(self.text_labels)) - def highlight_sentence(event: tk.Event): + def highlight_sentence(event: tk.Event) -> None: """ Called as the user types, this function calls the produce_password function of sentence_input_logic.py @@ -94,6 +92,10 @@ def highlight_sentence(event: tk.Event): ---------- event: tk.Event Necessary for running the function as the user types. + + Returns + ------- + None """ char_dict = {} @@ -126,6 +128,10 @@ def show_password(password: str) -> None: ---------- password: str The password to be shown generated from the sentence. + + Returns + ------- + None """ self.password_label.configure(state='normal') self.password_label.delete('1.0', 'end') @@ -141,6 +147,10 @@ def display_warnings(warnings: list) -> None: ---------- warnings: list List of the tips for the user's password. + + Returns + ------- + None """ self.warning_label_1.configure(text=warnings[0]) self.warning_label_1.place(relx=0.5, rely=0.75, anchor='center') @@ -158,6 +168,10 @@ def display_warnings(warnings: list) -> None: def close_second_window() -> None: """ This function destroys the window when it is closed. + + Returns + ------- + None """ self.destroy() self.master.deiconify() @@ -167,6 +181,10 @@ def close_second_window() -> None: def show_icon(self) -> None: """ This function shows the icon of the toplevel window. + + Returns + ------- + None """ self.deiconify() self.iconbitmap('textures/logo.ico') diff --git a/code/password_generation/sentence_input_logic.py b/code/password_generation/sentence_input_logic.py index d067291..2e8dc33 100644 --- a/code/password_generation/sentence_input_logic.py +++ b/code/password_generation/sentence_input_logic.py @@ -8,7 +8,7 @@ from tkinter import TclError -def check_password_strength(inputted_password: str) -> list | str: +def check_password_strength(inputted_password: str) -> list: """ Called upon pressing the done button, this function defines several functions that check @@ -16,12 +16,16 @@ def check_password_strength(inputted_password: str) -> list | str: and returns appropriate messages. It then calls these functions and returns a list of messages indicating the results of each check. - Returns an empty list when the inputted_password in None. - Parameters ---------- inputted_password: str - The input of the user + The input of the user. + + Returns + ------- + list: + List that contains tips for the user to improve their password. + An empty list when the inputted_password is None. """ user_input = [] user_input[:0] = inputted_password # Adds each character of the input to a list. @@ -138,6 +142,11 @@ def produce_password(char_dict: dict) -> list: ---------- char_dict: dict The dictionary chaining each character to its index. + + Returns + ------- + list + The list of letters to be coloured and the produced password. """ letters_to_be_coloured = {} password = '' @@ -167,6 +176,10 @@ def copy_selected_text(labels: list) -> None: ---------- labels: list The list of labels that contain text that could be copied. + + Returns + ------- + None """ try: for label in labels: diff --git a/code/password_strength/password_strength_gui.py b/code/password_strength/password_strength_gui.py index 6a42d67..cde713f 100644 --- a/code/password_strength/password_strength_gui.py +++ b/code/password_strength/password_strength_gui.py @@ -24,7 +24,6 @@ class PasswordStrengthFrame(customtkinter.CTkFrame): an entry box for password input, and four warning labels to display the strength of the password. It also creates a menu for pasting text, which is triggered by a right-click on the input box. """ - def __init__(self, master: customtkinter.CTkFrame, **kwargs) -> None: super().__init__(master, **kwargs) title_font = customtkinter.CTkFont(family='Roboto', size=36) @@ -79,6 +78,10 @@ def display_paste_button(event: tkinter.Event, paste_menu: tkinter.Menu) -> None Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label. paste_menu: tkinter.Menu The contextual menu containing the paste button. + + Returns + ------- + None """ paste_menu.tk_popup(event.x_root, event.y_root - copy_button_y_offset) @@ -97,8 +100,12 @@ def display_warnings(entry_box: customtkinter.CTkEntry, w_labels: list, event: t The input box of the password. w_labels: list Warning labels. - event: tkinter.event + event: tkinter.Event Necessary for initiating the function as the user types. + + Returns + ------- + None """ for label in w_labels: label.configure(text='') @@ -119,6 +126,10 @@ def paste_text() -> None: """ Called upon pressing the paste button, this function uses the keyboard module to simulate pressing CTRL and V to paste text into the input_box. + + Returns + ------- + None """ # https://youtu.be/DTnz8wA6wpw keyboard.press(Key.ctrl_l) diff --git a/code/password_strength/password_strength_logic.py b/code/password_strength/password_strength_logic.py index d379374..8a67ac2 100644 --- a/code/password_strength/password_strength_logic.py +++ b/code/password_strength/password_strength_logic.py @@ -28,6 +28,13 @@ def check_password_strength(inputted_password: str, input_password_msg: str) -> The input of the user input_password_msg: str 'Please input a password.' + + Returns + ------- + list + If a password was inputted, this function will return the list of warnings/tips. + str + If no password was inputted, this function will return a message asking the user to input one. """ user_input = [] user_input[:0] = inputted_password # Adds each character of the input to a list.