-
-
Save MarcAlx/443358d5e7167864679ffa1b7d51cd06 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*- | |
# Created by Marc_Alx | |
# | |
# pip install winrt | |
# Documentation here : https://github.com/Microsoft/xlang/tree/master/src/package/pywinrt/projection | |
# NB Only works with version of Windows that supports 'windows.ui.notifications' | |
# | |
# Requirements | |
# Windows 10, October 2018 Update or later. | |
# Python for Windows, version 3.7 or later | |
# pip, version 19 or later | |
# | |
import winrt.windows.ui.notifications as notifications | |
import winrt.windows.data.xml.dom as dom | |
#create notifier | |
nManager = notifications.ToastNotificationManager | |
notifier = nManager.create_toast_notifier(); | |
#define your notification as string | |
tString = """ | |
<toast> | |
<visual> | |
<binding template='ToastGeneric'> | |
<text>Sample toast</text> | |
<text>Sample content</text> | |
</binding> | |
</visual> | |
</toast> | |
""" | |
#convert notification to an XmlDocument | |
xDoc = dom.XmlDocument() | |
xDoc.load_xml(tString) | |
#display notification | |
notifier.show(notifications.ToastNotification(xDoc)) |
@iDre4M cool that you make it work !
The only difference I see is that you provide an AppID, is it a random string or an Id you register elsewhere ?
Also It would be interesting to see the XML you give to show
.
For image you may look at the xml schema description by Microsoft : https://docs.microsoft.com/fr-fr/windows/uwp/design/shell/tiles-and-notifications/toast-schema#adaptiveimage seems to be an url pointing to an image.
@iDre4M cool that you make it work !
The only difference I see is that you provide an AppID, is it a random string or an Id you register elsewhere ?
Also It would be interesting to see the XML you give to
show
.
Well, this attempt is purely C# ish, where you don't write all that XML structure in a string, just add elements (that probably in the background either way ends up in XML structure) and XML was stated in the first line of the function.
Managed to fix issue with XML too, had to remove all the spaces at the start of each line, add "", give all elements their "IDs" and attributes if needed, no images from outside the local disk even then you had to give full path, buttons don't exist, all other functions are kind of out, unless that's because used older version, since latest (at that time) was experiencing import issues.
How do I get buttons to work?
Hi guys, I've created this as an easy to use package
Hi guys, I've created this as an easy to use package
Wow nice work! happy to have helped you with this gist.
is there a way to stack upcoming notifications over the previous ones as they come?
So I've tried this example as the first attempt, but couldn't make it work in any possible way (maybe I'm missing smth). But in the end found sort of OK and clear example to get it running, it worked properly, just couldn't find a way to add image tho... that's for future probably: