From b8487a0bc46c3acef345de049b41e75b277e4943 Mon Sep 17 00:00:00 2001 From: P7MJ Date: Fri, 6 Feb 2026 19:50:52 -0500 Subject: [PATCH] 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. --- ...eptor-aps-a-2.py => interceptor-aps-a-3.py | 177 ++++++++++-------- 1 file changed, 100 insertions(+), 77 deletions(-) rename interceptor-aps-a-2.py => interceptor-aps-a-3.py (52%) diff --git a/interceptor-aps-a-2.py b/interceptor-aps-a-3.py similarity index 52% rename from interceptor-aps-a-2.py rename to interceptor-aps-a-3.py index 609e25a..f6e5c84 100644 --- a/interceptor-aps-a-2.py +++ b/interceptor-aps-a-3.py @@ -14,15 +14,15 @@ from termcolor import colored # |___|_| |_|\__\___|_| \___\___| .__/ \__\___/|_| /_/ \_\_| |____/ # |_| APS Version Alpha-2 by P7MJ -# ---------- CONFIGURATION ---------- # +# ---------- Monitor Path ---------- # 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 p_name = "" p_path = "" # used only if program = 0. -# ---------- BRING TO FRONT ---------- # +# ---------- Bring to front ---------- # def bring_to_front(window_title): time.sleep(0.5) try: @@ -38,7 +38,7 @@ def bring_to_front(window_title): except Exception as e: print(colored(f"Error: {e}", 'red')) -# ---------- FILE WATCHER ---------- # +# ---------- File watch ---------- # def file_watch(iftest): print("=" * 80) print("Monitoring changes in " + monitor_path + ".") @@ -54,14 +54,14 @@ def file_watch(iftest): except Exception as e: print(colored(f"File Watch Error: {e}", 'red')) -# ---------- MINIMIZE ---------- # +# ---------- Minimize ---------- # def minimize(): print("=" * 80) print("Minimizing all windows...", end = " ") pyautogui.hotkey('win', 'd') print("Completed.") -# ---------- LAUNCH COVER PROGRAM ---------- # +# ---------- Launch cover (program) ---------- # def launch_cover(programs): time.sleep(0.5) print("=" * 80) @@ -105,7 +105,7 @@ def launch_cover(programs): else: print(colored("Error: Invalid Cover App Specified.", 'red')) -# ---------- LAUNCH COVER PROGRAM PATH ---------- # +# ---------- Launch cover (program) path ---------- # def launch_cover_path(path): print("Launching custom path...", end = " ") time.sleep(0.5) @@ -114,7 +114,7 @@ def launch_cover_path(path): ) print("Launched custom path.") -# ---------- LAUNCH SPECIFIC CHROME TAB ---------- # +# ---------- Specific Chrome tab ---------- # def specific_tab(browser, tab_no): time.sleep(0.5) try: @@ -142,89 +142,112 @@ def specific_tab(browser, tab_no): print(colored("ERROR: Window not found", 'red')) except Exception as e: print(colored(f"Specific-Tab Error: {e}", 'red')) - -# ---------- Main Process ---------- # -def main(): - global p_name, p_path, testmode - testmode = False +# ---------- Help Section ---------- # +def help_section(): + print() + 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("- (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.") + 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() +# ---------- Main ---------- # +testmode = False +def main(): + global testmode while True: - print() print("=" * 80) - print(f"Interceptor APS (Active Protection System) ===== TESTMODE: {testmode}") + print(f"Interceptor APS (Active Protection System) Alpha-3| 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") + 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 > ") - - 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: + + if program.isdigit(): + if int(program) >= 1 and int(program) <= 4: + print(f"Option {program} selected. Watching...") + try: + file_watch(testmode) + except KeyboardInterrupt: + print("User cancelled file watch.") + except Exception as e: + print(f"File watch error: {e}") + minimize() + launch_cover(program) + + if program == "5": # If path is selected (I doubt that) + 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() + launch_cover_path(p_path) # VERIFY IF DOUBLE ESCAPES ARE NEEDED WHEN PATH IS FIRST ENTERED BY USER + + elif program == "6": tabs_no = input("Tab number > ") if tabs_no.isdigit(): - pass + 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") - main() - watchresults = file_watch(testmode) # STILL TESTING Switch to false if finished!!! + 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() - 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("- (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("- (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("- (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.") - - elif program.lower() == "y": - if testmode == False: - testmode == True - print("Test mode set to True.\n") - main() + bring_to_front(p_name) + else: - testmode == False - main() + print(f"Error: Option \"{program}\" selected and passed isdigit() criteria, but did not get selected") + + 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: - pass # All other options, if selected, are already stored in program by this time - - # Begin the watching process. - try: - watchresults = file_watch(testmode) - except KeyboardInterrupt: - print("Canceled by user.") - main() + print("Error: Not an option.") - # If it advances to below then there must have been a file change. (VERIFY) - if program == "0": # If we chose path - minimize() - 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 - minimize() - bring_to_front(p_name) - else: - minimize() - launch_cover(program) # Other options must be string numbers 1-4 - - -# ---------- Running the code ---------- # + +# ---------- Main-main ---------- # if __name__ == "__main__": main() \ No newline at end of file