1 from getpass import getuser
2 import time
3 import Pmw
4 from teamwork.agent.audit import Auditor
5
7 """Minor augmentation of the PMW Balloon help system that allows one to
8 easily update balloon strings associated with entity histories"""
9
10 - def __init__(self, parent = None, **kw):
11 """Identical to the PMW Balloon class initialization, except that it
12 also initializes the table of managed widgets"""
13 Pmw.Balloon.__init__(self,parent,**kw)
14 self.bindings = {}
15
16 - def add(self,widget,entity,key):
17 """Adds the given widget to the handling of this balloon help system
18 and associates it with the given entity and state/goal name"""
19 if isinstance(entity,Auditor):
20 history = entity.getHistory(key)
21 try:
22 str = history[0]
23 except IndexError:
24
25 from getpass import getuser
26 entry = {'what':'initialized',
27 'who':getuser(),
28 'when':time.time()
29 }
30 entity.extendHistory(entry)
31 str = entity.formatHistory(entry)
32 self.bind(widget,str)
33 self.bindings[widget] = (entity,key)
34 else:
35
36 self.bind(widget,key)
37
39 """Updates the balloon help of all of the known widgets"""
40 if widget:
41 self.__update(widget)
42 else:
43 for widget in self.bindings.keys():
44 self.__update(widget)
45
47 """Updates the balloon help of the specified widget"""
48 entity,key = self.bindings[widget]
49 str = entity.getHistory(key)[0]
50 self.bind(widget,str)
51
53 del self.bindings[widget]
54
56 if widget:
57 self.__delete(widget)
58 else:
59 for widget in self.bindings.keys():
60 self.__delete(widget)
61