pywinrt / python-winsdk

Python package with bindings for Windows SDK
https://python-winsdk.readthedocs.io
MIT License
77 stars 8 forks source link

add changed notification listener error #16

Open vortex1024 opened 2 years ago

vortex1024 commented 2 years ago

if I do

listener = UserNotificationListener.get_current()
listener.add_notification_changed(handler)   

where handler is another defined function I get

OSError: [WinError -2147023728] Element not found

I know I have access to notifications because

notifs=await listener.get_notifications_async(1)

works

any fix? thanks

dlech commented 2 years ago

Which line triggers the error?

UserNotificationListener.get_current()

This should be UserNotificationListener.current. It is a property.

vortex1024 commented 2 years ago

ah, sorry. the next line: listener.add_notification_changed(handler)
triggers the erorr

dlech commented 2 years ago

does the error still happen if you fix the current property?

dlech commented 2 years ago

This should be UserNotificationListener.current. It is a property.

Actually, I guess this is wrong because of pywinrt/pywinrt#13. Static properties currently are not implemented like instance properties.

vortex1024 commented 2 years ago

well, yes. AttributeError: type object '_winsdk_Windows_UI_Notifications_Management.UserNo' has no attribute 'current' still, I guess all that would do is call get_current under the hood, right? would it help if I gave you the whole code to test? although it is not much, just imports.

dlech commented 2 years ago

I'm not sure that anything in the Windows.UI namespace is really usable outside of a Windows Store app at this point.

vortex1024 commented 2 years ago

ok. it seems partially usable, at least, since I can get the notification list and get_access_request_async returns allowed, only the event doesn't work. That's why I thought it should be functional.

gradnerj commented 1 year ago

The issue is resolved when installing Python from the Windows store rather than python.org.

I was using Python 3.10.9, installed with the official 64-bit installer, and the program operated as expected because I was using the python3 command, which was pointing to the Windows Store Python3 installation.

I sent the script to a coworker who installed 3.11.1, and he received the error. I installed 3.11.1 and replicated the same error as the OP.

Steps to resolve the bug:

  1. Uninstall all Python-related apps and programs from Apps & Features ( this isn't entirely necessary, but a good sanity check)
  2. Open a new PowerShell and type python3. This should launch the Windows Store Python 3.10 page.
  3. Click the Get button to install Python 3.10.
  4. After the installation, restart your PowerShell and verify the installation with python3 --version. You should see Python 3.10.9 as the output.
  5. Install pywinsdk with python3 -m pip install winsdk.

These steps resolved the error on two separate machines, and the program successfully listened for new notifications.

Borgotto commented 1 year ago

The issue is resolved when installing Python from the Windows store rather than python.org.

I was using Python 3.10.9, installed with the official 64-bit installer, and the program operated as expected because I was using the python3 command, which was pointing to the Windows Store Python3 installation.

I sent the script to a coworker who installed 3.11.1, and he received the error. I installed 3.11.1 and replicated the same error as the OP.

Steps to resolve the bug:

  1. Uninstall all Python-related apps and programs from Apps & Features ( this isn't entirely necessary, but a good sanity check)
  2. Open a new PowerShell and type python3. This should launch the Windows Store Python 3.10 page.
  3. Click the Get button to install Python 3.10.
  4. After the installation, restart your PowerShell and verify the installation with python3 --version. You should see Python 3.10.9 as the output.
  5. Install pywinsdk with python3 -m pip install winsdk.

These steps resolved the error on two separate machines, and the program successfully listened for new notifications.

I can confirm that the error isn't present on the Microsoft Store edition of Python. I've looked EVERYWHERE for a solution, thank you @gradnerj