mrob95 / pyvda Goto Github PK
View Code? Open in Web Editor NEWPython module for manipulating Windows 10/11 windows and virtual desktops.
License: MIT License
Python module for manipulating Windows 10/11 windows and virtual desktops.
License: MIT License
Interfaces for this are available on Windows 11. I've added the interface definitions for these functions to https://github.com/mrob95/pyvda/blob/master/pyvda/com_defns.py#L216-L220 but have not linked these up to the VirtualDesktop class.
I don't have access to a Windows 11 machine atm, so if someone is on Windows 11 and can make a PR for a set_wallpaper method that would be great. It should raise an error if BUILD_OVER_21313 is not True.
Attempting to call get_virtual_desktops()
on my Windows 11 22H2 (build 22621.1) machine throws this error:
_ctypes.COMError: (-2147023116, 'A null reference pointer was passed to the stub.', (None, None, None, 0, None))
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))
This is not technically an issue, but an idea/request.
Would like to be able to do the following:
Get Virtual Desktop Name
Change Virtual Desktop Name
Change Virtual Desktop Background
Create New Virtual Desktop
Delete Virtual Desktop
I've seen this option in C# but would love to be able to use it within your module
The desktops reordering feature was made available in the latest Win10 builds (starting from Windows 10 build 21337).
Is it possible to implement it somehow programmatically on a Win10 build without native support, particularly 19044 ?
After the latest minor Windows update I performed, pyvda suddenly fails directly on import (from pyvda import VirtualDesktop
).
Platform version: 10.0.22621
Error log:
Connected to pydev debugger (build 232.9559.58)
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1078, in _handle_fromlist
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "D:\dev\git\...\...\tray.py", line 10, in <module>
from ....... import AutoSwitchLoop
File "D:\dev\git\...\...\....py", line 7, in <module>
from pyvda import VirtualDesktop
File "D:\dev\git\...\.venv\lib\site-packages\pyvda\__init__.py", line 51, in <module>
from .pyvda import (
File "D:\dev\git\...\.venv\lib\site-packages\pyvda\pyvda.py", line 24, in <module>
managers = Managers()
File "D:\dev\git\...\.venv\lib\site-packages\pyvda\utils.py", line 55, in __init__
self.manager_internal = get_vd_manager_internal()
File "D:\dev\git\...\.venv\lib\site-packages\pyvda\utils.py", line 41, in get_vd_manager_internal
return _get_object(IVirtualDesktopManagerInternal, CLSID_VirtualDesktopManagerInternal)
File "D:\dev\git\...\.venv\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))
The error encountered is the same as #33.
I am using https://github.com/sdias/win-10-virtual-desktop-enhancer - which already includes a .dll
ready-to-go.
However, even the "suggestion for the source" (https://github.com/Ciantic/VirtualDesktopAccessor/; assuming https://github.com/Ciantic/VirtualDesktopAccessor/tree/2019-windows10 given that the rest are win-11 code), looks like it has the exact same GUIDs.
I think it would be helpful to add a way of getting a window's HWND from it's title, so that it can be used to automate moving windows in more scenarios.
I currently implemented this as follows:
def move_window_by_name(hwnd, l_param):
if win32gui.IsWindowVisible(hwnd):
if 'Window Title' in win32gui.GetWindowText(hwnd):
AppView(hwnd).move(VirtualDesktop(2))
win32gui.EnumWindows(move_window_by_name, None)
I'm sure there's a way to add this into the main module, I just didn't look into it.
Or, at least maybe put this code in the README in case anyone else wants it.
Traceback (most recent call last):
File "C:\Users\Me\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvda\pyvda.py", line 375, in go
managers.manager_internal.SwitchDesktop(*NULL_IF_OVER_20231, self._virtual_desktop)
_ctypes.COMError: (-2147024809, 'The parameter is incorrect.', (None, None, None, 0, None))
Haven't been able to thoroughly test this but figured I should make an issue on the off chance that someone knows what's going on. This is version 0.3.0 on Windows 11 so I'm aware you might not have a machine that runs that.
I used getattr
in window.hwnd
to see if the window has been closed. I did this to see if it would generate an exception and it did. The exception was _ctypes.COMError. I've tried to find this in pyvda
and the required packages (comtypes
, pywin32
) but I've been unable to find it. I want to import it so I can contextlib.suppress
the exception.
I have a few questions to consider:
1、How do I set permissions on virtual desktops
2、I want to hide the virtual desktop taskbar window
Edition Windows 11 Pro
Version 21H2
Installed on 1/29/2022
OS build 22000.493
Experience Windows Feature Experience Pack 1000.22000.493.0
Exception from function create_work_space:
Traceback (most recent call last):
File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\lib\site-packages\dragonfly\actions\action_function.py", line 145, in _execute
self._function(**arguments)
File "D:\Backup\Library\Documents\Code\Caster\castervoice\lib\windows_virtual_desktops.py", line 26, in create_work_space
n = len(pyvda.get_virtual_desktops())
File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\pyvda.py", line 421, in get_virtual_desktops
manager_internal = get_vd_manager_internal()
File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\utils.py", line 37, in get_vd_manager_internal
return _get_object(IVirtualDesktopManagerInternal, CLSID_VirtualDesktopManagerInternal)
File "C:\Users\Main\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\utils.py", line 26, in _get_object
pServiceProvider.QueryService(
_ctypes.COMError: (-2147467262, 'No such interface supported', (None, None, None, 0, None))
Execution failed: 'create_work_space'(): (-2147467262, 'No such interface supported', (None, None, None, 0, None))
{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10} exists.
However the build version BUILD_OVER_21313 is being skipped and it makes it down to the if statement.
Line 244 in 2b8eaaf
The root analysis is sys.getwindowsversion().build
is reporting 9200
on my machine.
However running the above code through the interpreter:
>>> import sys
>>> sys.getwindowsversion().build
22000
So I'm left scratching my head a little bit on this one that it could be Natlink related.
CoInitialize()
must be added to _get_object
in utils.py
or else it will throw the above error. This took me a while to figure out, as i kept trying to fix it by calling CoInitialize()
from my own script, to no avail.
Thanks for the work done in building a wrapper for the virtualdesktopmanager class. Absolutely brilliant. But I will like to have the experience to write this on my own and have some hands on experience building the wrapper from the groundwork. Just to fill my curiosity. Any reference will be helpful
nice job!it works.thanks
when trying to use pyvda.get_virtual_desktops()
I encountered a problem:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Mich\Desktop\TT\wb.py", line 7, in <module>
from pyvda import get_virtual_desktops
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\__init__.py", line 51, in <module>
from .pyvda import (
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\pyvda.py", line 24, in <module>
managers = Managers()
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\utils.py", line 53, in __init__
self.manager_internal = get_vd_manager_internal()
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\utils.py", line 40, in get_vd_manager_internal
return _get_object(IVirtualDesktopManagerInternal, CLSID_VirtualDesktopManagerInternal)
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyvda\utils.py", line 24, in _get_object
CoInitialize()
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 150, in CoInitialize
return CoInitializeEx(COINIT_APARTMENTTHREADED)
File "C:\Users\Mich\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 156, in CoInitializeEx
_ole32.CoInitializeEx(None, flags)
File "_ctypes/callproc.c", line 998, in GetResult
OSError: [WinError -2147417850] Po ustawieniu trybu wątku nie można go zmienić
Process finished with exit code 1
Translate: "OSError: [WinError -2147417850] Po ustawieniu trybu wątku nie można go zmienić" -> Once the thread mode is set, it cannot be changed
having the same issue as @nanosil in this issue post #33, i compiled my script with pyvda in it and have it to startup with my pc and running into this traceback error
running the script non compiled runs into same issue, the compiled script was running fine for about a month before this issue and was running fine yesterday and currently runs fine on another pc, running windows 11 2h22 and just upgraded to 2h23 to see if it would help with the issue but does not work on either version, running python 3.11.5 and pyvda 0.3.2
Is there any chance this can be updated for windows 11?
My installation of windows 11 is modified. I'm also using python 3.11.7, cause pyvda doesn't work with python 3.12.
I've been able to get pyvda to work on windows 11.
Anyway, can you update pyvda to work with windows 11?
Platform version: 10.0.22621
Error log:
Traceback (most recent call last):
File "c:\Users\crtkd\OneDrive\Documents\Python Code\desktest.py", line 161, in <module>
dest_dsk = pyvda.VirtualDesktop.create()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\crtkd\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvda\pyvda.py", line 295, in create
desktop = managers.manager_internal.CreateDesktopW(*NULL_IF_OVER_20231)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: call takes exactly 1 arguments (2 given)
I know it's not the scope of your tool, but it'd be nice if AppView
had a .name
.
It is not complicated either:
...: from win32gui import GetWindowText
In [2]:print(GetWindowText(get_apps_by_z_order()[0]))
IPython: E:pyvda/pyvda
... or you can choose to do some comtypes
etc.
It would facilitate e.g. on the #44 debug
When the Virtualdesktop().go() is used to go to a desktop, the Windows desktop icons become super big.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.