[TransWarp] how to build a dynamic component container?

Phillip J. Eby pje at telecommunity.com
Tue Aug 19 10:55:59 EDT 2003


At 04:41 PM 8/19/03 +0200, Matthias Drochner wrote:

> > Instead of using addaxis, just configure the
> > axisgroup to have its axes set at construction time via a keyword argument
>
>Hmm - I get the problem that the group members don't have individual
>names in component space anymore. Eg with
>
>ta1 = testaxis()
>ta2 = testaxis()
>ag1 = axisgroup(axislist = [ta1, ta2])
>ag2 = axisgroup()
>top = axisgroup(config.makeRoot(), "movetest", axislist=[ag1, ag2])
>
>I end up with component names like
>/movetest/axislist/axislist

Hmm.  How about:

ag1 = axisgroup()
ta1 = testaxis(ag1, 'ta1')
ta2 = testaxis(ag1, 'ta2')
ag1.axislist = [ta1,ta2]

Or:

al = []
ag1 = axisgroup(axislist=al)
al.append(testaxis(ag1,'ta1'))
al.append(testaxis(ag1,'ta2'))


>Do I have to overload lookupComponent() in the axisgroup class
>or something like that? The names could be passed as list by another
>keyword argument, or by making the list consist of tuples...

I'm afraid there's really no provision at present to give dynamic items in 
a sequence some kind of absolute path.  Probably the simplest thing to do 
is create a Component subclass that represents a sequence of items, and 
which gives its contents numeric names when you add them to the list.  In 
this way, you could do something like:

ag1 = axisgroup( axislist = ComponentList(items=[testaxis(),testaxis()]) )

And then the ComponentList would have the axisgroup as its parent, and each 
testaxis would have the ComponentList as their parent.  The ComponentList 
would also need a getattr(), if you intended to traverse the paths, rather 
than just use them for configuration lookups.

Even better...  create an IComponentList interface, and define the 
ComponentList class as an adapter from list or tuple to 
IComponentList.  Then, you can do:

ag1 = axisgroup( axislist = [testaxis(),testaxis()] )

as long as you declare the axisgroup.axislist binding with 
'adaptTo=IComponentList'.




More information about the PEAK mailing list