Mercurial > MadButterfly
comparison pyink/trait.py @ 1349:b0e54ae756f8
More doc
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 12 Feb 2011 19:46:58 +0800 |
parents | 22a79dcbaec6 |
children | 1a4d15fe2c62 |
comparison
equal
deleted
inserted
replaced
1348:22a79dcbaec6 | 1349:b0e54ae756f8 |
---|---|
260 # in an attribute, named 'provide_traits', defined in composition | 260 # in an attribute, named 'provide_traits', defined in composition |
261 # class. The attribute provide_traits of a composition class is a | 261 # class. The attribute provide_traits of a composition class is a |
262 # dictionary mapping from require attributes of used traits to names | 262 # dictionary mapping from require attributes of used traits to names |
263 # of attributes of the composition class. | 263 # of attributes of the composition class. |
264 # | 264 # |
265 # \verbatim | |
266 # @composite | |
267 # class foo(object): | |
268 # use_trait = (trait_a, trait_b) | |
269 # provide_traits = {trait_a.var_a: 'var_foo'} | |
270 # | |
271 # var_foo = 'value of var_foo' | |
272 # pass | |
273 # \endverbatim | |
274 # | |
275 # Like mapping require attributes of used traits, there is a map, | |
276 # named method_map_traits, for methods of used traits. | |
277 # | |
278 # \verbatim | |
279 # @composite | |
280 # class foo(object): | |
281 # use_trait = (trait_a, trait_b) | |
282 # provide_traits = {trait_a.var_a: 'var_foo'} | |
283 # method_map_traits = {trait_a.xxx: 'hello') | |
284 # | |
285 # var_foo = 'value of var_foo' | |
286 # pass | |
287 # \endverbatim | |
288 # | |
289 # Previous example maps trait_a.xxx method to foo.hello method. | |
290 # composite does not include methods that has a name prefixed by a '_' | |
291 # charater. But, you can still force it, by an explicity mapping in | |
292 # method_map_traits, to include a method prefixed by a '_' character. | |
293 # | |
265 def composite(clazz): | 294 def composite(clazz): |
266 if not hasattr(clazz, 'use_traits'): | 295 if not hasattr(clazz, 'use_traits'): |
267 raise KeyError, \ | 296 raise KeyError, \ |
268 '%s has no use_trait: it must be a list of traits' % (repr(clazz)) | 297 '%s has no use_trait: it must be a list of traits' % (repr(clazz)) |
269 traits = clazz.use_traits | 298 traits = clazz.use_traits |