handlescreenshots


Namehandlescreenshots JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/handlescreenshots
SummaryFast screenshots of (background) windows with, includes a find_window method
upload_time2024-03-23 05:49:37
maintainerNone
docs_urlNone
authorJohannes Fischer
requires_pythonNone
licenseMIT
keywords screenshots hwnd
VCS
bugtrack_url
requirements appshwnd numpy pywin32
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Fast screenshots of (background) windows with, includes a find_window method

## pip install handlescreenshots

### Tested against Windows 10 / Python 3.11 / Anaconda

## Win32WindowCapture Class

### The Win32WindowCapture class provides functionality to capture screenshots of windows on the Windows operating system. It leverages the pywin32 module, along with NumPy for image processing.

### Key Features:

#### Window Capture: 
Captures screenshots of specified (background) windows.

#### Window Cropping: 
Supports cropping of captured screenshots based on user-defined coordinates.

#### Frame Rate Display: 
Optionally displays frames per second (FPS) during capture.

#### Color Space Conversion: 
Supports conversion from BGR to RGB color space.

#### Error Handling: 
Implements robust error handling to ensure stability during capture operations.

```py
Class Methods:
__init__(self, hwnd: int, crop: Tuple[int, int, int, int] = (0, 0, 0, 0), show_fps: bool = False, brg_to_rgb: bool = False, ignore_exceptions: bool = True): Initializes a Win32WindowCapture instance with the specified window handle (hwnd). Additional parameters allow for customization of cropping, FPS display, color space conversion, and error handling.

get_window_position(self) -> Tuple[int, int, int, int]: Retrieves the position of the window and calculates its width and height.

get_screenshot(self, brg_to_rgb: Optional[bool] = None) -> Tuple[np.ndarray, Tuple[int, int, int, int], int, int, int, int]: Captures a screenshot of the window. Supports optional conversion from BGR to RGB color space.

__iter__(self) -> Iterable[Tuple[np.ndarray, Tuple[int, int, int, int], int, int, int, int, int, int]]: Implements an iterator that continuously captures screenshots of the window.
```
The find_window method provides a convenient way to locate windows based on various criteria defined in the searchdict parameter. 
This method offers several advantages:

Flexibility: By specifying different search parameters such as process ID, window title, window text, coordinates, class name, etc., users can locate windows in a variety of ways. This flexibility allows for precise window identification in diverse scenarios.

Customization: The searchdict parameter allows users to customize their search criteria according to their specific requirements. This customization empowers users to tailor window identification to the unique characteristics of their applications.

## find_window

```py

    find_window(searchdict: Dict[str, Union[int, str, Tuple[int, int, int, int]]]) -> Dict[str, Union[int, str, Tuple[int, int, int, int]]]: Static method to locate windows based on specified search parameters. Returns information about the best-matching window.
        all searchdict options:
        searchdict = {
            "pid": 1004,
            "pid_re": "^1.*",
            "title": "IME",
            "title_re": "IM?E",
            "windowtext": "Default IME",
            "windowtext_re": r"Default\s*IME",
            "hwnd": 197666,
            "hwnd_re": r"\d+",
            "length": 12,
            "length_re": "[0-9]+",
            "tid": 6636,
            "tid_re": r"6\d+36",
            "status": "invisible",
            "status_re": "(?:in)?visible",
            "coords_client": (0, 0, 0, 0),
            "coords_client_re": r"\([\d,\s]+\)",
            "dim_client": (0, 0),
            "dim_client_re": "(1?0, 0)",
            "coords_win": (0, 0, 0, 0),
            "coords_win_re": r"\)$",
            "dim_win": (0, 0),
            "dim_win_re": "(1?0, 0)",
            "class_name": "IME",
            "class_name_re": "I?ME$",
            "path": "C:\\Windows\\ImmersiveControlPanel\\SystemSettings.exe",
            "path_re": "SystemSettings.exe",
        }
```

## How to use it 

