Updated A-2 to A-3
Removed `program` state flag property and replaced with operation distinguishing from selection menu; Branched numeral and character option logic in main(); Fixed test mode toggle; Minor menu edits; Removed the status of variables `program`, `p_name` and `p_path` as storage to simplify code; Verified that double escapes were and are not required by the user to launch programs by path; Standardized error messages, included `KeyboardInterrupt` exceptions, and added umbrella error catchers.
This commit is contained in:
@@ -14,15 +14,15 @@ from termcolor import colored
|
|||||||
# |___|_| |_|\__\___|_| \___\___| .__/ \__\___/|_| /_/ \_\_| |____/
|
# |___|_| |_|\__\___|_| \___\___| .__/ \__\___/|_| /_/ \_\_| |____/
|
||||||
# |_| APS Version Alpha-2 by P7MJ
|
# |_| APS Version Alpha-2 by P7MJ
|
||||||
|
|
||||||
# ---------- CONFIGURATION ---------- #
|
# ---------- Monitor Path ---------- #
|
||||||
monitor_path = r"C:\Program Files\Renato Software\Senso.Cloud.Client" # Path to be monitored
|
monitor_path = r"C:\Program Files\Renato Software\Senso.Cloud.Client" # Path to be monitored
|
||||||
|
|
||||||
# ---------- DON'T TOUCH ---------- #
|
# ---------- Variables (REMOVE) ---------- #
|
||||||
program = "" # 0 is use path, -1 is use name, 1-4 is programs
|
program = "" # 0 is use path, -1 is use name, 1-4 is programs
|
||||||
p_name = ""
|
p_name = ""
|
||||||
p_path = "" # used only if program = 0.
|
p_path = "" # used only if program = 0.
|
||||||
|
|
||||||
# ---------- BRING TO FRONT ---------- #
|
# ---------- Bring to front ---------- #
|
||||||
def bring_to_front(window_title):
|
def bring_to_front(window_title):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
try:
|
try:
|
||||||
@@ -38,7 +38,7 @@ def bring_to_front(window_title):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(colored(f"Error: {e}", 'red'))
|
print(colored(f"Error: {e}", 'red'))
|
||||||
|
|
||||||
# ---------- FILE WATCHER ---------- #
|
# ---------- File watch ---------- #
|
||||||
def file_watch(iftest):
|
def file_watch(iftest):
|
||||||
print("=" * 80)
|
print("=" * 80)
|
||||||
print("Monitoring changes in " + monitor_path + ".")
|
print("Monitoring changes in " + monitor_path + ".")
|
||||||
@@ -54,14 +54,14 @@ def file_watch(iftest):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(colored(f"File Watch Error: {e}", 'red'))
|
print(colored(f"File Watch Error: {e}", 'red'))
|
||||||
|
|
||||||
# ---------- MINIMIZE ---------- #
|
# ---------- Minimize ---------- #
|
||||||
def minimize():
|
def minimize():
|
||||||
print("=" * 80)
|
print("=" * 80)
|
||||||
print("Minimizing all windows...", end = " ")
|
print("Minimizing all windows...", end = " ")
|
||||||
pyautogui.hotkey('win', 'd')
|
pyautogui.hotkey('win', 'd')
|
||||||
print("Completed.")
|
print("Completed.")
|
||||||
|
|
||||||
# ---------- LAUNCH COVER PROGRAM ---------- #
|
# ---------- Launch cover (program) ---------- #
|
||||||
def launch_cover(programs):
|
def launch_cover(programs):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
print("=" * 80)
|
print("=" * 80)
|
||||||
@@ -105,7 +105,7 @@ def launch_cover(programs):
|
|||||||
else:
|
else:
|
||||||
print(colored("Error: Invalid Cover App Specified.", 'red'))
|
print(colored("Error: Invalid Cover App Specified.", 'red'))
|
||||||
|
|
||||||
# ---------- LAUNCH COVER PROGRAM PATH ---------- #
|
# ---------- Launch cover (program) path ---------- #
|
||||||
def launch_cover_path(path):
|
def launch_cover_path(path):
|
||||||
print("Launching custom path...", end = " ")
|
print("Launching custom path...", end = " ")
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
@@ -114,7 +114,7 @@ def launch_cover_path(path):
|
|||||||
)
|
)
|
||||||
print("Launched custom path.")
|
print("Launched custom path.")
|
||||||
|
|
||||||
# ---------- LAUNCH SPECIFIC CHROME TAB ---------- #
|
# ---------- Specific Chrome tab ---------- #
|
||||||
def specific_tab(browser, tab_no):
|
def specific_tab(browser, tab_no):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
try:
|
try:
|
||||||
@@ -143,88 +143,111 @@ def specific_tab(browser, tab_no):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(colored(f"Specific-Tab Error: {e}", 'red'))
|
print(colored(f"Specific-Tab Error: {e}", 'red'))
|
||||||
|
|
||||||
|
# ---------- Help Section ---------- #
|
||||||
# ---------- Main Process ---------- #
|
def help_section():
|
||||||
def main():
|
|
||||||
global p_name, p_path, testmode
|
|
||||||
testmode = False
|
|
||||||
|
|
||||||
while True:
|
|
||||||
print()
|
print()
|
||||||
print("=" * 80)
|
|
||||||
print(f"Interceptor APS (Active Protection System) ===== TESTMODE: {testmode}")
|
|
||||||
print("-" * 80)
|
|
||||||
print("Choose a cover app to open:")
|
|
||||||
print("[1] Chrome (1)")
|
|
||||||
print("[2] Edge (1)")
|
|
||||||
print("[3] Adobe Illustrator (2)")
|
|
||||||
print("[4] Onenote (3)")
|
|
||||||
print("[5] Enter a path (4)")
|
|
||||||
print("[6] Specify Chrome Tab Number (5)")
|
|
||||||
print("[7] Specify Window Name (6)\n")
|
|
||||||
print("[x] Help")
|
|
||||||
print("[y] Set test mode", end = "\n\n")
|
|
||||||
program = input("Enter your option > ")
|
|
||||||
|
|
||||||
if program == "5": # If path is selected (I doubt that)
|
|
||||||
p_path = input("Enter full path > ")
|
|
||||||
program = "0" # Indicate that the path option is selected
|
|
||||||
elif program == "6":
|
|
||||||
try:
|
|
||||||
tabs_no = input("Tab number > ")
|
|
||||||
if tabs_no.isdigit():
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print("Error: Not a digit")
|
|
||||||
main()
|
|
||||||
watchresults = file_watch(testmode) # STILL TESTING Switch to false if finished!!!
|
|
||||||
minimize()
|
|
||||||
specific_tab("chrome", int(tabs_no))
|
|
||||||
main()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Canceled by user.")
|
|
||||||
main()
|
|
||||||
elif program == "7": # If name is chosen
|
|
||||||
program = "-1" # Indicate that the name option is selected
|
|
||||||
p_name = input("Name > ")
|
|
||||||
elif program.lower() == "x":
|
|
||||||
print("- (1): Opens a new, empty window of this program")
|
print("- (1): Opens a new, empty window of this program")
|
||||||
print("- (2): Opens the window. You have to open the application first and set it up to the desired state to have it work.")
|
print("- (2): Opens the window. You have to open the application first and set it up to the desired state to have it work.")
|
||||||
print("- (3): Opens an identical but new window of what you already have. The program can be closed, but you must set it up to the desired state before closing it.")
|
print("- (3): Opens an identical but new window of what you already have. The program can be closed, but you must set it up to the desired state before closing it.")
|
||||||
print("- (4): Enter a path to the program. This only opens the program and requires you to do research on the program behavior when opened. I am still verifying if you need to enter \"\\\\\" for each \\.")
|
print("- (4): Enter a path to the program. This only opens the program and requires you to do research on the program behavior when opened.")
|
||||||
print("- (5): Opens the specified chrome tab. This method is newly developed and is a bit slower to respond, but can precisely open any tab in chrome.")
|
print("- (5): Opens the specified Chrome tab. This method is newly developed and is a bit slower to respond, but can precisely open any tab in Chrome.")
|
||||||
print("- (6): Specifies a window name. Partial names (wildcards) are default.")
|
print("- (6): Specifies a window name. Partial names (wildcards) are default.")
|
||||||
|
print()
|
||||||
|
|
||||||
elif program.lower() == "y":
|
# ---------- Main ---------- #
|
||||||
if testmode == False:
|
testmode = False
|
||||||
testmode == True
|
def main():
|
||||||
print("Test mode set to True.\n")
|
global testmode
|
||||||
main()
|
while True:
|
||||||
else:
|
print("=" * 80)
|
||||||
testmode == False
|
print(f"Interceptor APS (Active Protection System) Alpha-3| TESTMODE: {testmode}")
|
||||||
main()
|
print("-" * 80)
|
||||||
else:
|
print("Choose a cover app to open:")
|
||||||
pass # All other options, if selected, are already stored in program by this time
|
print("[1] Chrome (note 1)")
|
||||||
|
print("[2] Edge (note 1)")
|
||||||
|
print("[3] Adobe Illustrator (note 2)")
|
||||||
|
print("[4] Onenote (note 3)")
|
||||||
|
print("[5] Enter a path (note 4)")
|
||||||
|
print("[6] Specify Chrome Tab Number (note 5)")
|
||||||
|
print("[7] Specify Window Name (note 6)\n")
|
||||||
|
print("[x] Help (w/notes)")
|
||||||
|
print("[y] Toggle test mode", end = "\n\n")
|
||||||
|
print("[c] Exit")
|
||||||
|
program = input("Enter your option > ")
|
||||||
|
|
||||||
# Begin the watching process.
|
if program.isdigit():
|
||||||
|
if int(program) >= 1 and int(program) <= 4:
|
||||||
|
print(f"Option {program} selected. Watching...")
|
||||||
try:
|
try:
|
||||||
watchresults = file_watch(testmode)
|
file_watch(testmode)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Canceled by user.")
|
print("User cancelled file watch.")
|
||||||
main()
|
except Exception as e:
|
||||||
|
print(f"File watch error: {e}")
|
||||||
|
minimize()
|
||||||
|
launch_cover(program)
|
||||||
|
|
||||||
# If it advances to below then there must have been a file change. (VERIFY)
|
if program == "5": # If path is selected (I doubt that)
|
||||||
if program == "0": # If we chose path
|
p_path = input("Enter full path >")
|
||||||
|
print("Path selected. Watching...", end = " ")
|
||||||
|
try:
|
||||||
|
file_watch(testmode)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("User cancelled file watch.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"File watch error: {e}")
|
||||||
|
print("File change detected!")
|
||||||
minimize()
|
minimize()
|
||||||
launch_cover_path(p_path) # VERIFY IF DOUBLE ESCAPES ARE NEEDED WHEN PATH IS FIRST ENTERED BY USER
|
launch_cover_path(p_path) # VERIFY IF DOUBLE ESCAPES ARE NEEDED WHEN PATH IS FIRST ENTERED BY USER
|
||||||
elif program == "-1": # If we chose name
|
|
||||||
|
elif program == "6":
|
||||||
|
tabs_no = input("Tab number > ")
|
||||||
|
if tabs_no.isdigit():
|
||||||
|
print(f"Tab {tabs_no} selected. Watching...", end = " ")
|
||||||
|
try:
|
||||||
|
file_watch(testmode)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("User cancelled file watch.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"File watch error: {e}")
|
||||||
|
print("File change detected!")
|
||||||
|
minimize()
|
||||||
|
specific_tab("chrome", int(tabs_no))
|
||||||
|
else:
|
||||||
|
print("Error: Not a digit")
|
||||||
|
pass
|
||||||
|
|
||||||
|
elif program == "7": # If name is chosen
|
||||||
|
p_name = input("Name of window > ")
|
||||||
|
print(f"Window \"{p_name}\" selected. Watching...", end = " ")
|
||||||
|
try:
|
||||||
|
file_watch(testmode)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("User cancelled file watch.")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"File watch error: {e}")
|
||||||
|
print("File change detected!")
|
||||||
minimize()
|
minimize()
|
||||||
bring_to_front(p_name)
|
bring_to_front(p_name)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
minimize()
|
print(f"Error: Option \"{program}\" selected and passed isdigit() criteria, but did not get selected")
|
||||||
launch_cover(program) # Other options must be string numbers 1-4
|
|
||||||
|
elif program.isalpha():
|
||||||
|
if program.lower() == "x":
|
||||||
|
help_section()
|
||||||
|
|
||||||
|
elif program.lower() == "y":
|
||||||
|
testmode = not testmode
|
||||||
|
print(f"Test mode set to {testmode}")
|
||||||
|
elif program.lower() == "c":
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print(f"Error: Option \"{program}\" selected and passed isalpha() criteria, but did not get selected")
|
||||||
|
else:
|
||||||
|
print("Error: Not an option.")
|
||||||
|
|
||||||
|
|
||||||
# ---------- Running the code ---------- #
|
# ---------- Main-main ---------- #
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user