1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
"""
MessageList.py
March 28, 2011
A box to display message items.
"""
import logging
from gi.repository import GObject, Gtk
from MessageItem import MessageItem
from Theme import Color
logger = logging.getLogger("MessageList")
class MessageList(Gtk.ScrolledWindow):
"""A box to display message items"""
def __init__(self):
GObject.GObject.__init__(self)
self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self._filter = None
self._messages = []
self._message_limit = 20
self._width = 400
self._current_theme = None
self._viewport = Gtk.Viewport()
self.add(self._viewport)
self._vbox = Gtk.VBox()
self._vbox.set_border_width(5)
self._viewport.add(self._vbox)
def add_message(self, message):
"""Adds a message to the box"""
item = MessageItem(message)
item.set_width(self._width)
if self._current_theme != None:
item.set_theme(self._current_theme)
self._messages.insert(0, item)
if self._filter == None or self._filter == message.app_name:
item.show_all()
self._vbox.pack_start(item, False, False, 2)
self._vbox.reorder_child(item, 0)
if self._message_limit > 0 and len(self._messages) > self._message_limit:
item = self._messages.pop()
self._vbox.remove(item)
item.destroy()
def clear_messages(self):
"""Clear all the messages"""
for item in self._messages:
self._vbox.remove(item)
item.destroy()
self._messages = []
def filter_by(self, app_name):
"""Sets the filter and hides everything not matching it. Use None for all apps."""
self._filter = app_name
for item in self._messages:
if app_name == None or item.get_app_name() == app_name:
item.show_all()
else:
item.hide_all()
def mark_as_read(self):
"""Marks all the items as read"""
for item in self._messages:
if item.is_unread():
item.set_unread(False)
else:
break
def set_theme(self, theme):
"""Sets the theme of this message list"""
self._current_theme = theme
for item in self._messages:
item.set_theme(theme)
color = theme.get_background()
color.set_bg_normal(self._viewport)
def set_width(self, width):
"""Updates the default width and the width of all the childen message items."""
self._width = width
for item in self._messages:
item.set_width(width)
self._vbox.set_size_request(width - 20, -1)
|