Skip to content

Instantly share code, notes, and snippets.

@twiecki
Created February 6, 2012 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twiecki/1755796 to your computer and use it in GitHub Desktop.
Save twiecki/1755796 to your computer and use it in GitHub Desktop.
PrototypedFrom of a list
from traits.api import \
PrototypedFrom, Float, HasTraits, Instance, Str, List, on_trait_change
from copy import copy
class Parent (HasTraits):
first_name = Str
family_name = ''
favorite_first_name = Str
child_allowance = Float(1.00)
things = List(['bicycle', 'house'])
class Child (HasTraits):
__prefix__ = 'child_'
first_name = PrototypedFrom('mother', 'favorite_*')
last_name = PrototypedFrom('father', 'family_name')
allowance = PrototypedFrom('father', '*')
things = PrototypedFrom('father', 'things')
father = Instance(Parent)
mother = Instance(Parent)
#@on_trait_change('things')
def _things_items_changed(self, old, new):
print "Appending"
print old
print new
if self.things is self.father.things:
self.things = copy(self.things)
#self.things.append(new_thing)
fred = Parent( first_name = 'Fred', family_name = 'Lopez', favorite_first_name = 'Diego', child_allowance = 5.0 )
maria = Parent(first_name = 'Maria', family_name = 'Gonzalez', favorite_first_name = 'Tomas', child_allowance = 10.0 )
nino = Child( father=fred, mother=maria )
nino.things.append('toys')
nino.things.append('even more toys')
print fred.things
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment