def Scriptable(trait=Any, **metadata): """ Scriptable is a wrapper around another trait that makes it scriptable, ie. changes to its value can be recorded. If a trait is read, but the value isn't set to another scriptable trait or passed to a scriptable method then the read will not be included in the recorded script. To make sure a read is always recorded set the 'has_side_effects' argument to True. """ trait = trait_cast(trait) metadata['default'] = trait.default_value()[1] return Property(_scriptable_get, _scriptable_set, trait=trait, **metadata)
def __init__(self, trait_type, smart_notify=True, **metadata): """Defines a shadow property trait that is best explained by example:: class Thing(HasTraits): x = ShadowProperty(Float, smart_notify=False) def _x_changed(self, value): print value In this example, the actual value of the property (`x`) will be stored in `_x` and `_x_changed` will be called regardless whether the value actually changed or not. If `smart_notify` is set to `True` then the handler is called only if the value has actually changed. Note that the validation uses the validation of the specified `trait_type` parameter. """ self.trait_type = trait_cast(trait_type) self.smart_notify = smart_notify super(ShadowProperty, self).__init__(**metadata)