~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to scripts/test-appindicator.py

  • Committer: Jason Conti
  • Date: 2011-05-18 21:17:09 UTC
  • Revision ID: jason.conti@gmail.com-20110518211709-inr5d289rvcabeor
Removing the indicator directory. indicator-notifications is now hosted at lp:recent-notifications/indicator. Also cleaned up the root directory a bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
test-appindicator.py
 
3
August 16, 2010
 
4
"""
 
5
 
 
6
import appindicator
 
7
import gtk
 
8
import os
 
9
 
 
10
from recent_notifications.Notification import Notification
 
11
 
 
12
def get_icon(name):
 
13
  return os.path.join(os.path.dirname(os.path.abspath(__file__)), "icons", name + ".svg")
 
14
 
 
15
class RecentIndicator(object):
 
16
  def __init__(self):
 
17
    self._menu = gtk.Menu()
 
18
    self._message_items = []
 
19
    self._max_items = 5
 
20
 
 
21
    self._menu.append(gtk.SeparatorMenuItem())
 
22
    self._mark_as_read_item = gtk.MenuItem("Mark all as read")
 
23
    self._mark_as_read_item.connect("activate", self.on_mark_as_read)
 
24
    self._menu.append(self._mark_as_read_item)
 
25
 
 
26
    self._menu.show_all()
 
27
    self._menu.set_take_focus(False)
 
28
 
 
29
    self._indicator = appindicator.Indicator("recent-notifications", 
 
30
        get_icon("mono-dark-2-notification-read"), 
 
31
        appindicator.CATEGORY_OTHER)
 
32
    self._indicator.set_attention_icon(get_icon("mono-dark-2-notification-unread"))
 
33
    self._indicator.set_status(appindicator.STATUS_ACTIVE)
 
34
    self._indicator.set_menu(self._menu)
 
35
 
 
36
    self._notify = Notification()
 
37
    self._notify.connect("message-received", self.on_message_received)
 
38
 
 
39
  def add_item(self, message):
 
40
    #self._menu.prepend(gtk.SeparatorMenuItem())
 
41
    current_item = gtk.MenuItem(message.summary)
 
42
    self._menu.prepend(current_item)
 
43
    self._message_items.insert(0, current_item)
 
44
    self._menu.show_all()
 
45
    #self._indicator.set_menu(self._menu)
 
46
    self._indicator.set_status(appindicator.STATUS_ATTENTION)
 
47
 
 
48
  def remove_last_item(self):
 
49
    if len(self._message_items) > 0:
 
50
      last_item = self._message_items.pop()
 
51
      self._menu.remove(last_item)
 
52
      last_item.destroy()
 
53
 
 
54
  def on_mark_as_read(self, item):
 
55
    self._indicator.set_status(appindicator.STATUS_ACTIVE)
 
56
 
 
57
  def on_message_received(self, monitor, message):
 
58
    if len(self._message_items) >= self._max_items:
 
59
      self.remove_last_item()
 
60
    self.add_item(message)
 
61
 
 
62
def main():
 
63
  indicator = RecentIndicator()
 
64
  gtk.main()
 
65
 
 
66
if __name__ == '__main__':
 
67
  main()