mrob95 / pyvda

Python module for manipulating Windows 10/11 windows and virtual desktops.
MIT License
90 stars 12 forks source link

Windows update KB5034765 completely broke pyvda #34

Closed phpjunkie420 closed 3 months ago

phpjunkie420 commented 8 months ago

Windows update KB5034765 completely broke pyvda.

Traceback (most recent call last):
  File "C:\Users\phpjunkie\Python\Scripts\firefox.pyw", line 5, in <module>
    from pyvda import AppView, VirtualDesktop
  File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\__init__.py", line 58, in <module>
    from .pyvda import (
  File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 20, in <module>
    managers = Managers()
               ^^^^^^^^^^
  File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\utils.py", line 55, in __init__
    self.manager_internal = get_vd_manager_internal()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\utils.py", line 41, in get_vd_manager_internal
    return _get_object(IVirtualDesktopManagerInternal, CLSID_VirtualDesktopManagerInternal)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\utils.py", line 30, in _get_object
    pServiceProvider.QueryService(
_ctypes.COMError: (-2147467262, 'No such interface supported', (None, None, None, 0, None))
phpjunkie420 commented 8 months ago

Sorry, I'm using Windows 11 Pro and I have Python 3.11.8 installed.

mrob95 commented 8 months ago

Thanks for reporting. The Windows APIs that pyvda uses are not documented/stable so this happens every so often.

I haven't had the update yet but when it happens I'll see what changed and fix it, or if you'd like you can see if you can find the new interface definition. I gave some instructions for this here https://github.com/mrob95/pyvda/issues/15#issuecomment-1145299809

phpjunkie420 commented 8 months ago

I'm back to this same issue with get_apps_by_z_order.

from pyvda import get_apps_by_z_order
from win32gui import GetWindowText

for window in get_apps_by_z_order():
    print(GetWindowText(window.hwnd))

generates the exception...

Traceback (most recent call last): File "C:\Users\phpjunkie\Python\Scripts\debug\debug5.py", line 4, in for window in get_apps_by_z_order(): ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 226, in get_apps_by_z_order if current_desktop and not view.is_on_desktop(vd): ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 193, in is_on_desktop return (self.desktop_id == desktop.id) or self.is_pinned() or self.is_app_pinned() ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 144, in is_app_pinned return managers.pinned_apps.IsAppIdPinned(self.app_id) ^^^^^^^^^^^ File "C:\Users\phpjunkie\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 62, in app_id return self._view.GetAppUserModelId() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _ctypes.COMError: (-2147023728, 'Element not found.', (None, None, None, 0, None))

For some reason it is having problems with pinned apps, cause this works...

from pyvda import VirtualDesktop as Desktop
from win32gui import GetWindowText

window = Desktop.current().apps_by_z_order(include_pinned = False)[0]
print(GetWindowText(window.hwnd))

Generates the title from PyCharm...

Scripts [C:/Users/*****/Python/Scripts] – …\debug\debug5.py

phpjunkie420 commented 8 months ago

It has something to do with the last update v0.4.1 'cause v0.4.0 works just fine.

peterder72 commented 8 months ago

Also broken for me after updating at 0.4.1, albeit with a slightly different error:

NotImplementedError: Interface IVirtualDesktopManagerInternal not supported for windows version 10.0.22621, platform version 10.0.22621. Please open an issue at https://github.com/mrob95/pyvda/issues.

I didn't yet run the tool to fetch the GUIDs on my machine, but maybe the dumps found here could help

mrob95 commented 8 months ago

Thanks for the reports. I'll work on this this weekend. The version/build numbers reported by windows are sufficiently unreliable that I think it will be better to just try all of the interfaces and see whether one works, which seems to be what Microsoft recommend doing.

stdedos commented 8 months ago

Also, for people feeling like contributing:

mrob95 commented 8 months ago

@peterder72 @phpjunkie420 @stdedos I have just pushed a big change. It would be great if you could run the tests on the master branch on your machines and see whether it makes things better, worse, or no change. I'll test on an up-to-date win11 laptop tomorrow.

stdedos commented 8 months ago

I have just pushed a big change. It would be great if you could run the tests on the master branch on your machines and see whether it makes things better, worse, or no change. I'll test on an up-to-date win11 laptop tomorrow.

Unfortunately, I can do it late tomorrow the earliest

mrob95 commented 8 months ago

Unfortunately, I can do it late tomorrow the earliest

That's fine, no rush, any testing is appreciated 👍

phpjunkie420 commented 8 months ago

@peterder72 @phpjunkie420 @stdedos I have just pushed a big change. It would be great if you could run the tests on the master branch on your machines and see whether it makes things better, worse, or no change. I'll test on an up-to-date win11 laptop tomorrow.

I looked at the releases and it shows 0.4.1 which is the release that generated the exception I posted.

peterder72 commented 8 months ago

@mrob95 I seem to be still having the same issue with the new master, I'll try getting the exact interface UUID tomorrow

mrob95 commented 8 months ago

@mrob95 I seem to be still having the same issue with the new master, I'll try getting the exact interface UUID tomorrow

Thanks, any information you could give would be great - has it worked on a previous version of pyvda? Theoretically nothing should have changed relating to version 10.0.22621

phpjunkie420 commented 8 months ago

@mrob95 I seem to be still having the same issue with the new master, I'll try getting the exact interface UUID tomorrow

Thanks, any information you could give would be great - has it worked on a previous version of pyvda? Theoretically nothing should have changed relating to version 10.0.22621

I don't know what changed from 0.4.0 to 0.4.1, 'case 0.4.0 works just fine. I did a bit of testing to figure out the source of the problem and it has something to do with pinned apps.

phpjunkie420 commented 8 months ago

I use a custom start menu on all of my computers, and a hacked taskbar to revert back to the kinda classic taskbar on windows 11 so I'm not sure of what a pinned app is: if it is 'pin to taskbar,' like the old school quick launch apps on the taskbar, which is what I'm using, or if it is the 'pin to start' on the start menu itself. Screenshot 2024-02-25 110251

My next comment is off topic. I think that the windows start menu, from windows 11 all the way down to windows vista, and the taskbar in windows 11 is junk ass bull****. I really can't see why they would lock the height of the taskbar or make it less customizable. I don't like combined grouping of apps, and I like being able to see the titles of the apps on my taskbar.

peterder72 commented 8 months ago

@mrob95 Everything worked for a long time before, I think I was even on 0.3.X earlier. After a Windows update all my pyvda scripts started crashing, an update to 0.4.1 also didn't help

peterder72 commented 8 months ago

@mrob95 Just checked, now makes sense why the fix doesn't work. The interface is not there at all... image

stdedos commented 8 months ago

Sorry for the tangent: @phpjunkie420, what are those widgets top-right? 🤩

stdedos commented 8 months ago

On the matter-at-hand: If you really go the https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexw#remarks avenue, I think you need to re-wire the library 😅

  1. Create a class that is able to do everything
  2. Probe-for-config, and instantiate the interfaces "as available"
  3. When users probe for a functionality, accept / throw NotImplementedError as available.
    1. ... hopefully allow the lib-users to handle "such a situation" gracefully (via a strict=True, or graceful=True)
  4. Attempt to be helpful to everyone:
    1. "Feature VirtualDesktop.name is not supported in $winver. Cause: GUID a-b-c-d is not available."
    2. OleView is an amazing tool. But if you could implement a utils-class-func to search for "known GUID names" (e.g. IVirtualDesktop*), and print their associated GUID keys for debugging.
peterder72 commented 8 months ago

Alright, so I've looked into it a bit.

Apparently I was blind yesterday, and the error I got was about IVirtualDesktopManagerInternal2, not IVirtualDesktopManagerInternal, which actually succeeded after the latest fix. It also turned out I don't have any names associated with my COM interfaces anymore (or OleView doesn't show them on Windows 11, also possible), so I have to only deal with GUIDs, which is why I couldn't find anything in the screenshot I posted above.

I did some manual digging, and found the missing GUID for IVirtualDesktopManagerInternal2: 53F5CA0B-158F-4124-900C-057158060B27.

Manually changing the GUID in the library fixed all issues on my machine. The GUID seems to match with this dump

phpjunkie420 commented 8 months ago

Sorry for the tangent: @phpjunkie420, what are those widgets top-right? 🤩 Rainmeter, desktop customization tool kinda like conky for linux.

This is the skin I'm using. Gadgets: Gadgets for Rainmeter

phpjunkie420 commented 8 months ago

@mrob95 Everything worked for a long time before, I think I was even on 0.3.X earlier. After a Windows update all my pyvda scripts started crashing, an update to 0.4.1 also didn't help

downgrade to 0.4.0

pip install pyvda==0.4.0

stdedos commented 8 months ago

Broken for me as well:

/pyvda ((1a7591f...)|BISECTING)
$ git bisect good
fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d is the first bad commit
commit fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d
Author: Mike Roberts <mike.roberts.2k10@googlemail.com>
Date:   Mon Feb 26 13:57:14 2024 +0000

    fix catching of not implemented error when creating internal2

 pyvda/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
$ git bisect log
git bisect start
# status: waiting for both good and bad commits
# bad: [cd21c5dfc1f0da328e94281d4820da01382ad29e] Merge pull request #42 from mrob95/win11_fixes
git bisect bad cd21c5dfc1f0da328e94281d4820da01382ad29e
# status: waiting for good commit(s), bad commit known
# good: [8b67db68587292e19e596fa3f23ca3c78e18c581] bump version to 0.4.1
git bisect good 8b67db68587292e19e596fa3f23ca3c78e18c581
# good: [208a324b3849197d7165af7489d94b8a69718b0d] refactor: use feature detection to get build rather than relying on unreliable win32 api
git bisect good 208a324b3849197d7165af7489d94b8a69718b0d
# good: [200aa0487cc319203713ec4be10870f162413c16] improve no supported version error message
git bisect good 200aa0487cc319203713ec4be10870f162413c16
# bad: [764cfaaf44105b35d12d33122c453181c63a627a] fix com definitions for the latest win11
git bisect bad 764cfaaf44105b35d12d33122c453181c63a627a
# bad: [fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d] fix catching of not implemented error when creating internal2
git bisect bad fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d
# good: [1a7591fe24ace66c92c57102b4c8d97aeccad641] Merge pull request #41 from mrob95/feature-detection
git bisect good 1a7591fe24ace66c92c57102b4c8d97aeccad641
# first bad commit: [fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d] fix catching of not implemented error when creating internal2
stdedos commented 8 months ago

... git bisect run python -m pytest --cov-report term-missing --cov=pyvda tests/ gave a different result, FWIW

pyvda (master)
$ git bisect start HEAD v0.4.1

pyvda ((208a324...)|BISECTING)
$ git bisect run python -m pytest --cov-report term-missing --cov=pyvda tests/
running 'python' '-m' 'pytest' '--cov-report' 'term-missing' '--cov=pyvda' 'tests/'
...
=========================== short test summary info ===========================
ERROR tests/test_desktop_functions.py - _ctypes.COMError: (-2147023728, 'Ôï ó...
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.41s ===============================
af5dea86a2af1df4a4939154bfc7e69f10dc5e96 is the first bad commit
commit af5dea86a2af1df4a4939154bfc7e69f10dc5e96
Author: Mike Roberts <mike.roberts.2k10@googlemail.com>
Date:   Sun Feb 25 15:27:21 2024 +0000

    isort

 pyvda/__init__.py               |  8 ++++----
 pyvda/com_base.py               | 15 +++------------
 pyvda/com_defns.py              | 38 ++++++++++++++++----------------------
 pyvda/pyvda.py                  | 11 ++++-------
 pyvda/utils.py                  | 24 ++++++++++--------------
 tests/test_desktop_functions.py | 18 +++++++-----------
 6 files changed, 44 insertions(+), 70 deletions(-)
bisect found first bad commit

/pyvda ((af5dea8...)|BISECTING)
$ git bisect log
# bad: [cd21c5dfc1f0da328e94281d4820da01382ad29e] Merge pull request #42 from mrob95/win11_fixes
# good: [8b67db68587292e19e596fa3f23ca3c78e18c581] bump version to 0.4.1
git bisect start 'HEAD' 'v0.4.1'
# good: [208a324b3849197d7165af7489d94b8a69718b0d] refactor: use feature detection to get build rather than relying on unreliable win32 api
git bisect good 208a324b3849197d7165af7489d94b8a69718b0d
# bad: [200aa0487cc319203713ec4be10870f162413c16] improve no supported version error message
git bisect bad 200aa0487cc319203713ec4be10870f162413c16
# bad: [64ab622e6ca61530a9524e112f7676a5987bcb37] fix: type hints
git bisect bad 64ab622e6ca61530a9524e112f7676a5987bcb37
# bad: [af5dea86a2af1df4a4939154bfc7e69f10dc5e96] isort
git bisect bad af5dea86a2af1df4a4939154bfc7e69f10dc5e96
# first bad commit: [af5dea86a2af1df4a4939154bfc7e69f10dc5e96] isort
mrob95 commented 8 months ago

Alright, so I've looked into it a bit.

Apparently I was blind yesterday, and the error I got was about IVirtualDesktopManagerInternal2, not IVirtualDesktopManagerInternal, which actually succeeded after the latest fix. It also turned out I don't have any names associated with my COM interfaces anymore (or OleView doesn't show them on Windows 11, also possible), so I have to only deal with GUIDs, which is why I couldn't find anything in the screenshot I posted above.

I did some manual digging, and found the missing GUID for IVirtualDesktopManagerInternal2: 53F5CA0B-158F-4124-900C-057158060B27.

Manually changing the GUID in the library fixed all issues on my machine. The GUID seems to match with this dump

Thanks, could you try the latest master branch? I fixed a bug relating to this so hopefully that has caught it. If not I'll add the extra GUID.

mrob95 commented 8 months ago

Broken for me as well:

/pyvda ((1a7591f...)|BISECTING)
$ git bisect good
fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d is the first bad commit
commit fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d
Author: Mike Roberts <mike.roberts.2k10@googlemail.com>
Date:   Mon Feb 26 13:57:14 2024 +0000

    fix catching of not implemented error when creating internal2

 pyvda/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
$ git bisect log
git bisect start
# status: waiting for both good and bad commits
# bad: [cd21c5dfc1f0da328e94281d4820da01382ad29e] Merge pull request #42 from mrob95/win11_fixes
git bisect bad cd21c5dfc1f0da328e94281d4820da01382ad29e
# status: waiting for good commit(s), bad commit known
# good: [8b67db68587292e19e596fa3f23ca3c78e18c581] bump version to 0.4.1
git bisect good 8b67db68587292e19e596fa3f23ca3c78e18c581
# good: [208a324b3849197d7165af7489d94b8a69718b0d] refactor: use feature detection to get build rather than relying on unreliable win32 api
git bisect good 208a324b3849197d7165af7489d94b8a69718b0d
# good: [200aa0487cc319203713ec4be10870f162413c16] improve no supported version error message
git bisect good 200aa0487cc319203713ec4be10870f162413c16
# bad: [764cfaaf44105b35d12d33122c453181c63a627a] fix com definitions for the latest win11
git bisect bad 764cfaaf44105b35d12d33122c453181c63a627a
# bad: [fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d] fix catching of not implemented error when creating internal2
git bisect bad fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d
# good: [1a7591fe24ace66c92c57102b4c8d97aeccad641] Merge pull request #41 from mrob95/feature-detection
git bisect good 1a7591fe24ace66c92c57102b4c8d97aeccad641
# first bad commit: [fedcbc55679eeea19fe0e9f0a8b6d8bacba8553d] fix catching of not implemented error when creating internal2

On the latest master branch are you able to import the library at all? Could you run with debug logging enabled up until it fails and post the output?

stdedos commented 8 months ago
Jupyter QtConsole 5.5.1
Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.

import logging

# Set the global logging level
logging.basicConfig(level=logging.DEBUG)  # Set to DEBUG, INFO, WARNING, ERROR, or CRITICAL

# Now, all loggers will default to DEBUG level unless specified otherwise.
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:pyvda.build:Starting feature detection...
DEBUG:pyvda.build:Querying {4970BA3D-FD4E-4647-BEA3-D89076EF4B9C}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e145c50>
DEBUG:pyvda.build:Querying {A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612e145350>
DEBUG:pyvda.build:Querying {B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612e145c50>
DEBUG:pyvda.build:Querying {094AFE11-44F2-4BA0-976F-29A97E263EE0}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15e88 at 2612e145350>
DEBUG:pyvda.build:Querying {F31574D6-B682-4CDC-BD56-1827860ABEC6}... Success!
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16128 at 2612e145c50>
DEBUG:comtypes:Release <POINTER(IUnknown) ptr=0x2612ca15478 at 2612e145f50>
DEBUG:pyvda.build:Feature detection complete. Windows version is under 19041
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15d38 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca15a98 at 2612dd8aad0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca16828 at 2612e1463d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca15c58 at 2612e147050>
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15e18 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15088 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca15b08 at 2612e5cd4d0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca15d38 at 2612e5cfd50>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca16128 at 2612e5acc50>
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca14f38 at 2612e5cfed0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca15e18 at 2612e5ccdd0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca16128 at 2612e5cc050>

from pyvda import VirtualDesktop
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca14f38 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612e7020d0>
---------------------------------------------------------------------------
COMError                                  Traceback (most recent call last)
Cell In[2], line 1
----> 1 from pyvda import VirtualDesktop

File pyvda\pyvda\__init__.py:58
     55     _check_version()
     57 from ._version import __version__
---> 58 from .pyvda import (
     59     AppView,
     60     VirtualDesktop,
     61     get_apps_by_z_order,
     62     get_virtual_desktops,
     63     set_wallpaper_for_all_desktops,
     64 )

File pyvda\pyvda\pyvda.py:16
     13 ASFW_ANY = -1
     14 NULL_PTR = 0
---> 16 managers = Managers()
     19 class AppView():
     20     """
     21     A wrapper around an `IApplicationView` object exposing window functionality relating to:
     22 
   (...)
     26 
     27     """

File pyvda\pyvda\utils.py:66, in Managers.__init__(self)
     64 self.view_collection = get_view_collection()
     65 self.pinned_apps = get_pinned_apps()
---> 66 self.manager_internal2 = get_vd_manager_internal2()

File pyvda\pyvda\utils.py:50, in get_vd_manager_internal2()
     48 def get_vd_manager_internal2() -> Optional[IVirtualDesktopManagerInternal2]:
     49     try:
---> 50         return _get_object(IVirtualDesktopManagerInternal2, CLSID_VirtualDesktopManagerInternal) # type: ignore
     51     except NotImplementedError:
     52         return None

File pyvda\pyvda\utils.py:30, in _get_object(cls, clsid)
     26     pServiceProvider = CoCreateInstance(
     27         CLSID_ImmersiveShell, IServiceProvider, CLSCTX_LOCAL_SERVER
     28     )
     29     pObject = POINTER(cls)()
---> 30     pServiceProvider.QueryService( # type: ignore
     31         clsid or cls._iid_,
     32         cls._iid_,
     33         pObject,
     34     )
     35 except _ctypes.COMError as e:
     36     if e.text == "No such interface supported":

COMError: (-2147467262, 'Δεν υποστηρίζεται τέτοια διασύνδεση', (None, None, None, 0, None))

... it's not a friendly experience, to be blatantly honest. On a REPL, being spammed with DEBUG messages on tab-auto-completion, it feels just weird.

Do things after you are properly imported

mrob95 commented 8 months ago
Jupyter QtConsole 5.5.1
Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.

import logging

# Set the global logging level
logging.basicConfig(level=logging.DEBUG)  # Set to DEBUG, INFO, WARNING, ERROR, or CRITICAL

# Now, all loggers will default to DEBUG level unless specified otherwise.
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:pyvda.build:Starting feature detection...
DEBUG:pyvda.build:Querying {4970BA3D-FD4E-4647-BEA3-D89076EF4B9C}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e145c50>
DEBUG:pyvda.build:Querying {A3175F2D-239C-4BD2-8AA0-EEBA8B0B138E}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612e145350>
DEBUG:pyvda.build:Querying {B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612e145c50>
DEBUG:pyvda.build:Querying {094AFE11-44F2-4BA0-976F-29A97E263EE0}... Δεν υποστηρίζεται τέτοια διασύνδεση
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15e88 at 2612e145350>
DEBUG:pyvda.build:Querying {F31574D6-B682-4CDC-BD56-1827860ABEC6}... Success!
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16128 at 2612e145c50>
DEBUG:comtypes:Release <POINTER(IUnknown) ptr=0x2612ca15478 at 2612e145f50>
DEBUG:pyvda.build:Feature detection complete. Windows version is under 19041
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15d38 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca15a98 at 2612dd8aad0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca16828 at 2612e1463d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca15c58 at 2612e147050>
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15e18 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15088 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612e1470d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca15b08 at 2612e5cd4d0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca15d38 at 2612e5cfd50>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca16128 at 2612e5acc50>
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15a98 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca16828 at 2612dd713d0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopManagerInternal) ptr=0x2612ca14f38 at 2612e5cfed0>
DEBUG:comtypes:Release <POINTER(IApplicationViewCollection) ptr=0x2612ca15e18 at 2612e5ccdd0>
DEBUG:comtypes:Release <POINTER(IVirtualDesktopPinnedApps) ptr=0x2612ca16128 at 2612e5cc050>

from pyvda import VirtualDesktop
DEBUG:comtypes:CoInitializeEx(None, 2)
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca14f38 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca15478 at 2612e7020d0>
DEBUG:comtypes:Release <POINTER(IServiceProvider) ptr=0x2612ca156a8 at 2612e7020d0>
---------------------------------------------------------------------------
COMError                                  Traceback (most recent call last)
Cell In[2], line 1
----> 1 from pyvda import VirtualDesktop

File pyvda\pyvda\__init__.py:58
     55     _check_version()
     57 from ._version import __version__
---> 58 from .pyvda import (
     59     AppView,
     60     VirtualDesktop,
     61     get_apps_by_z_order,
     62     get_virtual_desktops,
     63     set_wallpaper_for_all_desktops,
     64 )

File pyvda\pyvda\pyvda.py:16
     13 ASFW_ANY = -1
     14 NULL_PTR = 0
---> 16 managers = Managers()
     19 class AppView():
     20     """
     21     A wrapper around an `IApplicationView` object exposing window functionality relating to:
     22 
   (...)
     26 
     27     """

File pyvda\pyvda\utils.py:66, in Managers.__init__(self)
     64 self.view_collection = get_view_collection()
     65 self.pinned_apps = get_pinned_apps()
---> 66 self.manager_internal2 = get_vd_manager_internal2()

File pyvda\pyvda\utils.py:50, in get_vd_manager_internal2()
     48 def get_vd_manager_internal2() -> Optional[IVirtualDesktopManagerInternal2]:
     49     try:
---> 50         return _get_object(IVirtualDesktopManagerInternal2, CLSID_VirtualDesktopManagerInternal) # type: ignore
     51     except NotImplementedError:
     52         return None

File pyvda\pyvda\utils.py:30, in _get_object(cls, clsid)
     26     pServiceProvider = CoCreateInstance(
     27         CLSID_ImmersiveShell, IServiceProvider, CLSCTX_LOCAL_SERVER
     28     )
     29     pObject = POINTER(cls)()
---> 30     pServiceProvider.QueryService( # type: ignore
     31         clsid or cls._iid_,
     32         cls._iid_,
     33         pObject,
     34     )
     35 except _ctypes.COMError as e:
     36     if e.text == "No such interface supported":

COMError: (-2147467262, 'Δεν υποστηρίζεται τέτοια διασύνδεση', (None, None, None, 0, None))

... it's not a friendly experience, to be blatantly honest. On a REPL, being spammed with DEBUG messages on tab-auto-completion, it feels just weird.

Do things after you are properly imported

Thank you. I think it was matching on the error message that was the problem, I have merged a fix.

mrob95 commented 8 months ago

On the matter-at-hand: If you really go the https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexw#remarks avenue, I think you need to re-wire the library 😅

  1. Create a class that is able to do everything
  2. Probe-for-config, and instantiate the interfaces "as available"
  3. When users probe for a functionality, accept / throw NotImplementedError as available.

    1. ... hopefully allow the lib-users to handle "such a situation" gracefully (via a strict=True, or graceful=True)
  4. Attempt to be helpful to everyone:

    1. "Feature VirtualDesktop.name is not supported in $winver. Cause: GUID a-b-c-d is not available."
    2. OleView is an amazing tool. But if you could implement a utils-class-func to search for "known GUID names" (e.g. IVirtualDesktop*), and print their associated GUID keys for debugging.

I started trying to implement it this way the other day. The problem is that we need to know what all the interfaces are when we define them, to be able to set the return values and arguments correctly. We can't just say 'GetCurrentDesktop returns an IVirtualDesktop, but we don't know which one yet', we need to know. Doing the feature detection once at start-up seems like at least a not-terrible option, and should be robust once these issues are worked through. Not having a way of testing any of this in CI across all of the Windows versions makes me reluctant to do big refactors.

stdedos commented 8 months ago

We can't just say 'GetCurrentDesktop returns an IVirtualDesktop, but we don't know which one yet', we need to know

You can return ... a union? 😅 I know it's not optimal, but if "all of those" return a thing that responds to e.g. .name and .rename(), then it's good enough for static analysis?

Not having a way of testing any of this in CI across all of the Windows versions makes me reluctant to do big refactors.

Yea, it sucks 😅 But hey, we/I am here 🙃

So far, you have a test harness that "I did not believe it was working on Windows". I'm star-struck to see how well it works.

stdedos commented 8 months ago

I'm good with https://github.com/mrob95/pyvda/commit/11762ff22a2799833dbf9116edc00501d39d4cc6 (instead of previous https://github.com/mrob95/pyvda/commit/cd21c5dfc1f0da328e94281d4820da01382ad29e)

mrob95 commented 8 months ago

Sorry for the tangent: @phpjunkie420, what are those widgets top-right? 🤩 Rainmeter, desktop customization tool kinda like conky for linux.

This is the skin I'm using. Gadgets: Gadgets for Rainmeter

Reproduced this and merged a fix, thanks.

I've just released 0.4.3. I'm aware of an issue on the latest version of Windows 11 where set_focus returns a permission error, but otherwise I think everything should be working on all supported versions. Please let me know if not.