Skip to content

Commit d4d4561

Browse files
authored
Merge pull request #55 from IceTheDev2/code-cleaning-add-raises-and-returns-to-each-fuction
Code cleaning add raises and returns to each fuction
2 parents d0af7eb + 558e9c4 commit d4d4561

File tree

11 files changed

+230
-23
lines changed

11 files changed

+230
-23
lines changed

code/diacritics_fix.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
REMEDIED_CHARS = {ord(c): c for c in 'ĂăÂâÎîȘșTtȚțEeÉéÈèÊêËëIiÍíÌìÎîOoÓóÒòÔôÖöŐőUuÚúÙùÛûÜüŰűNnÑñÇçSsŚśŠšZzŽž'}
77

88

9-
def on_key_press(e: tkinter.Event):
9+
# https://stackoverflow.com/questions/75846986/certain-characters-like-%c8%9b-and-%c8%99-become-question-marks-as-i-type-them-in-a-tkin
10+
def on_key_press(e: tkinter.Event) -> str:
1011
"""
11-
...
12+
This function remedies a bug that made it impossible to type certain diacritics by finding those characters in the
13+
input and replacing them properly.
14+
15+
Returns
16+
-------
17+
str
18+
'break'.
1219
"""
1320
char = REMEDIED_CHARS.get(e.keysym_num)
1421
if char:
1522
e.widget.insert('insert', e.char[:-1] + char)
1623
return 'break'
17-

code/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, master: customtkinter.CTkTabview, **kwargs):
7272
i += 1
7373

7474

75-
def resize(root_window: tk.Tk, event: tk.Event = None):
75+
def resize(root_window: tk.Tk, event: tk.Event = None) -> None:
7676
"""
7777
This function aims to reduce resizing lag.
7878
@@ -82,6 +82,10 @@ def resize(root_window: tk.Tk, event: tk.Event = None):
8282
The main window of the app.
8383
event:
8484
Necessary for executing the function when the user resizes.
85+
86+
Returns
87+
-------
88+
None
8589
"""
8690
root_window.update_idletasks()
8791

@@ -108,12 +112,16 @@ def __init__(self):
108112
self.bind('<Configure>', lambda a: resize(self))
109113

110114

111-
def main():
115+
def main() -> None:
112116
"""
113117
Called upon starting the program,
114118
this function uses the Tkinter module to create a window, notebook,
115119
two frames the user can switch between,
116120
and a basic configuration.
121+
122+
Returns
123+
-------
124+
None
117125
"""
118126
root = App()
119127
root.mainloop()

code/password_generation/diceware_gui.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def show_copy_menu(event: tk.Event) -> None:
9191
----------
9292
event: tkinter.event
9393
Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label.
94+
95+
Returns
96+
-------
97+
None
9498
"""
9599
self.copy_menu.tk_popup(event.x_root, event.y_root - 30)
96100

@@ -99,6 +103,10 @@ def show_copy_menu(event: tk.Event) -> None:
99103
def clear_window() -> None:
100104
"""
101105
This function clears the window of any output widgets.
106+
107+
Returns
108+
-------
109+
None
102110
"""
103111
self.widget_text_dict = {}
104112

@@ -125,8 +133,11 @@ def insert_text(textbox: customtkinter.CTkTextbox, text: str) -> None:
125133
Called when the user 'rolls the dice' from the display_words function,
126134
this function aims to take a customtkinter Textbox,
127135
insert text into it, and bind it to show a copy pop-up menu when the user right-clicks.
128-
"""
129136
137+
Returns
138+
-------
139+
None
140+
"""
130141
textbox.configure(state='normal')
131142
textbox.delete('1.0', 'end')
132143
textbox.insert('1.0', text)
@@ -143,6 +154,10 @@ def display_words(pair: dict) -> None:
143154
----------
144155
pair: dict
145156
Contains the pairs of dice roll numbers and related words according to the dice ware wordlist.
157+
158+
Returns
159+
-------
160+
None
146161
"""
147162
text_height = 1
148163
text_padx = 10
@@ -197,6 +212,10 @@ def show_passwords() -> None:
197212
"""
198213
Called when the user clicks the show button,
199214
this function shows all passwords.
215+
216+
Returns
217+
-------
218+
None
200219
"""
201220
if self.widget_text_dict != {}:
202221
for widget, text in self.widget_text_dict.items():
@@ -210,6 +229,10 @@ def hide_passwords() -> None:
210229
"""
211230
Called when the user clicks the hide button,
212231
this function hides all passwords.
232+
233+
Returns
234+
-------
235+
None
213236
"""
214237
for widget, text in self.widget_text_dict.items():
215238
widget.configure(state='normal')
@@ -234,6 +257,10 @@ def hide_passwords() -> None:
234257
def close_second_window() -> None:
235258
"""
236259
This function destroys the window when it is closed.
260+
261+
Returns
262+
-------
263+
None
237264
"""
238265
self.destroy()
239266
self.master.deiconify()
@@ -243,6 +270,10 @@ def close_second_window() -> None:
243270
def show_icon(self) -> None:
244271
"""
245272
This function shows the icon of the toplevel window.
273+
274+
Returns
275+
-------
276+
None
246277
"""
247278
self.deiconify()
248279
self.iconbitmap('textures/logo.ico')

