commit 0d211eabc7a431a2b992f6ff86689c2497b1f330
parent 863a5b18a7a6a6e2c123046b279054748ceb4581
Author: FIGBERT <figbertwelner@gmail.com>
Date: Mon, 15 Jul 2019 15:51:27 -0700
Simplifying repetitive code
Diffstat:
M | Scripts/figENC.py | | | 138 | +++++++++++++++---------------------------------------------------------------- |
1 file changed, 26 insertions(+), 112 deletions(-)
diff --git a/Scripts/figENC.py b/Scripts/figENC.py
@@ -10,6 +10,25 @@ import file_check as check
crypto_mode = ""
+def reset():
+ file_frame.pack_forget()
+ file_label.pack_forget()
+ file_instructions.pack_forget()
+ reset_text(file_input)
+ file_input.pack_forget()
+ passcode_frame.pack_forget()
+ passcode_label.pack_forget()
+ passcode_instructions.pack_forget()
+ reset_text(passcode_input)
+ passcode_input.pack_forget()
+ save.pack_forget()
+ save_label.pack_forget()
+ save_instructions.pack_forget()
+ reset_text(save_input)
+ save_input.pack_forget()
+ submit.pack_forget()
+
+
def setup(mode):
""""Change the GUI to match the app mode,
based on the user's action_list selection.
@@ -20,22 +39,7 @@ def setup(mode):
mode = mode[0]
global crypto_mode
if mode == 0: #Encrypt with fresh keys (password locked)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
file_frame.pack(fill="both")
file_label.config(text="Filepath/s to the file/s to encrypt")
file_label.pack()
@@ -70,22 +74,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "key_enc"
elif mode == 1: #Encrypt with fresh keys (no password)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
file_frame.pack(fill="both")
file_label.config(text="Filepath/s to the file/s to encrypt")
file_label.pack()
@@ -108,22 +97,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "weak_key_enc"
elif mode == 2: #Encrypt with generated keys
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
file_frame.pack(fill="both")
file_label.config(text="Filepath/s to the file/s to encrypt")
file_label.pack()
@@ -139,22 +113,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "enc"
elif mode == 3: #Decrypt with generated keys (password locked)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
file_frame.pack(fill="both")
file_label.config(text="Filepath/s to the file/s to decrypt")
file_label.pack()
@@ -181,22 +140,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "dec"
elif mode == 4: #Decrypt with generated keys (no password)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
file_frame.pack(fill="both")
file_label.config(text="Filepath/s to the file/s to decrypt")
file_label.pack()
@@ -212,22 +156,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "weak_dec"
elif mode == 5: #Only create fresh keys (password locked)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
passcode_frame.pack(fill="both")
passcode_label.config(text="Set private key passcode")
passcode_label.pack()
@@ -256,22 +185,7 @@ def setup(mode):
submit.pack(pady="10")
crypto_mode = "just_key"
elif mode == 6: #Only create fresh keys (no password)
- file_frame.pack_forget()
- file_label.pack_forget()
- file_instructions.pack_forget()
- reset_text(file_input)
- file_input.pack_forget()
- passcode_frame.pack_forget()
- passcode_label.pack_forget()
- passcode_instructions.pack_forget()
- reset_text(passcode_input)
- passcode_input.pack_forget()
- save.pack_forget()
- save_label.pack_forget()
- save_instructions.pack_forget()
- reset_text(save_input)
- save_input.pack_forget()
- submit.pack_forget()
+ reset()
save.pack(fill="both")
save_label.config(text="Save location for keys")
save_label.pack()