Exemplo n.º 1
0
    def __init__( me, type =int, item_type =None,
                    sync_size_masters =None,    # list-of-other vectors
                    sync_size_slaves  =None,    # list-of-other vectors
                    **kargs):
        item_type = StaticType.makeStaticType( item_type or type )
        item_type.name = 'item'                         #??
        me.item_type = item_type
        me._item_validator = item_type._validate

        kargs = Sizer.__init__( me, **kargs)

        class Container_type( SeqContainer):
            __slots__ = ()
            _parent = me
        me.container_type = Container_type

        if sync_size_slaves is not None:
            if isinstance( sync_size_slaves, Syncer.DualList):
                sync_size_slaves.append( me)
            me._sync_slaves = sync_size_slaves
        if sync_size_masters is not None:
            if isinstance( sync_size_masters, Syncer.DualList):
                sync_size_masters.append( me)
            me._sync_masters = sync_size_masters

        StaticType.__init__( me, Container_type, default_value= Container_type,
                    typ_matcher= lambda value,typ: isinstance( value, (tuple,list)),
                    **kargs )
Exemplo n.º 2
0
 def __init__( me, type_description ='',
                 UI_width = None,
                 **kargs):
     kargs = Sizer.__init__( me, **kargs)
     UI_width = UI_width or me.max
     StaticType.__init__( me, str,
         type_description=type_description or me.__class__.__name__,
         UI_width=UI_width,
         **kargs)
Exemplo n.º 3
0
 def __str__( me):
     m = me.typ
     me.typ = me.item_type
     try:
         r = StaticType.__str__( me)
     finally:
         me.typ = m
     return r + Sizer.__str__( me)
Exemplo n.º 4
0
 def __init__( me, dict, dictname ='', validator =None, type =None,
                 auto_default_value =False,              #if no default_value, use first key as default_value
                 use_reverse =REVERSE_KEY_AND_VALUE,     #bool or format(key,value)
             **kargs ):
     me.dict = dict
     me.dictname = dictname
     if not dict:
         msg_Empty( me, what='dict' )
     if validator:
         for k in dict:
             if not validator( k):
                 msg_OutOfRange( struct=me, what='dict key', member=k, value= dict[k] )
     StaticType.__init__( me, type, validator=validator, **kargs )
     if me.default_value in (config.notSetYet, _NONE) and auto_default_value:       #get first one
         for k in dict:
             me.default_value = k
             break
     if use_reverse:
         me.StaticType_alt = me.AKeyFromDict_reverse( me, dict,
                                 use_key_and_value= isinstance( use_reverse, str) and use_reverse or None )
         me.auto_StaticTypes = me.auto_StaticTypes + ( me.StaticType_alt, )
Exemplo n.º 5
0
    def __init__( me,
            typ =int,       #actual type of elements
            min =None,      #min value
            max =None,      #max value
            typ_matcher =typ_matcher_numeric_lessthan,
            **kargs
        ):

        try:                        #allow type=.. instead of typ=..
            typ = kargs[ 'type']
            del kargs[ 'type']
        except KeyError: pass

        if type(max) is long  and typ<long : typ = long
        if type(max) is float and typ<float: typ = float

        if min is not None and max is not None:
            assert min <= max
        me.min = min
        me.max = max
        StaticType.__init__( me, typ,
                typ_matcher= typ_matcher,
                **kargs
        )
Exemplo n.º 6
0
 def _setattr_props( me, obj, name, value ):
     StaticType._setattr_props( me, obj, name, value )
     #XXX what if value is notSetYet, i.e. unset?
     for typ in me._sync_slaves:
         typ.sync_get_slave_func( obj)( value)
Exemplo n.º 7
0
 def __str__( me):
     return StaticType.__str__(me) + str_min_max( me, ', range')
Exemplo n.º 8
0
 def description( me):
     return StaticType.description(me) + Sizer.__str__( me)
Exemplo n.º 9
0
 def __str__( me):
     return StaticType.__str__( me) + Sizer.__str__( me)
Exemplo n.º 10
0
 def __str__( me):
     return StaticType.__str__( me) + ' ' + me.dictname
Exemplo n.º 11
0
 def z__get__( me, obj, klas =None):
     if obj is None: return me
     value = StaticType.__get__( me, obj, klas )
     return me.size_sync( value)
Exemplo n.º 12
0
 def _setattr_props( me, obj, name, value ):
     StaticType._setattr_props( me, obj, name, value )
     #XXX what if value is notSetYet, i.e. unset?
     me.sync_setup( obj, do_sync=True)    #after actual setattr