<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from . trait_base import Undefined <EOL> from . traits import CTrait <EOL> from . has_traits import HasTraits , HasPrivateTraits <EOL> from . trait_errors import TraitError <EOL> from . trait_types import Tuple , Dict , Any , Str , Instance , Event , Callable <EOL> from . trait_handlers import TraitType , _read_only , _write_only , _arg_count <EOL> class BaseTraitValue ( HasPrivateTraits ) : <EOL> def as_ctrait ( self , original_trait ) : <EOL> """<STR_LIT>""" <EOL> notifiers = original_trait . _notifiers ( <NUM_LIT:0> ) <EOL> if self . _ctrait is not None : <EOL> if ( notifiers is None ) or ( len ( notifiers ) == <NUM_LIT:0> ) : <EOL> return self . _ctrait <EOL> trait = CTrait ( <NUM_LIT:0> ) <EOL> trait . clone ( self . _ctrait ) <EOL> else : <EOL> trait = self . _as_ctrait ( original_trait ) <EOL> if ( ( trait is not None ) and <EOL> ( notifiers is not None ) and <EOL> ( len ( notifiers ) > <NUM_LIT:0> ) ) : <EOL> trait . _notifiers ( <NUM_LIT:1> ) . extend ( notifiers ) <EOL> return trait <EOL> def _as_ctrait ( self , original_trait ) : <EOL> """<STR_LIT>""" <EOL> value_trait = self . trait ( '<STR_LIT:value>' ) <EOL> if value_trait is None : <EOL> return None <EOL> if value_trait . type != '<STR_LIT>' : <EOL> raise TraitError ( "<STR_LIT>" ) <EOL> metadata = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self } <EOL> getter , setter , validate = value_trait . property ( ) <EOL> read_only = ( getter is _read_only ) <EOL> if not read_only : <EOL> getter = self . _getter <EOL> metadata [ '<STR_LIT>' ] = True <EOL> if setter is not _write_only : <EOL> if read_only : <EOL> setter = self . _read_only_setter <EOL> else : <EOL> setter = self . _setter <EOL> metadata [ '<STR_LIT>' ] = True <EOL> return self . _property_trait ( getter , setter , validate , metadata ) <EOL> def _property_trait ( self , getter , setter , validate , metadata ) : <EOL> """<STR_LIT>""" <EOL> n = <NUM_LIT:0> <EOL> if validate is not None : <EOL> n = _arg_count ( validate ) <EOL> trait = CTrait ( <NUM_LIT:4> ) <EOL> trait . property ( getter , _arg_count ( getter ) , <EOL> setter , _arg_count ( setter ) , <EOL> validate , n ) <EOL> trait . value_allowed ( True ) <EOL> trait . value_property ( True ) <EOL> trait . __dict__ = metadata <EOL> return trait <EOL> def _getter ( self , object , name ) : <EOL> return self . value <EOL> def _setter ( self , object , name , value ) : <EOL> old_value = self . value <EOL> self . value = value <EOL> new_value = self . value <EOL> if new_value != old_value : <EOL> object . trait_property_changed ( name , old_value , new_value ) <EOL> def _read_only_setter ( self , object , name , value ) : <EOL> self . value = value <EOL> object . trait_property_changed ( name , Undefined , value ) <EOL> class TraitValue ( BaseTraitValue ) : <EOL> default = Callable <EOL> args = Tuple <EOL> kw = Dict <EOL> type = Any <EOL> delegate = Instance ( HasTraits ) <EOL> name = Str <EOL> def _as_ctrait ( self , original_trait ) : <EOL> """<STR_LIT>""" <EOL> if self . default is not None : <EOL> trait = CTrait ( <NUM_LIT:0> ) <EOL> trait . clone ( original_trait ) <EOL> if original_trait . __dict__ is not None : <EOL> trait . __dict__ = original_trait . __dict__ . copy ( ) <EOL> trait . default_value ( <NUM_LIT:7> , ( self . default , self . args , self . kw ) ) <EOL> elif self . type is not None : <EOL> type = self . type <EOL> try : <EOL> rc = issubclass ( type , TraitType ) <EOL> except : <EOL> rc = False <EOL> if rc : <EOL> type = type ( * self . args , ** self . kw ) <EOL> if not isinstance ( type , TraitType ) : <EOL> raise TraitError ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) % self . trait ) <EOL> self . _ctrait = trait = type . as_ctrait ( ) <EOL> trait . value_allowed ( True ) <EOL> elif self . delegate is None : <EOL> return None <EOL> else : <EOL> if self . name == '<STR_LIT>' : <EOL> raise TraitError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> metadata = { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : True } <EOL> getter = self . _delegate_getter <EOL> setter = self . _delegate_setter <EOL> validate = None <EOL> self . add_trait ( '<STR_LIT:value>' , Event ( ) ) <EOL> self . delegate . on_trait_change ( self . _delegate_modified , self . name ) <EOL> trait = self . _property_trait ( getter , setter , validate , metadata ) <EOL> return trait <EOL> def _delegate_getter ( self , object , name ) : <EOL> return getattr ( self . delegate , self . name ) <EOL> def _delegate_setter ( self , object , name , value ) : <EOL> setattr ( self . delegate , self . name , value ) <EOL> def _delegate_modified ( self ) : <EOL> self . value = True <EOL> def SyncValue ( delegate , name ) : <EOL> return TraitValue ( delegate = delegate , name = name ) <EOL> def TypeValue ( type ) : <EOL> return TraitValue ( type = type ) <EOL> def DefaultValue ( default , args = ( ) , kw = { } ) : <EOL> return TraitValue ( default = default , args = args , kw = kw ) <EOL> from . import ctraits <EOL> ctraits . _value_class ( BaseTraitValue ) </s>
