changeset 1:ba1005429c76

Reset the status icon if the notification is closed
author Guido Berhoerster <guido+weechat@berhoerster.name>
date Tue, 10 Mar 2015 11:30:05 +0100
parents dfe10c951e21
children 400b3d7b1313
files notification.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/notification.py	Tue Mar 10 11:27:22 2015 +0100
+++ b/notification.py	Tue Mar 10 11:30:05 2015 +0100
@@ -222,6 +222,10 @@
     def on_activate(self, widget):
         self.reset()
 
+    def on_notification_closed(self, notification):
+        if notification.get_closed_reason() == 2:
+            self.reset()
+
     def notify(self, summary, message, icon):
         if self.status_icon:
             self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION,
@@ -246,6 +250,7 @@
         notification = pynotify.Notification(summary, body, icon_name)
         if icon_pixbuf is not None:
             notification.set_image_from_pixbuf(icon_pixbuf)
+        notification.connect('closed', self.on_notification_closed)
         notification.show()
 
     def reset(self):
@@ -330,6 +335,10 @@
         self.update_icon()
         return True
 
+    def on_notification_closed(self, notification):
+        if notification.get_closed_reason() == 2:
+            self.reset()
+
     def notify(self, summary, message, icon):
         if self.status_icon:
             self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION,
@@ -356,6 +365,7 @@
         notification = Notify.Notification.new(summary, body, icon_name)
         if icon_pixbuf is not None:
             notification.set_image_from_pixbuf(icon_pixbuf)
+        notification.connect('closed', self.on_notification_closed)
         notification.show()
 
     def reset(self):
@@ -408,6 +418,7 @@
             self.update_icon()
             self.status_icon.setVisible(True)
             self.status_icon.activated.connect(self.on_activated)
+            self.status_icon.messageClicked.connect(self.on_message_clicked)
         else:
             self.status_icon = None
 
@@ -423,6 +434,9 @@
     def on_activated(self, reason):
         self.reset()
 
+    def on_message_clicked(self):
+        self.reset()
+
     def on_blink_timeout(self):
         self.blink_on = not self.blink_on
         self.update_icon()