From c01f30e55c3a57dbd32d8ed828a9de0069a6bab8 Mon Sep 17 00:00:00 2001 From: Average Blank <112507212+AverageBlank@users.noreply.github.com> Date: Sat, 29 Jul 2023 14:10:20 +0530 Subject: [PATCH] Update main.py Fixed bugs, added minimalStyle, added checkboxes. --- main.py | 107 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/main.py b/main.py index b339b50..8821ad9 100644 --- a/main.py +++ b/main.py @@ -57,13 +57,14 @@ def encryption(): ClearScreen() while True: - inp = confirm("Do you have an encryption key?").ask() + inp = confirm("Do you have an encryption key?", style=minimalStyle).ask() if inp: - key = password("Enter the key:").ask() + key = password("Enter the key:", style=minimalStyle).ask() elif inp == False: while True: GenKey = confirm( - "Do you want to generate a key?\n[You will lose access to previous data]" + "Do you want to generate a key?\n[You will lose access to previous data]", + style=minimalStyle, ).ask() if GenKey == False: exit() @@ -74,7 +75,9 @@ def encryption(): f"Given below is the key, you will not get access to it again.\n{key}" ) while True: - copyKey = confirm("Do you want to copy the key?").ask() + copyKey = confirm( + "Do you want to copy the key?", style=minimalStyle + ).ask() if copyKey: pyperclip.copy(key) break @@ -89,8 +92,26 @@ def encryption(): ######? Clear Screen ##### def ClearScreen(): + global minimalStyle + #####* For Rich ##### console = Console() + + #####* For Questionary Style ##### + minimalStyle = Style( + [ + ("answer", "fg:#FFFFFF italic"), # ? White + ("question", "fg:#FFFFFF bold"), # ? White + ("pointer", "fg:#00FFFF bold"), # ? Cyan + ("highlighted", "fg:#FFFFFF"), # ? White + ("selected", "fg:#A9A9A9"), # ? Grey + ("qmark", "fg:#77DD77"), # ? Green + ] + ) + + #####* Clearing the Screen ##### system("clear" if OSName == "posix" else "cls") + + #####* Printing Password Manager ##### console.print(Panel.fit("[bold italic #77DDD4]Password Manager", padding=(0, 22))) @@ -111,11 +132,15 @@ def StatBar(time: float, desc: str): def GenPass(p): genop = "" while True: - gen = confirm("Do you want to generate a password?").ask() + gen = confirm("Do you want to generate a password?", style=minimalStyle).ask() if gen: while True: try: - genlen = int(text("How long should the password be?").ask()) + genlen = int( + text( + "How long should the password be?", style=minimalStyle + ).ask() + ) if genlen <= 0: raise ValueError break @@ -158,7 +183,9 @@ def AddEntry(t): #####* Getting Values ##### while True: - name = text("What do you want the entry to be called?").ask() + name = text( + "What do you want the entry to be called?", style=minimalStyle + ).ask() if name == "": print("Name cannot be left empty.") continue @@ -166,8 +193,8 @@ def AddEntry(t): print("That name already exists.") continue break - email = text("Enter Email ID [Optional]:").ask() - usrname = text("Enter Username [Optional]:") + email = text("Enter Email ID [Optional]:", style=minimalStyle).ask() + usrname = text("Enter Username [Optional]:", style=minimalStyle).ask() passwd = GenPass("Enter Password:") passwd = fernet.encrypt(passwd.encode()) @@ -205,17 +232,23 @@ def EditEntry(t): for i in result: options.append(f"{i[0]}. {i[1]}".title()) options.append("0. Back") - choice = select("Which entry do you want to edit?", options).ask() + choice = select( + "Which entry do you want to edit?", options, style=minimalStyle + ).ask() choice = int(choice[0]) if choice == 0: raise AttributeError #####* Getting Values ##### - opt = checkbox("What all do you want to edit?", ["Name", "Email", "Username", "Password"]).ask() + opt = checkbox( + "What all do you want to edit?", + ["Name", "Email", "Username", "Password"], + style=minimalStyle, + ).ask() ###? Name ### if "Name" in opt: while True: - Name = text("What should the name be?").ask() + Name = text("What should the name be?", style=minimalStyle).ask() if Name == "": print("Name cannot be left empty.") continue @@ -223,23 +256,17 @@ def EditEntry(t): break ###? Email ### if "Email" in opt: - Email = text("What should the email be?").ask() - cur.execute( - rf"update {t} set Email='{Email}' where IndexNo={choice}" - ) + Email = text("What should the email be?", style=minimalStyle).ask() + cur.execute(rf"update {t} set Email='{Email}' where IndexNo={choice}") ###? Username ### if "Username" in opt: - Username = text("What should the username be?").ask() - cur.execute( - rf"update {t} set Username='{Username}' where IndexNo={choice}" - ) + Username = text("What should the username be?", style=minimalStyle).ask() + cur.execute(rf"update {t} set Username='{Username}' where IndexNo={choice}") ###? Password ### if "Password" in opt: Passwd = GenPass("What should the password be?") Passwd = fernet.encrypt(Passwd.encode()) - cur.execute( - rf'update {t} set Password="{Passwd}" where IndexNo={choice}' - ) + cur.execute(rf'update {t} set Password="{Passwd}" where IndexNo={choice}') if Name == "-" and Email == "-" and Username == "-" and Passwd == "-": print("The entry has not been modified.") else: @@ -277,7 +304,9 @@ def DelEntry(t): for i in result: options.append(f"{i[0]}. {i[1]}".title()) options.append("0. Back") - choice = select("Which entry do you want to edit?", options).ask() + choice = select( + "Which entry do you want to edit?", options, style=minimalStyle + ).ask() choice = int(choice[0]) if choice == 0: raise AttributeError @@ -287,7 +316,8 @@ def DelEntry(t): cur.execute(rf"select Name from {t} where IndexNo={choice}") name = cur.fetchall()[0][0] conf = confirm( - f"Are you sure you want to delete the entry for {name}?" + f"Are you sure you want to delete the entry for {name}?", + style=minimalStyle, ).ask() if conf: cur.execute(rf"delete from {t} where IndexNo={choice}") @@ -304,7 +334,7 @@ def DelEntry(t): conn.commit() ###? Confirmation ### print(f"The entry for {name} has been successfully deleted!") - sleep(1) + input("Please enter to continue...") break elif conf == False: break @@ -351,13 +381,11 @@ def CopyEntry(t): name = cur.fetchall()[0][0] while True: ###? Getting What User Wants to Copy to Clipboard ### - conf = ( - select( - "What do you want to copy?", - ["Email", "Username", "Password"], - ) - .ask() - ) + conf = select( + "What do you want to copy?", + ["Email", "Username", "Password"], + style=minimalStyle, + ).ask() ###? Email ### if conf == "Email": cur.execute(rf"select Email from {t} where IndexNo={choice}") @@ -415,24 +443,13 @@ def PrintOptions(): while True: global minimalStyle - #####* For Questionary Style ##### - minimalStyle = Style( - [ - ("answer", "fg:#FFFFFF italic"), # ? White - ("question", "fg:#FFFFFF bold"), # ? White - ("pointer", "fg:#00FFFF bold"), # ? Cyan - ("highlighted", "fg:#FFFFFF"), # ? White - ("selected", "fg:#A9A9A9"), # ? Grey - ("qmark", "fg:#77DD77"), # ? Green - ] - ) - ####* Clearing the Screen #### ClearScreen() ####* Printing Options #### choice = select( "What is your choice?", ["Add Entry", "Edit Entry", "Delete Entry", "Copy Entry", "Quit"], + style=minimalStyle, ).ask() #######? Calling Functions #######