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