-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add events add docs
- Loading branch information
Showing
19 changed files
with
578 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = source | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@ECHO OFF | ||
|
||
pushd %~dp0 | ||
|
||
REM Command file for Sphinx documentation | ||
|
||
if "%SPHINXBUILD%" == "" ( | ||
set SPHINXBUILD=sphinx-build | ||
) | ||
set SOURCEDIR=source | ||
set BUILDDIR=build | ||
|
||
%SPHINXBUILD% >NUL 2>NUL | ||
if errorlevel 9009 ( | ||
echo. | ||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
echo.installed, then set the SPHINXBUILD environment variable to point | ||
echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
echo.may add the Sphinx directory to PATH. | ||
echo. | ||
echo.If you don't have Sphinx installed, grab it from | ||
echo.https://www.sphinx-doc.org/ | ||
exit /b 1 | ||
) | ||
|
||
if "%1" == "" goto help | ||
|
||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
goto end | ||
|
||
:help | ||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
|
||
:end | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Events | ||
|
||
A Toast Notification ends up with an event among `Activated`, `Dissmissed` and `Failed`. | ||
|
||
By default, `Notifier` handles `Activated` by printing the argument of the Action(button) and the inputs of Inputs, handes `Dissmissed` by printing the reason of `Dissmissed`, handles `Failed` by raising error_code. | ||
|
||
```python | ||
from winsdk_toast import Notifier, Toast | ||
|
||
|
||
# Step1. Create Notifier with applicationId | ||
notifier = Notifier('程序名 applicationId') | ||
|
||
# Step2. Create Toast which contains the message to be shown | ||
toast = Toast() | ||
toast.add_text('第一行 1st line', hint_align='center', hint_style='caption') | ||
toast.add_input(type_='text', id_='input_name') | ||
toast.add_action('关闭 Close') | ||
toast.set_audio(silent='true') # Mute | ||
|
||
# Step3. Show the Toast | ||
notifier.show(toast) | ||
``` | ||
|
||
If click the `X` at the top-right, `Dissmissed` event happens and prints | ||
|
||
``` | ||
Dismissed reason: UserCanceled | ||
``` | ||
|
||
If wait till it disappears, `Dissmissed` event happens and prints | ||
|
||
``` | ||
Dismissed reason: TimeOut | ||
``` | ||
|
||
If click the `关闭 Close` button, `Activated` event happens and prints | ||
|
||
``` | ||
Activated with | ||
argument: dismiss | ||
inputs: {'input_name': ''} | ||
``` | ||
|
||
If type `test input` in the input box and click on `关闭 Close` button, `Activated` event happens and prints | ||
|
||
``` | ||
Activated with | ||
argument: dismiss | ||
inputs: {'input_name': 'test input'} | ||
``` | ||
|
||
I haven't figured out how the `activationType` and `arguments` of `action` work, so just leave them to dismiss the Toast Notification. | ||
|
||
## Custom `handle` | ||
|
||
Just define the functions that handle the `EventArgsActivated`, `EventArgsDismissed`, `EventArgsFailed` respectively, and pass them to `notifier.show`. | ||
|
||
```python | ||
from winsdk_toast import Notifier, Toast | ||
from winsdk_toast.event import EventArgsActivated, EventArgsDismissed, EventArgsFailed | ||
|
||
|
||
def handle_activated(event_args_activated: EventArgsActivated): | ||
print('activated') | ||
print('inputs:', event_args_activated.inputs) | ||
print('argument:', event_args_activated.argument) | ||
|
||
|
||
def handle_dismissed(event_args_dismissed: EventArgsDismissed): | ||
print('dismissed') | ||
print('reason:', event_args_dismissed.reason) | ||
|
||
|
||
def handle_failed(event_args_failed: EventArgsFailed): | ||
print('failed') | ||
print('error_code:', event_args_failed.error_code) | ||
|
||
|
||
# Step1. Create Notifier with applicationId | ||
notifier = Notifier('程序名 applicationId') | ||
|
||
# Step2. Create Toast which contains the message to be shown | ||
toast = Toast() | ||
toast.add_text('第一行 1st line', hint_align='center', hint_style='caption') | ||
toast.add_input(type_='text', id_='input_name') | ||
toast.add_action('关闭 Close') | ||
toast.set_audio(silent='true') # Mute | ||
|
||
# Step3. Show the Toast | ||
notifier.show( | ||
toast, handle_activated=handle_activated, handle_dismissed=handle_dismissed, handle_failed=handle_failed | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Examples | ||
======================================== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
minimal.md | ||
pic_and_button.md | ||
events.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Minimal | ||
|
||
```python | ||
from winsdk_toast import Notifier, Toast | ||
|
||
|
||
# Step1. Create Notifier with applicationId | ||
notifier = Notifier('程序名 applicationId') | ||
|
||
# Step2. Create Toast which contains the message to be shown | ||
toast = Toast() | ||
toast.add_text('第一行 1st line') | ||
|
||
# Step3. Show the Toast | ||
notifier.show(toast) | ||
``` | ||
|
||
![minimal.gif](pics/minimal.gif) | ||
|
||
Which can also be achieved by | ||
|
||
```python | ||
from winsdk_toast import Notifier, Toast | ||
|
||
|
||
# Step1. Create Notifier with applicationId | ||
notifier = Notifier('程序名 applicationId') | ||
|
||
# Step2. Create Toast which contains the message to be shown | ||
xml = """ | ||
<toast activationType="background"> | ||
<visual> | ||
<binding template="ToastGeneric"> | ||
<text>第一行 1st line</text> | ||
</binding> | ||
</visual> | ||
</toast> | ||
""" | ||
toast = Toast(xml) | ||
|
||
# Step3. Show the Toast | ||
notifier.show(toast) | ||
``` |
Oops, something went wrong.