```py
from handlescreenshots import Win32WindowCapture
import cv2
import time 
searchdict = {"windowtext_re": r".*Bluestacks.*", "path_re": ".*HD-Player.*"}
bestwindow = Win32WindowCapture.find_window(searchdict)
print(bestwindow)
print(bestwindow["hwnd_of_best_window"])
try:
    for pic in Win32WindowCapture(
        bestwindow["hwnd_of_best_window"],
        crop=(100, 20, 30, 40),
        show_fps=False,
        brg_to_rgb=False,
        ignore_exceptions=True,
    ):
        print(
            "window_rect_not_cropped",
            "offset_left",
            "offset_top",
            "w",
            "h",
            "end_x",
            "end_y",
            pic[1:],
            end="                             \r",
        )
        cv2.imshow(str(bestwindow["window_text_of_best_window"]), pic[0])
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
except KeyboardInterrupt:
    try:
        time.sleep(1)
    except: 
        pass 
cv2.destroyAllWindows()

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/handlescreenshots",
    "name": "handlescreenshots",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "screenshots, hwnd",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/b3/bc46b6a1be7f31c1caa196d9e8f0fa54fdd1fce432d07fc54b0b281717a9/handlescreenshots-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Fast screenshots of (background) windows with, includes a find_window method\r\n\r\n## pip install handlescreenshots\r\n\r\n### Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n## Win32WindowCapture Class\r\n\r\n### The Win32WindowCapture class provides functionality to capture screenshots of windows on the Windows operating system. It leverages the pywin32 module, along with NumPy for image processing.\r\n\r\n### Key Features:\r\n\r\n#### Window Capture: \r\nCaptures screenshots of specified (background) windows.\r\n\r\n#### Window Cropping: \r\nSupports cropping of captured screenshots based on user-defined coordinates.\r\n\r\n#### Frame Rate Display: \r\nOptionally displays frames per second (FPS) during capture.\r\n\r\n#### Color Space Conversion: \r\nSupports conversion from BGR to RGB color space.\r\n\r\n#### Error Handling: \r\nImplements robust error handling to ensure stability during capture operations.\r\n\r\n```py\r\nClass Methods:\r\n__init__(self, hwnd: int, crop: Tuple[int, int, int, int] = (0, 0, 0, 0), show_fps: bool = False, brg_to_rgb: bool = False, ignore_exceptions: bool = True): Initializes a Win32WindowCapture instance with the specified window handle (hwnd). Additional parameters allow for customization of cropping, FPS display, color space conversion, and error handling.\r\n\r\nget_window_position(self) -> Tuple[int, int, int, int]: Retrieves the position of the window and calculates its width and height.\r\n\r\nget_screenshot(self, brg_to_rgb: Optional[bool] = None) -> Tuple[np.ndarray, Tuple[int, int, int, int], int, int, int, int]: Captures a screenshot of the window. Supports optional conversion from BGR to RGB color space.\r\n\r\n__iter__(self) -> Iterable[Tuple[np.ndarray, Tuple[int, int, int, int], int, int, int, int, int, int]]: Implements an iterator that continuously captures screenshots of the window.\r\n```\r\nThe find_window method provides a convenient way to locate windows based on various criteria defined in the searchdict parameter. \r\nThis method offers several advantages:\r\n\r\nFlexibility: By specifying different search parameters such as process ID, window title, window text, coordinates, class name, etc., users can locate windows in a variety of ways. This flexibility allows for precise window identification in diverse scenarios.\r\n\r\nCustomization: The searchdict parameter allows users to customize their search criteria according to their specific requirements. This customization empowers users to tailor window identification to the unique characteristics of their applications.\r\n\r\n## find_window\r\n\r\n```py\r\n\r\n    find_window(searchdict: Dict[str, Union[int, str, Tuple[int, int, int, int]]]) -> Dict[str, Union[int, str, Tuple[int, int, int, int]]]: Static method to locate windows based on specified search parameters. Returns information about the best-matching window.\r\n        all searchdict options:\r\n        searchdict = {\r\n            \"pid\": 1004,\r\n            \"pid_re\": \"^1.*\",\r\n            \"title\": \"IME\",\r\n            \"title_re\": \"IM?E\",\r\n            \"windowtext\": \"Default IME\",\r\n            \"windowtext_re\": r\"Default\\s*IME\",\r\n            \"hwnd\": 197666,\r\n            \"hwnd_re\": r\"\\d+\",\r\n            \"length\": 12,\r\n            \"length_re\": \"[0-9]+\",\r\n            \"tid\": 6636,\r\n            \"tid_re\": r\"6\\d+36\",\r\n            \"status\": \"invisible\",\r\n            \"status_re\": \"(?:in)?visible\",\r\n            \"coords_client\": (0, 0, 0, 0),\r\n            \"coords_client_re\": r\"\\([\\d,\\s]+\\)\",\r\n            \"dim_client\": (0, 0),\r\n            \"dim_client_re\": \"(1?0, 0)\",\r\n            \"coords_win\": (0, 0, 0, 0),\r\n            \"coords_win_re\": r\"\\)$\",\r\n            \"dim_win\": (0, 0),\r\n            \"dim_win_re\": \"(1?0, 0)\",\r\n            \"class_name\": \"IME\",\r\n            \"class_name_re\": \"I?ME$\",\r\n            \"path\": \"C:\\\\Windows\\\\ImmersiveControlPanel\\\\SystemSettings.exe\",\r\n            \"path_re\": \"SystemSettings.exe\",\r\n        }\r\n```\r\n\r\n## How to use it \r\n\r\n```py\r\nfrom handlescreenshots import Win32WindowCapture\r\nimport cv2\r\nimport time \r\nsearchdict = {\"windowtext_re\": r\".*Bluestacks.*\", \"path_re\": \".*HD-Player.*\"}\r\nbestwindow = Win32WindowCapture.find_window(searchdict)\r\nprint(bestwindow)\r\nprint(bestwindow[\"hwnd_of_best_window\"])\r\ntry:\r\n    for pic in Win32WindowCapture(\r\n        bestwindow[\"hwnd_of_best_window\"],\r\n        crop=(100, 20, 30, 40),\r\n        show_fps=False,\r\n        brg_to_rgb=False,\r\n        ignore_exceptions=True,\r\n    ):\r\n        print(\r\n            \"window_rect_not_cropped\",\r\n            \"offset_left\",\r\n            \"offset_top\",\r\n            \"w\",\r\n            \"h\",\r\n            \"end_x\",\r\n            \"end_y\",\r\n            pic[1:],\r\n            end=\"                             \\r\",\r\n        )\r\n        cv2.imshow(str(bestwindow[\"window_text_of_best_window\"]), pic[0])\r\n        if cv2.waitKey(1) & 0xFF == ord(\"q\"):\r\n            break\r\nexcept KeyboardInterrupt:\r\n    try:\r\n        time.sleep(1)\r\n    except: \r\n        pass \r\ncv2.destroyAllWindows()\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fast screenshots of (background) windows with, includes a find_window method",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/handlescreenshots"
    },
    "split_keywords": [
        "screenshots",
        " hwnd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c38a99cd3be7eacfc74abf1bd473989ab12b35035af01a74ff08c888ceb4fed6",
                "md5": "6650eec209fa05c780bda4e7a05e06cf",
                "sha256": "70350e8f40af90eb991814f9a4c101243f46e14560b7c38832759428cb2ad9b9"
            },
            "downloads": -1,
            "filename": "handlescreenshots-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6650eec209fa05c780bda4e7a05e06cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 25168,
            "upload_time": "2024-03-23T05:49:36",
            "upload_time_iso_8601": "2024-03-23T05:49:36.010970Z",
            "url": "https://files.pythonhosted.org/packages/c3/8a/99cd3be7eacfc74abf1bd473989ab12b35035af01a74ff08c888ceb4fed6/handlescreenshots-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7eb3bc46b6a1be7f31c1caa196d9e8f0fa54fdd1fce432d07fc54b0b281717a9",
                "md5": "b5cb75b5584b25244d85811c067e12de",
                "sha256": "69aaeec05f9b6fba1395c415a38c72d90aebc5e188c22925040534981f165fbf"
            },
            "downloads": -1,
            "filename": "handlescreenshots-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "b5cb75b5584b25244d85811c067e12de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24889,
            "upload_time": "2024-03-23T05:49:37",
            "upload_time_iso_8601": "2024-03-23T05:49:37.954362Z",
            "url": "https://files.pythonhosted.org/packages/7e/b3/bc46b6a1be7f31c1caa196d9e8f0fa54fdd1fce432d07fc54b0b281717a9/handlescreenshots-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-23 05:49:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "handlescreenshots",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "appshwnd",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "pywin32",
            "specs": []
        }
    ],
    "lcname": "handlescreenshots"
}
        
Elapsed time: 0.32401s