appshwnd


Nameappshwnd JSON
Version 0.11 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/appshwnd
Summaryincludes functions for finding windows based on various attributes, getting information about visible and invisible windows, and making window names unique
upload_time2023-05-10 05:59:32
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords ctypes hwnd search windows
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # appshwnd

This module provides utilities for finding and manipulating windows in Windows OS. It includes functions for finding windows based on various attributes,  getting information about visible and invisible windows, and making window names unique (e.g. With FFmpeg, you can record a window, but you have to pass the title of the Window which causes problems if there are duplicates. )

## pip install appshwnd


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


### Functions
```python
FUNCTIONS
    find_window_and_make_best_window_unique(searchdict: dict, timeout: float | int = 5, make_unique: bool = True, *args, **kwargs)
            Search for the window that matches the given criteria dictionary and makes its window title unique (if desired).
        Args:
            searchdict (dict): The dictionary that contains the search criteria for the window.
            timeout (float or int): The time in seconds to wait for making the window unique. Defaults to 5.
            make_unique (bool): Whether to make the window unique or not. Defaults to True.
            *args: Passed to re.search .
            **kwargs: Passed to re.search
        Returns:
            A tuple of best windows, best window, hwnd, start window text, updated window text, and revert name function.
    
    get_invisible_and_visible_windows()
            Get information about both visible and invisible windows.
        Args:
            None
        Returns:
            A list of WindowInfo objects for both visible and invisible windows.
    
    get_invisible_windows()
            Get information about invisible windows only.
        Args:
            None
        Returns:
            A list of WindowInfo objects for invisible windows only.
    
    get_visible_windows()
            Get information about visible windows only.
        Args:
            None
        Returns:
            A list of WindowInfo objects for visible windows only.
    
    time(...)
        time() -> floating point number
        
        Return the current time in seconds since the Epoch.
        Fractions of a second may be present if the system clock provides them.



# A dictionary that contains all possible search criteria for finding a window. 
# You can pass as many attributes as you want. The window with the most matches wins. 
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",
}

from appshwnd import ( find_window_and_make_best_window_unique,
 get_invisible_and_visible_windows,
 get_invisible_windows,
 get_visible_windows,
 get_window_infos,)
 
 
# Find the window without changing the window title 
(
    bestwindows,  # most matches = first place
    bestwindow,  # WindowInfo object
    hwnd,  # 132762
    startwindowtext,  # 'Default IME'
    updatedwindowtext,  # 'Default IME' (no difference, because of make_unique=False)
    revertnamefunction,  # restore the original name
) = find_window_and_make_best_window_unique(
    searchdict, timeout=5, make_unique=False, flags=re.I
)

# Example search for Notepad 


get_visible_windows()
....
WindowInfo(pid=8896, title='Notepad', windowtext='*Untitled - Notepad', hwnd=2034552, length=20, tid=2772, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(745, 1638, 324, 1058), dim_win=(893, 734), class_name='Notepad', path='C:\\Windows\\System32\\notepad.exe'),
....
WindowInfo(pid=16852, title='Notepad', windowtext='*Untitled - Notepad', hwnd=657206, length=20, tid=16876, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(475, 1368, 219, 953), dim_win=(893, 734), class_name='Notepad', path='C:\\Windows\\System32\\notepad.exe')]
....


searchdict = {
    "title": "Notepad",
    "windowtext_re": r"\*+",
    'path_re': '.*notepad.exe.*'
}

# Find the window and make it unique
(
    bestwindows,  # most matches = first place
    bestwindow,  # WindowInfo object
    hwnd,  # window handle
    startwindowtext,  # current window text
    updatedwindowtext,  # updated window text
    revertnamefunction,  # function to restore the original window text
) = find_window_and_make_best_window_unique(
    searchdict, timeout=5, make_unique=True, flags=re.I
)

# Example of restoring the original window text
startwindowtext  # '*Untitled - Notepad'
updatedwindowtext  # '*Untitled - Notepad ' (notice the space at the end - this window title is now unique)
revertnamefunction()  # Restore the old name
startwindowtext  # '*Untitled - Notepad'
updatedwindowtext  # '*Untitled - Notepad'

An example with FFmpeg (to make sure that you are recording the right window)
1) Make the window title unique 
2) Start FFmpeg in a subprocess (Popen)
3) After 2 seconds, you can change the name back: revertnamefunction()

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/appshwnd",
    "name": "appshwnd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ctypes,hwnd,search,windows",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a6/8d/c4f25bd07781bc1a30b45282eea05bd4b7f335d872fc2b1b28bba0c92fb9/appshwnd-0.11.tar.gz",
    "platform": null,
    "description": "# appshwnd\r\n\r\nThis module provides utilities for finding and manipulating windows in Windows OS. It includes functions for finding windows based on various attributes,  getting information about visible and invisible windows, and making window names unique (e.g. With FFmpeg, you can record a window, but you have to pass the title of the Window which causes problems if there are duplicates. )\r\n\r\n## pip install appshwnd\r\n\r\n\r\n#### ### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n\r\n### Functions\r\n```python\r\nFUNCTIONS\r\n    find_window_and_make_best_window_unique(searchdict: dict, timeout: float | int = 5, make_unique: bool = True, *args, **kwargs)\r\n            Search for the window that matches the given criteria dictionary and makes its window title unique (if desired).\r\n        Args:\r\n            searchdict (dict): The dictionary that contains the search criteria for the window.\r\n            timeout (float or int): The time in seconds to wait for making the window unique. Defaults to 5.\r\n            make_unique (bool): Whether to make the window unique or not. Defaults to True.\r\n            *args: Passed to re.search .\r\n            **kwargs: Passed to re.search\r\n        Returns:\r\n            A tuple of best windows, best window, hwnd, start window text, updated window text, and revert name function.\r\n    \r\n    get_invisible_and_visible_windows()\r\n            Get information about both visible and invisible windows.\r\n        Args:\r\n            None\r\n        Returns:\r\n            A list of WindowInfo objects for both visible and invisible windows.\r\n    \r\n    get_invisible_windows()\r\n            Get information about invisible windows only.\r\n        Args:\r\n            None\r\n        Returns:\r\n            A list of WindowInfo objects for invisible windows only.\r\n    \r\n    get_visible_windows()\r\n            Get information about visible windows only.\r\n        Args:\r\n            None\r\n        Returns:\r\n            A list of WindowInfo objects for visible windows only.\r\n    \r\n    time(...)\r\n        time() -> floating point number\r\n        \r\n        Return the current time in seconds since the Epoch.\r\n        Fractions of a second may be present if the system clock provides them.\r\n\r\n\r\n\r\n# A dictionary that contains all possible search criteria for finding a window. \r\n# You can pass as many attributes as you want. The window with the most matches wins. \r\nsearchdict = {\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\nfrom appshwnd import ( find_window_and_make_best_window_unique,\r\n get_invisible_and_visible_windows,\r\n get_invisible_windows,\r\n get_visible_windows,\r\n get_window_infos,)\r\n \r\n \r\n# Find the window without changing the window title \r\n(\r\n    bestwindows,  # most matches = first place\r\n    bestwindow,  # WindowInfo object\r\n    hwnd,  # 132762\r\n    startwindowtext,  # 'Default IME'\r\n    updatedwindowtext,  # 'Default IME' (no difference, because of make_unique=False)\r\n    revertnamefunction,  # restore the original name\r\n) = find_window_and_make_best_window_unique(\r\n    searchdict, timeout=5, make_unique=False, flags=re.I\r\n)\r\n\r\n# Example search for Notepad \r\n\r\n\r\nget_visible_windows()\r\n....\r\nWindowInfo(pid=8896, title='Notepad', windowtext='*Untitled - Notepad', hwnd=2034552, length=20, tid=2772, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(745, 1638, 324, 1058), dim_win=(893, 734), class_name='Notepad', path='C:\\\\Windows\\\\System32\\\\notepad.exe'),\r\n....\r\nWindowInfo(pid=16852, title='Notepad', windowtext='*Untitled - Notepad', hwnd=657206, length=20, tid=16876, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(475, 1368, 219, 953), dim_win=(893, 734), class_name='Notepad', path='C:\\\\Windows\\\\System32\\\\notepad.exe')]\r\n....\r\n\r\n\r\nsearchdict = {\r\n    \"title\": \"Notepad\",\r\n    \"windowtext_re\": r\"\\*+\",\r\n    'path_re': '.*notepad.exe.*'\r\n}\r\n\r\n# Find the window and make it unique\r\n(\r\n    bestwindows,  # most matches = first place\r\n    bestwindow,  # WindowInfo object\r\n    hwnd,  # window handle\r\n    startwindowtext,  # current window text\r\n    updatedwindowtext,  # updated window text\r\n    revertnamefunction,  # function to restore the original window text\r\n) = find_window_and_make_best_window_unique(\r\n    searchdict, timeout=5, make_unique=True, flags=re.I\r\n)\r\n\r\n# Example of restoring the original window text\r\nstartwindowtext  # '*Untitled - Notepad'\r\nupdatedwindowtext  # '*Untitled - Notepad ' (notice the space at the end - this window title is now unique)\r\nrevertnamefunction()  # Restore the old name\r\nstartwindowtext  # '*Untitled - Notepad'\r\nupdatedwindowtext  # '*Untitled - Notepad'\r\n\r\nAn example with FFmpeg (to make sure that you are recording the right window)\r\n1) Make the window title unique \r\n2) Start FFmpeg in a subprocess (Popen)\r\n3) After 2 seconds, you can change the name back: revertnamefunction()\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "includes functions for finding windows based on various attributes, getting information about visible and invisible windows, and making window names unique",
    "version": "0.11",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/appshwnd"
    },
    "split_keywords": [
        "ctypes",
        "hwnd",
        "search",
        "windows"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d2f6a12ccd8654406b334f1c737db1f01caa8feeb5d656ec86a397c9ced063ad",
                "md5": "7203810bb3b3b4e91d9ec4f57d0e38c0",
                "sha256": "4af988db2aba7cf4afc83adb02941563254ce7333a10ab078d63f0bb43d428a2"
            },
            "downloads": -1,
            "filename": "appshwnd-0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7203810bb3b3b4e91d9ec4f57d0e38c0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9353,
            "upload_time": "2023-05-10T05:59:29",
            "upload_time_iso_8601": "2023-05-10T05:59:29.588491Z",
            "url": "https://files.pythonhosted.org/packages/d2/f6/a12ccd8654406b334f1c737db1f01caa8feeb5d656ec86a397c9ced063ad/appshwnd-0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a68dc4f25bd07781bc1a30b45282eea05bd4b7f335d872fc2b1b28bba0c92fb9",
                "md5": "44bf584ab30859c90193b8ff4205657a",
                "sha256": "7b6d2d30eb4c3a0f667c57627ec91498731fba0365b674303c9839be2164bb4d"
            },
            "downloads": -1,
            "filename": "appshwnd-0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "44bf584ab30859c90193b8ff4205657a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6063,
            "upload_time": "2023-05-10T05:59:32",
            "upload_time_iso_8601": "2023-05-10T05:59:32.626602Z",
            "url": "https://files.pythonhosted.org/packages/a6/8d/c4f25bd07781bc1a30b45282eea05bd4b7f335d872fc2b1b28bba0c92fb9/appshwnd-0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-10 05:59:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "appshwnd",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "appshwnd"
}
        
Elapsed time: 0.25784s