• Stars
    star
    226
  • Rank 175,501 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created about 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Toast notifications for Windows 10 and 11 based on WinRT

Python PyPI

win11toast

Toast notifications for Windows 10 and 11 based on WinRT

image

Installation

pip install win11toast

Usage

from win11toast import toast

toast('Hello Python🐍')

image

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-text

Body

from win11toast import toast

toast('Hello Python', 'Click to open url', on_click='https://www.python.org')

image

Wrap text

from win11toast import toast

toast('Hello', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum accusantium porro numquam aspernatur voluptates cum, odio in, animi nihil cupiditate molestias laborum. Consequatur exercitationem modi vitae. In voluptates quia obcaecati!')

image

Run Python script on Click

from win11toast import toast

toast('Hello Pythonista', 'Click to run python script', on_click=r'C:\Users\Admin\Downloads\handler.pyw')
# {'arguments': 'C:\\Users\\Admin\\Downloads\\handler.pyw', 'user_input': {}}

Since the current directory when executing the script is C:\Windows\system32, use os.chdir() accordingly.

e.g. handler.pyw

On Windows, you can run a Python script in the background using the pythonw.exe executable, which will run your program with no visible process or way to interact with it.

https://stackoverflow.com/questions/9705982/pythonw-exe-or-python-exe

2b53d4528ff94d40a0ab6da7c7fe33c6

Callback

from win11toast import toast

toast('Hello Python', 'Click to open url', on_click=lambda args: print('clicked!', args))
# clicked! {'arguments': 'http:', 'user_input': {}}

Icon

from win11toast import toast

toast('Hello', 'Hello from Python', icon='https://unsplash.it/64?image=669')

image

Square

from win11toast import toast

icon = {
    'src': 'https://unsplash.it/64?image=669',
    'placement': 'appLogoOverride'
}

toast('Hello', 'Hello from Python', icon=icon)

image

Image

from win11toast import toast

toast('Hello', 'Hello from Python', image='https://4.bp.blogspot.com/-u-uyq3FEqeY/UkJLl773BHI/AAAAAAAAYPQ/7bY05EeF1oI/s800/cooking_toaster.png')

image

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-image

Hero

from win11toast import toast

image = {
    'src': 'https://4.bp.blogspot.com/-u-uyq3FEqeY/UkJLl773BHI/AAAAAAAAYPQ/7bY05EeF1oI/s800/cooking_toaster.png',
    'placement': 'hero'
}

toast('Hello', 'Hello from Python', image=image)

image

Progress

from time import sleep
from win11toast import notify, update_progress

notify(progress={
    'title': 'YouTube',
    'status': 'Downloading...',
    'value': '0',
    'valueStringOverride': '0/15 videos'
})

for i in range(1, 15+1):
    sleep(1)
    update_progress({'value': i/15, 'valueStringOverride': f'{i}/15 videos'})

update_progress({'status': 'Completed!'})

image

Attributes https://docs.microsoft.com/en-ca/uwp/schemas/tiles/toastschema/element-progress

https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/toast-progress-bar

Audio

from win11toast import toast

toast('Hello', 'Hello from Python', audio='ms-winsoundevent:Notification.Looping.Alarm')

Available audio https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio

From URL
from win11toast import toast

toast('Hello', 'Hello from Python', audio='https://nyanpass.com/nyanpass.mp3')
From file
from win11toast import toast

toast('Hello', 'Hello from Python', audio=r"C:\Users\Admin\Downloads\nyanpass.mp3")

I don't know how to add custom audio please help.

https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/custom-audio-on-toasts

Loop

from win11toast import toast

toast('Hello', 'Hello from Python', audio={'loop': 'true'})
from win11toast import toast

toast('Hello', 'Hello from Python', audio={'src': 'ms-winsoundevent:Notification.Looping.Alarm', 'loop': 'true'})

Silent🤫

from win11toast import toast

toast('Hello Python🐍', audio={'silent': 'true'})

Speak🗣

from win11toast import toast

toast('Hello Python🐍', dialogue='Hello world')

OCR👀

from win11toast import toast

toast(ocr='https://i.imgur.com/oYojrJW.png')

image

from win11toast import toast

toast(ocr={'lang': 'ja', 'ocr': r'C:\Users\Admin\Downloads\hello.png'})

image

Long duration

from win11toast import toast

toast('Hello Python🐍', duration='long')

displayed for 25 seconds https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toast

No timeout

from win11toast import toast

toast('Hello Python🐍', scenario='incomingCall')

The scenario your toast is used for, like an alarm, reminder, incomingCall or urgent.

https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toast#:~:text=None-,scenario,-The%20scenario%20your

image

Button

from win11toast import toast

toast('Hello', 'Hello from Python', button='Dismiss')
# {'arguments': 'http:Dismiss', 'user_input': {}}

image

from win11toast import toast

toast('Hello', 'Hello from Python', button={'activationType': 'protocol', 'arguments': 'https://google.com', 'content': 'Open Google'})
# {'arguments': 'https://google.com', 'user_input': {}}

image

from win11toast import toast

toast('Hello', 'Click a button', buttons=['Approve', 'Dismiss', 'Other'])

image

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-action

Play music or Open Explorer

from win11toast import toast

buttons = [
    {'activationType': 'protocol', 'arguments': 'C:\Windows\Media\Alarm01.wav', 'content': 'Play'},
    {'activationType': 'protocol', 'arguments': 'file:///C:/Windows/Media', 'content': 'Open Folder'}
]

toast('Music Player', 'Download Finished', buttons=buttons)

image

Input

from win11toast import toast

toast('Hello', 'Type anything', input='reply', button='Send')
# {'arguments': 'http:Send', 'user_input': {'reply': 'Hi there'}}

image

from win11toast import toast

toast('Hello', 'Type anything', input='reply', button={'activationType': 'protocol', 'arguments': 'http:', 'content': 'Send', 'hint-inputId': 'reply'})
# {'arguments': 'http:', 'user_input': {'reply': 'Hi there'}}

image

https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-input

Selection

from win11toast import toast

toast('Hello', 'Which do you like?', selection=['Apple', 'Banana', 'Grape'], button='Submit')
# {'arguments': 'dismiss', 'user_input': {'selection': 'Grape'}}

image

image

No arguments

from win11toast import toast

toast()

image

Non blocking

from win11toast import notify

notify('Hello Python', 'Click to open url', on_click='https://www.python.org')

Async

from win11toast import toast_async

async def main():
    await toast_async('Hello Python', 'Click to open url', on_click='https://www.python.org')

Jupyter

from win11toast import notify

notify('Hello Python', 'Click to open url', on_click='https://www.python.org')

image

from win11toast import toast_async

await toast_async('Hello Python', 'Click to open url', on_click='https://www.python.org')

image

import urllib.request
from pathlib import Path
src = str(Path(urllib.request.urlretrieve("https://i.imgur.com/p9dRdtP.jpg")[0]).absolute())

from win11toast import toast_async
await toast_async('にゃんぱすー', audio='https://nyanpass.com/nyanpass.mp3', image={'src': src, 'placement':'hero'})
from win11toast import toast_async

await toast_async('Hello Python🐍', dialogue='にゃんぱすー')

Debug

from win11toast import toast

xml = """
<toast launch="action=openThread&amp;threadId=92187">

    <visual>
        <binding template="ToastGeneric">
            <text hint-maxLines="1">Jill Bender</text>
            <text>Check out where we camped last weekend! It was incredible, wish you could have come on the backpacking trip!</text>
            <image placement="appLogoOverride" hint-crop="circle" src="https://unsplash.it/64?image=1027"/>
            <image placement="hero" src="https://unsplash.it/360/180?image=1043"/>
        </binding>
    </visual>

    <actions>

        <input id="textBox" type="text" placeHolderContent="reply"/>

        <action
          content="Send"
          imageUri="Assets/Icons/send.png"
          hint-inputId="textBox"
          activationType="background"
          arguments="action=reply&amp;threadId=92187"/>

    </actions>

</toast>"""

toast(xml=xml)

image

Notifications Visualizer image

Acknowledgements

More Repositories

1

gdrive.sh

Download a file or a folder easily. curl gdrive.sh | bash -s $fileid
Shell
198
star
2

toast-notification-examples

Toast notification examples for PowerShell
39
star
3

winocr

Python
12
star
4

vscode-remote-try-nuxt

Nuxt.js sample project for trying out the VS Code Remote - Containers extension
Dockerfile
7
star
5

cc-regex

'[email protected]'.match(/\x{email}/)
JavaScript
7
star
6

pichromecast

Library for MicroPython to communicate with the Google Chromecast.
Python
7
star
7

shell2http

Executing shell commands via HTTP server
Python
6
star
8

sketch2code-cli

sketch is easy. curl s2c.sh | bash -s sample.jpg
Shell
6
star
9

inversecooking-app

Vue
5
star
10

firesql

FireSQL is realtime MySQL like Firebase.
Python
4
star
11

textra

Machine translation for Everyone
Python
3
star
12

web-push-server

JavaScript
2
star
13

web-push-study

JavaScript
2
star
14

senkosan

Vue
2
star
15

youtube-trends

YouTube trending history data is https://drive.google.com/drive/folders/1jOjoLB0T1c32QCzjvaRAI-wT-EtlU_gB
Vue
2
star
16

firebase-nuxt-actions

Vue
1
star
17

web-push-demo

Web Push Demo
HTML
1
star
18

deta-drive-proxy

Download a Deta Drive file without X-Api-Key header
JavaScript
1
star
19

jetbrains-toolbox-app-installer

easy install on ubuntu
Shell
1
star
20

shell2udp

Executing shell commands via UDP server
Python
1
star
21

KiZooNa.js

HTTP MySQL/SQLite Proxy
JavaScript
1
star
22

notify-send

Firebase Cloud Messaging Demo
JavaScript
1
star
23

Apache-PHP-on-Alpine

Apache and PHP on Alpine on Docker.
1
star
24

Apache2.2-PHP5.2.17

PHP
1
star
25

apache-docker

1
star
26

firesql.js

FireSQL Javascript SDK for FireSQL.
TypeScript
1
star
27

own-push-notification

Homebrew push notifications without libraries.
1
star
28

weblio_popup_dictionary

Webページの英語にマウスオーバーさせることで「英和辞典」での意味を表示させるポップアップ辞書機能や、文章を選択することで翻訳結果へスムーズに移動することができる機能を備えた、Weblio非公式のエクステンションです。
JavaScript
1
star
29

population-transition

都道府県別の総人口推移グラフを表示するSPA(Single Page Application)
Vue
1
star