Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果存在多个 action 按钮的情况下, 如何知道点击了哪个按钮? #1

Open
Wickscc opened this issue Jun 10, 2022 · 1 comment

Comments

@Wickscc
Copy link

Wickscc commented Jun 10, 2022

image

如图所示, 点击了 1 2 3 4 过后 handle_activated 返回结果都是一样的

image

def testToast():
    # Step1. Create Notifier with applicationId
    notifier = Notifier('MQTT 消息通知')

    # 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_text('第二行 2nd line')
    toast.add_text('第三行 3rd line', placement='attribution')
    # toast.add_image(path_pic, placement='appLogoOverride')

    # toast.add_input(type_='selection', id_='input_name')
    toast.add_action('1', hint_inputId='1')
    toast.add_action('2')
    toast.add_action('3')
    toast.add_action('4')

    toast.set_audio(silent='true')  # Mute

    # Step3. Show the Toast
    notifier.show(toast, handle_activated=notifyActiveHandler, handle_dismissed=handle_dismissed)


def notifyActiveHandler(event_args_activated: EventArgsActivated):
    print('activated')
    print('inputs:', event_args_activated.inputs)
    event_args_activated.sender
    print('argument:', event_args_activated.argument)


def handle_dismissed(event_args_dismissed: EventArgsDismissed):
    print('dismissed')
    print('reason:', event_args_dismissed.reason)
@Mo-Dabao
Copy link
Owner

按钮(action)activationType这个参数,但是文档(尤其是对于非安装程序的)太少了,所以我暂时只将按钮用于关闭。

你的这个需求可以用选项菜单代替一下:

from winsdk_toast import Notifier, Toast
from winsdk_toast.event import EventArgsActivated, EventArgsDismissed, EventArgsFailed


def testToast():
    # Step1. Create Notifier with applicationId
    notifier = Notifier('MQTT 消息通知')

    # 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('selection', id_='input01')
    toast.add_selection(content='1', id_='selection_1')
    toast.add_selection(content='2', id_='selection_2')
    toast.add_selection(content='3', id_='selection_3')
    toast.add_selection(content='4', id_='selection_4')
    toast.add_action('确认')

    # Step3. Show the Toast
    notifier.show(toast, handle_activated=notifyActiveHandler, handle_dismissed=handle_dismissed)


def notifyActiveHandler(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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants