Windows-10-Toast-Notifications icon indicating copy to clipboard operation
Windows-10-Toast-Notifications copied to clipboard

Added on-click callback feature

Open Charnelx opened this issue 6 years ago • 41 comments

Hi. I added callback on click functionality discussed in this issue . Implementation followed this comment plus my own code snippet for decorator/handler.

How it works - just add to show_toast method argument called callback_on_click with callable as value.

Charnelx avatar Aug 19 '18 07:08 Charnelx

Great, this works perfectly for me!

teltmau5 avatar Aug 20 '18 06:08 teltmau5

Is this going to be merged?

@Charnelx could you give a bit more detail on this, sorry guys bit of a Python noob, I downloaded the changed file and replaced the old one in source, built from source (I think that worked correctly?) Just need some clarification on how to implement a click action to my toast notifications

JDogg1329 avatar Aug 26 '18 11:08 JDogg1329

@JDogg1329 , don't know about merge, but you can get this from my own repo if needed. On-click implementation is really easy - just pass callable (in this case function that doesn't receive any arguments) as value of show_toast method parameter called callback_on_click.

Example:

def say_hello():
    print('Hello!')

toast = ToastNotifier()
toast.show_toast( title="Notification", msg="Here comes the message",
                    icon_path=None, duration=5, threaded=False, callback_on_click=say_hello)

In this case, if notification is clicked, say_hello function will be called.

Charnelx avatar Aug 26 '18 18:08 Charnelx

Thanks @Charnelx ! So is it possible to pass an argument to the callback_on_click method?

JDogg1329 avatar Aug 27 '18 05:08 JDogg1329

@JDogg1329 , nope, you can't pass the argument in a direct way...but you can do a trick like this:

toast.show_toast( title="Notification", msg="Here comes the message",
                    icon_path=None, duration=5, threaded=False, callback_on_click=lambda: say_hello(arg))

Charnelx avatar Aug 29 '18 18:08 Charnelx

@Charnelx Bro I have been trying some random stuff for a long time. Thanks for your help. Now I can die peacefully 🤣

vineethpisvas1 avatar Nov 30 '18 08:11 vineethpisvas1

@Charnelx I noticed that if user won't click on the notification, after 10 seconds (in windows 10) the message will be moved to "Action Center" (the notification area on the left side of the screen), and there I couldn't handle the user's click action. Do you have any idea? I want a web page to be opened when user click on the notification.

Thanks

zvibazak avatar Mar 11 '19 13:03 zvibazak

I've installed win10toast via pip and it seems that's not the latest code version because the callback_on_click argument doesn't work. Error says "TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'"

hwsamuel avatar Apr 28 '19 20:04 hwsamuel

I've installed win10toast via pip and it seems that's not the latest code version because the callback_on_click argument doesn't work. Error says "TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'"

same for me.

umutinevi avatar Jun 20 '19 18:06 umutinevi

Does this still work? I tried replacing my init.py contents with the contents from your file @Charnelx but the script was full of errors and said the callback_on_click was not an argument I could use. Sorry if I am doing something wrong, but I'm a noob

ghost avatar Aug 19 '19 02:08 ghost

@crappy-coder21 , just try to update your version using pip.

Charnelx avatar Aug 21 '19 20:08 Charnelx

@Charnelx Nice work ! Are there any way to get win32con.WM_RBUTTONUP in lparam for example ?

LeNarvalo avatar Nov 07 '19 13:11 LeNarvalo

this should be merged to master it is a very useful feature

Zhell1 avatar Dec 19 '19 02:12 Zhell1

Anybody still having problems with the: TypeError: show_toast() got an unexpected keyword argument 'callback_on_click' I keep getting this message.

I installed yesterday so it must be the latest version.

What could i do wrong?

MPeek1995 avatar Mar 11 '20 18:03 MPeek1995

Was it fixed? Because I still get the error TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'

VerifyBot avatar May 04 '20 14:05 VerifyBot

Will this ever be merged? Because I hope so.

JakubBlaha avatar May 23 '20 08:05 JakubBlaha

If anyone want's this feature and is using pipenv, the following command will update the package to the version with the callback_on_click parameter.

pipenv install git+https://github.com/Charnelx/Windows-10-Toast-Notifications.git#egg=win10toast

I couldn't get it to work using pip.

JakubBlaha avatar May 23 '20 09:05 JakubBlaha

LGTM

aleanun89 avatar Jun 02 '20 13:06 aleanun89

There is still same problem:

TypeError: show_toast() got an unexpected keyword argument 'callback_on_click'

sercanyilmaz84 avatar Jul 23 '20 11:07 sercanyilmaz84

Here is the init: https://stackoverflow.com/questions/62828043/how-to-perform-a-function-when-toast-notification-is-clicked-in-python

malun22 avatar Oct 21 '20 15:10 malun22

Is it ever going to merge ? Or is @jacobcolbert dead due to corona ?

Its been 2 Years Now !

@Charnelx Please make a New pip Repo with Your Version 🙏

frak0d avatar Dec 07 '20 03:12 frak0d

Hey Guys,

this works perfectly, BUT:

in my case the callback_on_click is executed instantly after this toast shows up.

How can i make that the action only executes if I click it?

cheers leon

leon-mueller avatar Dec 09 '20 11:12 leon-mueller

@leon-mueller

You are probably doing something like

...(callback_on_click=print('clicked'))

when in reality, you wanna do

...(callback_on_click=lambda: print('clicked'))

jakubblaha-ids avatar Dec 09 '20 11:12 jakubblaha-ids

@jakubblaha-ids

I'm doing as followed:

... callback_on_click=open_ticket(ticket_link)

def open_ticket(url): webbrowser.open(url)

In this case it's always executing the def open_ticket when the toast shows up

leon-mueller avatar Dec 09 '20 12:12 leon-mueller

@leon-mueller

What you are doing is essentially the same as...

result = open_ticket(ticket_link)
...(click_on_callback=result)

You are calling the function and assigning it's return value to the click_on_callback parameter.

You instead need to pass in the function (not it's call resulting in a return value) as the click_on_callback argument. This can be done by defining a function without a name using the lambda keyword (you can google that) as follows.

...(callback_on_click=lambda: open_ticket(ticket_link))

JakubBlaha avatar Dec 09 '20 13:12 JakubBlaha

@JakubBlaha

aaaah damn didn't thought about that tho. Thank you very much!!!!

leon-mueller avatar Dec 09 '20 14:12 leon-mueller

i feel dumb, but how do i install it????

jellytoaster avatar Jan 25 '21 00:01 jellytoaster

@jellytoaster https://github.com/jithurjacob/Windows-10-Toast-Notifications/pull/38#issuecomment-633012502

JakubBlaha avatar Jan 25 '21 08:01 JakubBlaha

@jellytoaster #38 (comment) thx

jellytoaster avatar Jan 25 '21 13:01 jellytoaster

help, im getting errors saying "the system could not find the file specified." do i need anaconda or something????

jellytoaster avatar Jan 25 '21 13:01 jellytoaster