I have a written a small python script that uses notifications to alert the user when something happens. The script is run on either a cinnamon or gnome based desktop environment.
The nitty-gritty of the script is this:
from gi.repository import Notify
Notify.init("My Program Name")
notification = Notify.Notification.new("Hi")
notification.show()
Notify.uninit()
Notify.init("My New Program Name")
notification = Notify.Notification.new("Hi")
notification.show()
Notify.uninit()
from subprocess import call
call(['notify-send', 'hello', 'world'])
call(['notify-send', 'hello', 'again'])
As you can see the script is using Notify to send the first two messages and a subprocess call to send the last two messages.
What happens when you run this is you get 4 messages appear as notifications.
If I click on either of the "Notify" messages they both get deleted at once.
If I click on either of the "subprocess calls" they get deleted separately depending on which one I click. This is the behaviour I would like for the "Notify" messages.
As you can see in the code I supplied I have tried to re-init Notify with a new program name in order to try to get the messages appear to be from a different source but the messages still get deleted at the same time no matter which one I click on.
How do I get only one message to be deleted at a time when using Notify?
(I cannot just use the subprocess calls as I also want to add an action to the notification which I do not believe is possible with notify-send.)
I solved this by adding:
notification.set_hint('resident', GLib.Variant.new_boolean(True))
This sets the notification to only be cleared when the notification is clicked on.