Giter Site home page Giter Site logo

mrob95 / pyvda Goto Github PK

View Code? Open in Web Editor NEW
85.0 5.0 11.0 187 KB

Python module for manipulating Windows 10/11 windows and virtual desktops.

License: MIT License

Python 99.49% Makefile 0.33% Shell 0.17%
python accessibility virtual-desktops automation windows

pyvda's People

Contributors

compugenius avatar miroslavv3 avatar mrob95 avatar radiantly avatar reckoner avatar stdedos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pyvda's Issues

Add support for Change Virtual Desktop Background on Windows 11

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.

Windows update KB5034765 completely broke pyvda

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))

Expanding on Features available

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

'No such interface supported' after minor Windows update

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))

Support getting HWND from window title

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.

VirtualDesktop go method throws COMError

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.

_ctypes.COMError

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.

permission problem

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

`No such interface` supported on Windows 11 - build 22000.493

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.
image

However the build version BUILD_OVER_21313 is being skipped and it makes it down to the if statement.

else:

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.

How can I write a module simlilar to this?

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

OSError: [WinError -2147417850]

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

Error: _ctypes.COMError: (-2147467262, 'No such interface supported', (None, None, None, 0, None))

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
image

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 that pyvda be updated for windows 11?

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?

TypeError when creating desktop

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)

Add some small utility functions

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.