Package teamwork :: Package widgets :: Module balloon
[hide private]
[frames] | no frames]

Source Code for Module teamwork.widgets.balloon

 1  from getpass import getuser 
 2  import time 
 3  import Pmw 
 4  from teamwork.agent.audit import Auditor 
 5   
6 -class EntityBalloon(Pmw.Balloon):
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 # Initialize history 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 # Just plain old tooltip 36 self.bind(widget,key)
37
38 - def update(self,widget=None):
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
46 - def __update(self,widget):
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
52 - def __delete(self,widget):
53 del self.bindings[widget]
54
55 - def delete(self,widget=None):
56 if widget: 57 self.__delete(widget) 58 else: 59 for widget in self.bindings.keys(): 60 self.__delete(widget)
61