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

Stay in Notification Center

Open mrchaosbude opened this issue 6 years ago • 8 comments

is possible that the notification will remain in the Notification Center ?

mrchaosbude avatar Mar 27 '18 19:03 mrchaosbude

I think it's precise name is "Windows Action Center" if that helps.

ed-french avatar May 15 '18 20:05 ed-french

Also looking for this feature! There is a duration setting in the win API. I will make a pr within this week if there is no response.

SamuelYvon avatar Jun 11 '18 16:06 SamuelYvon

I tried to not call the DestroyWindow function to stay in the "Windows Action Center", it seems to be no problems.

ghost avatar Jul 01 '18 06:07 ghost

@jithurjacob Along the lines of what @usradd said, I think the best solution would be to change the code so that if you set duration=0 then the notification never closes.

JuicyJuuce avatar Jul 21 '18 04:07 JuicyJuuce

This has been requested in issue #15 with the intention of being implemented but would love to see this supported.

kurbanis avatar Dec 03 '18 15:12 kurbanis

duration = None worked for me .

umutinevi avatar Jun 20 '19 18:06 umutinevi

Set "duration = None" is easy, but it will raise an error, and you will fail to call the function "show_toast()" again. In fact, you can just comment line 153 in __init__.py, and the problem can be solved. Function "on_destroy()" will be like:

    def on_destroy(self, hwnd, msg, wparam, lparam):
        """Clean after notification ended.

        :hwnd:
        :msg:
        :wparam:
        :lparam:
        """
        nid = (self.hwnd, 0)
        # Shell_NotifyIcon(NIM_DELETE, nid)
        PostQuitMessage(0)

        return None

Or you can overwrite the function "on_destroy()". For example,

from win10toast import ToastNotifier

class MyToastNotifier(ToastNotifier):

    def on_destroy(self, hwnd, msg, wparam, lparam):
        pass

toaster = MyToastNotifier()
toaster.show_toast("Test", "Hello world!", threaded=True)

Arsennnic avatar Feb 21 '20 15:02 Arsennnic

@Arsennnic Just try catch the exception will do the job as well :)

from win10toast import ToastNotifier

toaster = ToastNotifier()
try:
    toaster.show_toast("Test", "Hello world!", duration=None)
except TypeError:
    pass

Or simply let the thread die

toaster.show_toast("Test", "Hello world!", duration=None, threaded=True)

One question for people, taking this kind of approach means hijacking the line sleep(duration) and prevent DestroyWindow(self.hwnd) from executing. But UnregisterClass(self.wc.lpszClassName, None) will also not executed as well. Is it going to raise any problem if the notification is not unregistered? Or does unregistering means removing it from that Action Center?

eugene-yang avatar Mar 31 '20 00:03 eugene-yang