Mercurial > addons > weechat-scripts > weechat-notification-script
comparison notification.py @ 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 |
comparison
equal
deleted
inserted
replaced
0:dfe10c951e21 | 1:ba1005429c76 |
---|---|
220 return True | 220 return True |
221 | 221 |
222 def on_activate(self, widget): | 222 def on_activate(self, widget): |
223 self.reset() | 223 self.reset() |
224 | 224 |
225 def on_notification_closed(self, notification): | |
226 if notification.get_closed_reason() == 2: | |
227 self.reset() | |
228 | |
225 def notify(self, summary, message, icon): | 229 def notify(self, summary, message, icon): |
226 if self.status_icon: | 230 if self.status_icon: |
227 self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION, | 231 self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION, |
228 summary)) | 232 summary)) |
229 self.status_icon.set_blinking(True) | 233 self.status_icon.set_blinking(True) |
244 body = message | 248 body = message |
245 | 249 |
246 notification = pynotify.Notification(summary, body, icon_name) | 250 notification = pynotify.Notification(summary, body, icon_name) |
247 if icon_pixbuf is not None: | 251 if icon_pixbuf is not None: |
248 notification.set_image_from_pixbuf(icon_pixbuf) | 252 notification.set_image_from_pixbuf(icon_pixbuf) |
253 notification.connect('closed', self.on_notification_closed) | |
249 notification.show() | 254 notification.show() |
250 | 255 |
251 def reset(self): | 256 def reset(self): |
252 if self.status_icon: | 257 if self.status_icon: |
253 self.status_icon.set_tooltip_text(APPLICATION) | 258 self.status_icon.set_tooltip_text(APPLICATION) |
328 def on_blink_timeout(self): | 333 def on_blink_timeout(self): |
329 self.blink_on = not self.blink_on | 334 self.blink_on = not self.blink_on |
330 self.update_icon() | 335 self.update_icon() |
331 return True | 336 return True |
332 | 337 |
338 def on_notification_closed(self, notification): | |
339 if notification.get_closed_reason() == 2: | |
340 self.reset() | |
341 | |
333 def notify(self, summary, message, icon): | 342 def notify(self, summary, message, icon): |
334 if self.status_icon: | 343 if self.status_icon: |
335 self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION, | 344 self.status_icon.set_tooltip_text('%s: %s' % (APPLICATION, |
336 summary)) | 345 summary)) |
337 if self.blink_timeout_id is None: | 346 if self.blink_timeout_id is None: |
354 body = message | 363 body = message |
355 | 364 |
356 notification = Notify.Notification.new(summary, body, icon_name) | 365 notification = Notify.Notification.new(summary, body, icon_name) |
357 if icon_pixbuf is not None: | 366 if icon_pixbuf is not None: |
358 notification.set_image_from_pixbuf(icon_pixbuf) | 367 notification.set_image_from_pixbuf(icon_pixbuf) |
368 notification.connect('closed', self.on_notification_closed) | |
359 notification.show() | 369 notification.show() |
360 | 370 |
361 def reset(self): | 371 def reset(self): |
362 if self.status_icon: | 372 if self.status_icon: |
363 self.status_icon.set_tooltip_text(APPLICATION) | 373 self.status_icon.set_tooltip_text(APPLICATION) |
406 self.status_icon = QtGui.QSystemTrayIcon() | 416 self.status_icon = QtGui.QSystemTrayIcon() |
407 self.status_icon.setToolTip(APPLICATION) | 417 self.status_icon.setToolTip(APPLICATION) |
408 self.update_icon() | 418 self.update_icon() |
409 self.status_icon.setVisible(True) | 419 self.status_icon.setVisible(True) |
410 self.status_icon.activated.connect(self.on_activated) | 420 self.status_icon.activated.connect(self.on_activated) |
421 self.status_icon.messageClicked.connect(self.on_message_clicked) | |
411 else: | 422 else: |
412 self.status_icon = None | 423 self.status_icon = None |
413 | 424 |
414 def on_sigint(self, signo, frame): | 425 def on_sigint(self, signo, frame): |
415 self.qapplication.exit(0) | 426 self.qapplication.exit(0) |
419 self.parser.parse(os.read(fd, BUFFER_SIZE)) | 430 self.parser.parse(os.read(fd, BUFFER_SIZE)) |
420 except EOFError: | 431 except EOFError: |
421 self.qapplication.exit(1) | 432 self.qapplication.exit(1) |
422 | 433 |
423 def on_activated(self, reason): | 434 def on_activated(self, reason): |
435 self.reset() | |
436 | |
437 def on_message_clicked(self): | |
424 self.reset() | 438 self.reset() |
425 | 439 |
426 def on_blink_timeout(self): | 440 def on_blink_timeout(self): |
427 self.blink_on = not self.blink_on | 441 self.blink_on = not self.blink_on |
428 self.update_icon() | 442 self.update_icon() |