<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from traits . api import HasPrivateTraits , Str , Any , Dict , Tuple , Callable , Bool <EOL> from . ui_traits import AView <EOL> from . helper import user_name_for <EOL> class InstanceChoiceItem ( HasPrivateTraits ) : <EOL> name = Str <EOL> view = AView <EOL> is_factory = Bool ( False ) <EOL> def get_name ( self , object = None ) : <EOL> """<STR_LIT>""" <EOL> return self . name <EOL> def get_view ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . view <EOL> def get_object ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_compatible ( self , object ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def is_selectable ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def is_droppable ( self ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> class InstanceChoice ( InstanceChoiceItem ) : <EOL> object = Any <EOL> name_trait = Str ( '<STR_LIT:name>' ) <EOL> def get_name ( self , object = None ) : <EOL> """<STR_LIT>""" <EOL> if self . name != '<STR_LIT>' : <EOL> return self . name <EOL> name = getattr ( self . object , self . name_trait , None ) <EOL> if isinstance ( name , basestring ) : <EOL> return name <EOL> return user_name_for ( self . object . __class__ . __name__ ) <EOL> def get_object ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . object <EOL> def is_compatible ( self , object ) : <EOL> """<STR_LIT>""" <EOL> return ( object is self . object ) <EOL> class InstanceFactoryChoice ( InstanceChoiceItem ) : <EOL> droppable = Bool ( False ) <EOL> selectable = Bool ( True ) <EOL> klass = Callable <EOL> args = Tuple <EOL> kw_args = Dict ( Str , Any ) <EOL> is_factory = True <EOL> def get_name ( self , object = None ) : <EOL> """<STR_LIT>""" <EOL> if self . name != '<STR_LIT>' : <EOL> return self . name <EOL> name = getattr ( object , '<STR_LIT:name>' , None ) <EOL> if isinstance ( name , basestring ) : <EOL> return name <EOL> if issubclass ( type ( self . klass ) , type ) : <EOL> klass = self . klass <EOL> else : <EOL> klass = self . get_object ( ) . __class__ <EOL> return user_name_for ( klass . __name__ ) <EOL> def get_object ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . klass ( * self . args , ** self . kw_args ) <EOL> def is_droppable ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . droppable <EOL> def is_compatible ( self , object ) : <EOL> """<STR_LIT>""" <EOL> if issubclass ( type ( self . klass ) , type ) : <EOL> return isinstance ( object , self . klass ) <EOL> return isinstance ( object , self . get_object ( ) . __class__ ) <EOL> def is_selectable ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . selectable <EOL> class InstanceDropChoice ( InstanceFactoryChoice ) : <EOL> droppable = True <EOL> selectable = False <EOL> is_factory = False </s>
