I want to display a button in a notification with pygobject. This button should call a callback when clicked, but it doesn't, and I don't understand why.
Here is my code :
from gi.repository import Notify, Gtk
class Test:
def __init__(self):
Notify.init('example')
self.notif()
Gtk.main()
def notif(self):
notif = Notify.Notification.new('Title', 'something','dialog-information')
notif.add_action('display', 'Button', self.callback, None)
notif.show()
def callback(self, notif_object, action_name, users_data):
print("Work!")
Gtk.main_quit()
Test()
When I click on the button "Button", nothing happens and the callback is not called. What is the problem ?
After some tries, I found that when I put Gtk.main()
immediately after notif.show()
, the callback work. But I can't use this solution since it implies that I can't show other notifications later.