code/password_generation/diceware_logic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def roll_dice() -> dict:
1313
Called when the user clicks the 'dice roll' of the diceware frame,
1414
this function returns a random pair of the number formed by 5 dice rolls
1515
and the associated word with that number, according to the diceware wordlist.
16+
17+
Returns
18+
-------
19+
dict
20+
The final pair of 5 dice rolls and the corresponding diceware word.
1621
"""
1722
final_pairs = {}
1823
dice_roll = ''
@@ -36,6 +41,10 @@ def copy_selected_text(labels: list) -> None:
3641
----------
3742
labels: list
3843
The list of labels containing passwords.
44+
45+
Returns
46+
-------
47+
None
3948
"""
4049
try:
4150
for label in labels:
@@ -54,6 +63,10 @@ def copy_selections(checkboxes_text_boxes: dict) -> None:
5463
----------
5564
checkboxes_text_boxes: dict
5665
The dict chaining together each checkbox to each respective password textbox.
66+
67+
Returns
68+
-------
69+
None
5770
"""
5871
text_to_be_copied = ''
5972
for key, value in checkboxes_text_boxes.items():

code/password_generation/generate_password_gui.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class PasswordGenerationFrame(customtkinter.CTkFrame):
2727
(length and character sets),
2828
and serves as a hub for all other password generation functions.
2929
"""
30-
3130
def __init__(self, master: customtkinter.CTkFrame, **kwargs) -> None:
3231
super().__init__(master, **kwargs)
3332
self.gui_font_name = 'Roboto'
@@ -69,6 +68,10 @@ def clear_text_label(textbox: customtkinter.CTkTextbox) -> None:
6968
----------
7069
textbox: customtkinter.CTkTextbox
7170
The text label to be cleared.
71+
72+
Returns
73+
-------
74+
None
7275
"""
7376
textbox.configure(state='normal')
7477
textbox.delete('1.0', 'end')
@@ -86,6 +89,10 @@ def show_password(indicator: int, btn: customtkinter.CTkButton) -> None:
8689
The number of the button that was clicked.
8790
btn: customtkinter.CTkButton
8891
The button that was clicked.
92+
93+
Returns
94+
-------
95+
None
8996
"""
9097
# https://stackoverflow.com/questions/68327/change-command-method-for-tkinter-button-in-python
9198
btn.configure(text='HIDE', command=lambda: hide_password(indicator, btn))
@@ -116,6 +123,10 @@ def hide_password(indicator: int, btn: customtkinter.CTkButton) -> None:
116123
The number of the button that was clicked.
117124
btn: CTKButton
118125
The button that was clicked.
126+
127+
Returns
128+
-------
129+
None
119130
"""
120131
btn.configure(text='SHOW', command=lambda: show_password(indicator, btn))
121132

@@ -141,6 +152,10 @@ def run_function_based_on_slider_value(value: float) -> None:
141152
----------
142153
value: float
143154
The slider's value
155+
156+
Returns
157+
-------
158+
None
144159
"""
145160
if value == 0:
146161
hide_all_passwords()
@@ -153,6 +168,10 @@ def show_all_passwords() -> None:
153168
this function goes through each password_label,
154169
inserts the specific password inside of it through the show_text function,
155170
and changes the button into a hide all button.
171+
172+
Returns
173+
-------
174+
None
156175
"""
157176
for indicator, btn in enumerate(self.show_hide_buttons):
158177
show_password(indicator, btn)
@@ -162,6 +181,10 @@ def hide_all_passwords() -> None:
162181
Called when the user clicks the 'hide all' button,
163182
this function goes through each password_label,
164183
and clears it.
184+
185+
Returns
186+
-------
187+
None
165188
"""
166189
for indicator, btn in enumerate(self.show_hide_buttons):
167190
hide_password(indicator, btn)
@@ -369,6 +392,10 @@ def show_copy_menu(event: tkinter.Event) -> None:
369392
----------
370393
event: tkinter.Event
371394
Gets the coordinates of the mouse cursor when the user releases a mouse button on a password_label.
395+
396+
Returns
397+
-------
398+
None
372399
"""
373400
# https://stackoverflow.com/questions/69425865/tkinter-event-x-y-mouse-position-wrong-value-only-when-mouse-movement-up
374401
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:
399426
----------
400427
event: tk.Event
401428
Necessary for running the function when the user presses the RETURN key.
429+
430+
Returns
431+
-------
432+
None
402433
"""
403434
message = logic.determine_error(
404435
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:
503534
or the first password label if an error is generated.
504535
message: str
505536
Each password or the error.
537+
538+
Returns
539+
-------
540+
None
506541
"""
507542
textbox.configure(state='normal')
508543
textbox.delete('1.0', 'end')
@@ -514,6 +549,10 @@ def open_other_methods(self) -> None:
514549
"""
515550
Called when the user clicks on the 'try other methods' button,
516551
this function creates a Toplevel window containing other methods of password generation.
552+
553+
Returns
554+
-------
555+
None
517556
"""
518557
if self.other_methods_window is None or not self.other_methods_window.winfo_exists():
519558
self.other_methods_window = other.OtherMethodsWindow(self)

code/password_generation/generate_password_logic.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def determine_error(valid_character_set_bool: bool, requested_password_length: s
6767
'An error occurred. Try again with at least 1 character set and a whole number between 4 and 100.'
6868
invalid_input_error: str
6969
'An error occurred. Try again with a whole number between 4 and 100.'
70+
71+
Returns
72+
-------
73+
str
74+
The error to be shown to the user.
7075
"""
7176
if valid_character_set_bool:
7277
try:
@@ -100,6 +105,11 @@ def validate_character_sets(lowercase_letters_var: tkinter.IntVar, uppercase_let
100105
The variable of the digits checkbox.
101106
punctuation_var: tkinter.IntVar
102107
The variable of the punctuation checkbox.
108+
109+
Returns
110+
-------
111+
bool
112+
Whether or not there's at least 1 valid character set.
103113
"""
104114
# https://www.reddit.com/user/Diapolo10/
105115
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
124134
The variable used to check if the digits checkbox has been selected or not.
125135
punctuation_var: tkinter.IntVar()
126136
The variable used to check if the punctuation checkbox has been selected or not.
137+
138+
Returns
139+
-------
140+
str
141+
The password.
127142
"""
128143
# Define all character sets that will be used in the password
129144
character_sets = []
@@ -155,12 +170,15 @@ def copy_selected_text(input_box: customtkinter.CTkEntry, labels: list) -> None:
155170
The entry box.
156171
labels: list
157172
The list of password labels.
173+
174+
Returns
175+
-------
176+
None
158177
"""
159178
try:
160179
for label in labels:
161180
selected_text = str(label.selection_get())
162181
clipboard.copy(selected_text)
163-
164182
input_box.focus_set()
165183
except (ValueError, TclError):
166184
# 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:
178196
Which password_label has been selected to copy its password.
179197
passwords: list
180198
The list of generated password.
199+
200+
Returns
201+
-------
202+
None
181203
"""
182204
clipboard.copy(passwords[index])

0 commit comments

Comments
 (0)