comparison engine/extensions/pychan/tools.py @ 330:33dd55160a9d

* Added a new method Widget.getNamedChildren * Made the distribute and mapEvents methods (a whole lot) faster. * Added a new (internal) attribute to Widget (has_name) * Added a small decorator for profiling rarely called functions.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 24 Aug 2009 11:45:28 +0000
parents 54bfd1015b35
children 48c99636453e
comparison
equal deleted inserted replaced
329:aca5744f017a 330:33dd55160a9d
1 # coding: utf-8 1 # -*- coding: utf-8 -*-
2 2
3 """ 3 """
4 Functional utilities designed for pychan use cases. 4 Functional utilities designed for pychan use cases.
5 """ 5 """
6 6
119 def chain_callback(event=0,widget=0): 119 def chain_callback(event=0,widget=0):
120 for callback in callbacks: 120 for callback in callbacks:
121 applyOnlySuitable(callback, event=event, widget=widget) 121 applyOnlySuitable(callback, event=event, widget=widget)
122 return chain_callback 122 return chain_callback
123 123
124 def repeatALot(n = 1000):
125 """
126 Internal decorator used to profile some pychan functions.
127 Only use with functions without side-effect.
128
129 Usage::
130 @repeatALot(n=10000)
131 def findChild(self,**kwargs):
132 ...
133 """
134 def wrap_f(f):
135 def new_f(*args,**kwargs):
136 for i in xrange(n):
137 f(*args,**kwargs)
138 return f(*args,**kwargs)
139 return new_f
140 return wrap_f
141
124 def this_is_deprecated(func,message=None): 142 def this_is_deprecated(func,message=None):
125 if message is None: 143 if message is None:
126 message = repr(func) 144 message = repr(func)
127 def wrapped_func(*args,**kwargs): 145 def wrapped_func(*args,**kwargs):
128 print "PyChan: You are using the DEPRECATED functionality: %s" % message 146 print "PyChan: You are using the DEPRECATED functionality: %s" % message