From fac9e155dd37675218577eb805b946264978e1ad Mon Sep 17 00:00:00 2001 From: Tareq Date: Thu, 8 Aug 2024 19:43:39 +0600 Subject: [PATCH 1/3] added the ZeuZ_Screenshot_Helper file --- Apps/Screenshot/ZeuZ_Screenshot_Helper.py | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Apps/Screenshot/ZeuZ_Screenshot_Helper.py diff --git a/Apps/Screenshot/ZeuZ_Screenshot_Helper.py b/Apps/Screenshot/ZeuZ_Screenshot_Helper.py new file mode 100644 index 000000000..ccefbfd18 --- /dev/null +++ b/Apps/Screenshot/ZeuZ_Screenshot_Helper.py @@ -0,0 +1,80 @@ +from pynput import mouse +import pyautogui as gui +from pathlib import Path +import os +import time +from PIL import Image +import json +import argparse + + +mouse_click_counter = 0 +coords = [] + +# function to get the coordinate once a right click occurs and append them in the coords list +def on_click(x, y, button, pressed): + global mouse_click_counter, coords + if pressed: + if button == mouse.Button.right: + mouse_click_counter += 1 + coords.append([x,y]) + print(f"Mouse clicked at ({x}, {y})") + + +# function to take a screenshot according to the coordinates and save the image +def take_partial_screenshot(left, top, right, bottom, path=None): + if path is None: + home_path = str(Path.home()) + downloads_folder = os.path.join(home_path, "Downloads") + file_format = "%Y_%m_%d_%H-%M-%S" + file_name = time.strftime(file_format) + ".png" + if os.path.exists(downloads_folder): + path = os.path.join(downloads_folder, file_name) + gui.screenshot(path) + im = Image.open(path) + im1 = im.crop((left, top, right, bottom)) + im1.save(path) + return path + + +def main(name, path=None): + try: + global coords + mouse_listener = None + + parser = argparse.ArgumentParser() + parser.add_argument("name", type=str, help="Enter the name of the tester") + parser.add_argument("--path", type=str, help="The path to folder where the image will be saved. Example E:\Automations Solutionz\GeoSoftware\image1.png. Default is the Download folder") + + print("The program has started...") + mouse_listener = mouse.Listener(on_click=on_click) + mouse_listener.start() + while mouse_click_counter < 2: + pass + mouse_listener.stop() + + left = coords[0][0] + top = coords[0][1] + right = coords[1][0] + bottom = coords[1][1] + attachment_path = take_partial_screenshot(left, top, right, bottom, path) + + data = { + name:{ + "coords": [left, top, right-left, bottom-top], + "attachment_path": attachment_path + } + } + json_str = json.dumps(data, indent=4) + print(json_str) + except Exception as e: + if mouse_listener: + mouse_listener.stop() + print(e) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("name", type=str, help="Enter the name of the tester") + parser.add_argument("--path", type=str, help="The path to folder where the image will be saved. Example E:\Automations Solutionz\GeoSoftware\image1.png. Default is the Download folder") + args = parser.parse_args() + main(args.name, args.path) \ No newline at end of file From ba429508fc7a76dc6fce80c284c6918eb9179c07 Mon Sep 17 00:00:00 2001 From: Tareq Date: Thu, 8 Aug 2024 20:37:50 +0600 Subject: [PATCH 2/3] added the pynput library in requirements file --- requirements-linux.txt | 3 ++- requirements-mac.txt | 3 ++- requirements-win.txt | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements-linux.txt b/requirements-linux.txt index cb0c3b181..7d209b2bd 100644 --- a/requirements-linux.txt +++ b/requirements-linux.txt @@ -57,4 +57,5 @@ pandas pyperclip thefuzz backports-datetime-fromisoformat; python_version < '3.11' -google-cloud-storage \ No newline at end of file +google-cloud-storage +pynput \ No newline at end of file diff --git a/requirements-mac.txt b/requirements-mac.txt index 741ef304b..23d066977 100644 --- a/requirements-mac.txt +++ b/requirements-mac.txt @@ -61,4 +61,5 @@ pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' thefuzz -google-cloud-storage \ No newline at end of file +google-cloud-storage +pynput \ No newline at end of file diff --git a/requirements-win.txt b/requirements-win.txt index 9043b8301..a7fc2d669 100644 --- a/requirements-win.txt +++ b/requirements-win.txt @@ -71,4 +71,5 @@ pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' thefuzz -google-cloud-storage \ No newline at end of file +google-cloud-storage +pynput \ No newline at end of file From 5865d60dbdae6868a5c15c48fd7dcf2303e449be Mon Sep 17 00:00:00 2001 From: Tareq Date: Sun, 11 Aug 2024 12:19:04 +0600 Subject: [PATCH 3/3] comments added to screenshot file --- Apps/Screenshot/ZeuZ_Screenshot_Helper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Apps/Screenshot/ZeuZ_Screenshot_Helper.py b/Apps/Screenshot/ZeuZ_Screenshot_Helper.py index ccefbfd18..f513b9170 100644 --- a/Apps/Screenshot/ZeuZ_Screenshot_Helper.py +++ b/Apps/Screenshot/ZeuZ_Screenshot_Helper.py @@ -47,6 +47,10 @@ def main(name, path=None): parser.add_argument("--path", type=str, help="The path to folder where the image will be saved. Example E:\Automations Solutionz\GeoSoftware\image1.png. Default is the Download folder") print("The program has started...") + print("Click the Right mouse button on the top-left point of the screen which will be the starting point of the screenshot") + print("Click the Right mouse button on the bottom-right point of the screen which will be the end point of the screenshot") + print("If no --path parameter is provided the image will be saved in the Download folder") + mouse_listener = mouse.Listener(on_click=on_click) mouse_listener.start() while mouse_click_counter < 2: