| |   |
| 61 | 61 | |
| 62 | 62 | self.popup.add_action("open", "Open", self.__open_link) |
| 63 | 63 | if len(alist) > 1: |
| 64 | | self.popup.add_action("previous", "Previous", self.__prev_msg) |
| 65 | | self.popup.add_action("next", "Next", self.__next_msg) |
| 66 | | |
| 67 | | def __prev_msg (self, notification, action): |
| 68 | | """Updates the notification with the next available msg """ |
| 69 | | if self.counter == 0: |
| 70 | | self.popup.set_timeout(self.timeout) |
| 71 | | self.show() |
| 72 | | else: |
| 73 | | self.counter -= 1 |
| 64 | self.popup.add_action("previous", "Previous", self.__change_msg) |
| 65 | self.popup.add_action("next", "Next", self.__change_msg) |
| 66 | |
| 67 | def __change_msg (self, notification, action): |
| 68 | """Updates the notification with the next/previous available msg """ |
| 69 | addend = {'previous' : -1, 'next' : 1} |
| 70 | next = self.counter + addend[action] |
| 71 | if next >= 0 and next < len(self.data): |
| 72 | self.counter = next |
| 74 | 73 | self.popup.update(self.popup.get_property('summary'), |
| 75 | 74 | self.__format_msg(self.data[self.counter])) |
| 76 | | self.popup.set_timeout(self.timeout) |
| 77 | | self.popup.show() |
| 78 | | |
| 79 | | def __next_msg (self, notification, action): |
| 80 | | """ """ |
| 81 | | if self.counter == len(self.data)-1: |
| 82 | | self.popup.set_timeout(self.timeout) |
| 83 | | self.show() |
| 84 | | else: |
| 85 | | self.counter += 1 |
| 86 | | self.popup.update(self.popup.get_property('summary'), |
| 87 | | self.__format_msg(self.data[self.counter])) |
| 88 | | self.popup.set_timeout(self.timeout) |
| 89 | | self.popup.show() |
| 75 | self.popup.set_timeout(self.timeout) |
| 76 | self.popup.show() |
| 90 | 77 | |
| 91 | 78 | def __format_msg (self, data): |
| 92 | 79 | """Formats DATA using the class attribute template """ |
| toggle raw diff |
--- a/gmail-sentinel.py
+++ b/gmail-sentinel.py
@@ -61,32 +61,19 @@ class GmailNotification:
self.popup.add_action("open", "Open", self.__open_link)
if len(alist) > 1:
- self.popup.add_action("previous", "Previous", self.__prev_msg)
- self.popup.add_action("next", "Next", self.__next_msg)
-
- def __prev_msg (self, notification, action):
- """Updates the notification with the next available msg """
- if self.counter == 0:
- self.popup.set_timeout(self.timeout)
- self.show()
- else:
- self.counter -= 1
+ self.popup.add_action("previous", "Previous", self.__change_msg)
+ self.popup.add_action("next", "Next", self.__change_msg)
+
+ def __change_msg (self, notification, action):
+ """Updates the notification with the next/previous available msg """
+ addend = {'previous' : -1, 'next' : 1}
+ next = self.counter + addend[action]
+ if next >= 0 and next < len(self.data):
+ self.counter = next
self.popup.update(self.popup.get_property('summary'),
self.__format_msg(self.data[self.counter]))
- self.popup.set_timeout(self.timeout)
- self.popup.show()
-
- def __next_msg (self, notification, action):
- """ """
- if self.counter == len(self.data)-1:
- self.popup.set_timeout(self.timeout)
- self.show()
- else:
- self.counter += 1
- self.popup.update(self.popup.get_property('summary'),
- self.__format_msg(self.data[self.counter]))
- self.popup.set_timeout(self.timeout)
- self.popup.show()
+ self.popup.set_timeout(self.timeout)
+ self.popup.show()
def __format_msg (self, data):
"""Formats DATA using the class attribute template """ |