1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """statusbar widget used by in admin window"""
19
20 __version__ = "$Rev$"
21
22
24 """
25 I implement the status bar used in the admin UI.
26 """
27
29 """
30 @param widget: a gtk.Statusbar to wrap.
31 """
32 self._widget = widget
33
34 self._cids = {}
35 self._mids = {}
36 self._contexts = ['main', 'notebook']
37
38 for context in self._contexts:
39 self._cids[context] = widget.get_context_id(context)
40 self._mids[context] = []
41
42 - def clear(self, context=None):
43 """
44 Clear the status bar for the given context, or for all contexts
45 if none specified.
46 """
47 if context:
48 self._clearContext(context)
49 return
50
51 for context in self._contexts:
52 self._clearContext(context)
53
54 - def push(self, context, message):
55 """
56 Push the given message for the given context.
57
58 @returns: message id
59 """
60 mid = self._widget.push(self._cids[context], message)
61 self._mids[context].append(mid)
62 return mid
63
64 - def pop(self, context):
65 """
66 Pop the last message for the given context.
67
68 @returns: message id popped, or None
69 """
70 if len(self._mids[context]):
71 mid = self._mids[context].pop()
72 self._widget.remove(self._cids[context], mid)
73 return mid
74
75 return None
76
77 - def set(self, context, message):
78 """
79 Replace the current top message for this context with this new one.
80
81 @returns: the message id of the message pushed
82 """
83 self.pop(context)
84 return self.push(context, message)
85
86 - def remove(self, context, mid):
87 """
88 Remove the message with the given id from the given context.
89
90 @returns: whether or not the given mid was valid.
91 """
92 if not mid in self._mids[context]:
93 return False
94
95 self._mids[context].remove(mid)
96 self._widget.remove(self._cids[context], mid)
97 return True
98
99 - def _clearContext(self, context):
100 if not context in self._cids.keys():
101 return
102
103 for mid in self._mids[context][:]:
104 self.remove(context, mid)
105