Package pyjamas :: Package ui :: Module MultiListener
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.ui.MultiListener

 1   
 2   
3 -class MultiListener(object):
4 # The combinations that are coupled. E.g., if onFocus is defined, then 5 # onLostFocus should also be defined. The set method will substitute the 6 # missing methods with the ignore method. 7 # See also pyjamas.builder.Builder.eventListeners 8 combinations = dict( 9 onFocus = ["onLostFocus"], 10 onLostFocus = ["onFocus"], 11 onKeyDown = ["onKeyUp", "onKeyPress"], 12 onKeyUp = ["onKeyPress", "onKeyDown"], 13 onKeyPress = ["onKeyDown", "onKeyUp"], 14 onMouseMove = ["onMouseDown","onMouseUp","onMouseEnter","onMouseLeave"], 15 onMouseDown = ["onMouseUp","onMouseEnter","onMouseLeave","onMouseMove"], 16 onMouseUp = ["onMouseEnter","onMouseLeave","onMouseMove","onMouseDown"], 17 onMouseEnter = ["onMouseLeave","onMouseMove","onMouseDown","onMouseUp"], 18 onMouseLeave = ["onMouseMove","onMouseDown","onMouseUp","onMouseEnter"], 19 onTabSelected = ["onBeforeTabSelected"], 20 onBeforeTabSelected = ["onTabSelected"], 21 ) 22
23 - def __init__(self, obj, **kwargs):
24 self.set(obj, **kwargs)
25
26 - def set(self, obj, **kwargs):
27 """Check for missing event functions and substitute these with """ 28 """the ignore method""" 29 ignore = getattr(self, "ignore") 30 for k, v in kwargs.iteritems(): 31 setattr(self, k, getattr(obj, v)) 32 if k in self.combinations: 33 for k1 in self.combinations[k]: 34 if not hasattr(self, k1): 35 setattr(self, k1, ignore)
36
37 - def ignore(self, *args, **kwargs):
38 """Ignore event""" 39 # The methods returns True, which is only needed for the method 40 # onBeforeTabSelected. 41 return True
42