Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleaning add raises and returns to each fuction #55

Merged
merged 27 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9bd7bec
Update diceware_gui.py
IceTheCoder May 22, 2023
b3f9e5e
Update diceware_gui.py
IceTheCoder May 22, 2023
6bf373e
Update diceware_gui.py
IceTheCoder May 22, 2023
108b6ff
Update diceware_gui.py
IceTheCoder May 22, 2023
ea9d40c
Update diceware_gui.py
IceTheCoder May 22, 2023
aac6982
Update diceware_gui.py
IceTheCoder May 22, 2023
be811c6
Update diceware_gui.py
IceTheCoder May 22, 2023
c3a990b
Update diceware_gui.py
IceTheCoder May 22, 2023
d29ca2b
Update diceware_logic.py
IceTheCoder May 22, 2023
7e82320
Update generate_password_gui.py
IceTheCoder May 22, 2023
a54b4aa
Update generate_password_gui.py
IceTheCoder May 22, 2023
67d35c6
Update generate_password_gui.py
IceTheCoder May 22, 2023
0a06359
Update generate_password_gui.py
IceTheCoder May 22, 2023
bf6860a
Update generate_password_gui.py
IceTheCoder May 22, 2023
3255a2c
Update diceware_gui.py
IceTheCoder May 22, 2023
5dba4ec
Update diceware_logic.py
IceTheCoder May 22, 2023
76dc768
Update generate_password_gui.py
IceTheCoder May 22, 2023
3c24544
Update generate_password_logic.py
IceTheCoder May 22, 2023
05e2b2b
Update other_methods_gui.py
IceTheCoder May 22, 2023
59d293f
Update sentence_input_gui.py
IceTheCoder May 22, 2023
8511596
Update sentence_input_logic.py
IceTheCoder May 22, 2023
dc5b9ea
Update sentence_input_logic.py
IceTheCoder May 22, 2023
b3b5307
Update password_strength_gui.py
IceTheCoder May 22, 2023
bf352cd
Update password_strength_gui.py
IceTheCoder May 22, 2023
efdd223
Update password_strength_logic.py
IceTheCoder May 22, 2023
b935c0c
Update diacritics_fix.py
IceTheCoder May 22, 2023
558e9c4
Update main.py
IceTheCoder May 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions code/diacritics_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

12 changes: 10 additions & 2 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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()

Expand All @@ -108,12 +112,16 @@ def __init__(self):
self.bind('<Configure>', 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()
Expand Down
33 changes: 32 additions & 1 deletion code/password_generation/diceware_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = {}

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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')
Expand All @@ -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()
Expand All @@ -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')
13 changes: 13 additions & 0 deletions code/password_generation/diceware_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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:
Expand All @@ -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():
Expand Down
41 changes: 40 additions & 1 deletion code/password_generation/generate_password_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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))
Expand Down Expand Up @@ -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))

Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion code/password_generation/generate_password_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand All @@ -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 = []
Expand Down Expand Up @@ -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
Expand All @@ -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])
Loading