~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to applet.py

  • Committer: Jason Conti
  • Date: 2010-02-17 02:46:20 UTC
  • Revision ID: jason.conti@gmail.com-20100217024620-1n0cdr5sz00bhoxo
Added code to queue messages in the message window.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
      ])
37
37
 
38
38
    self._window = MessageWindow()
 
39
    self._test_counter = 0
39
40
 
40
41
    self._applet.connect("destroy", self.on_applet_destroyed)
41
42
    self._applet.show_all()
63
64
 
64
65
  def on_button_toggled(self, button, *args):
65
66
    if button.get_active():
 
67
      self._window.add_message("blah " + str(self._test_counter))
 
68
      self._test_counter += 1
66
69
      self._window.show_all()
67
70
      self._window.align_with_applet(self)
68
71
    else:
73
76
 
74
77
class MessageWindow(gtk.Window):
75
78
  """Shows the log of notification messages."""
76
 
  def __init__(self):
 
79
  def __init__(self, limit_messages = 10):
77
80
    gtk.Window.__init__(self)
78
81
 
 
82
    self._limit_messages = limit_messages
 
83
 
79
84
    self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
80
85
    self.set_decorated(False)
81
86
    self.set_resizable(False)
82
87
    self.set_title("Message Window")
83
88
 
84
 
    self._label = gtk.Label("""
85
 
      This is my label!
86
 
      This is my label!
87
 
      This is my label!
88
 
      This is my label!
89
 
      This is my label!
90
 
      This is my label!
91
 
      This is my label!
92
 
      This is my label!
93
 
      """)
94
 
 
95
 
    self.add(self._label)
 
89
    self._vbox = gtk.VBox(True)
 
90
 
 
91
    self._messages = []
 
92
 
 
93
    self.add(self._vbox)
 
94
 
 
95
  def add_message(self, message):
 
96
    """Adds a message to the message window."""
 
97
    label = gtk.Label(message)
 
98
    self._messages.append(label)
 
99
    self._vbox.pack_start(label)
 
100
 
 
101
    if len(self._messages) > self._limit_messages:
 
102
      message = self._messages.pop(0)
 
103
      self._vbox.remove(message)
96
104
 
97
105
  def align_with_applet(self, applet):
98
106
    """Adapted from position_calendar_popup in the GNOME clock applet."""