[Bf-python] Observations on generic sequence type
Ken Hughes
khughes at pacific.edu
Fri May 19 18:18:52 CEST 2006
Joseph Gilbert wrote:
> Toni Alatalo wrote:
>
>> in normal python i think these would be:
>> NLA.actionstrips #a dict/mapping type of actions strips
>> NLA.actionstrips.values() #the list of ActionObjects there
>> NLA.actionsstrips['name'] #gets an actionstrip by name
>> NLA.actionstrips.items() #list in format (name, object)
>>
> Yea this is the 'new' way of handling items. Both myself and ken have
> added these 'sequence' type objects to the API. I think that it makes
> the api more user friendly. We could really use as generic base type to
> make this type of seq iteration more easy to code. I think this would
> be a more cleaner interface as well.
Off topic, but something I keep thinking about and then shelving....
I started writing a generic sequence wrapper last November and used it
on meshes, materials and IPOs IIRC. I started looking at it again in
March but at that time decided it wasn't worth the effort. Now that
we're adding more new things to the API I'm once again considering it.
The problem is it's difficult to really make a generic type for this.
The operations are similar for each but not identical.
Iterators are a good example:
* finding the "next" value in the sequence depends on the Blender data
structure implementing the object. It's easy for a ListBase object, but
for arrays we need to know the size of each array entry. So we need to
know whether the data is a ListBase or an array, and for arrays we also
need to know element size.
* once the next value is located, we have to create a BPyObject for that
particular element. So we need a pointer to the *_CreatePyObject()
procedure.
Indexing or mapping operations would need to know similar information.
Additionally, an assignment operation for a sequence sometimes needs
special operations. Copying the instance's data back into the structure
may also require executing some code to recalculate things (like the
DAG or material lists) So we need a pointer to a post-process procedure.
Sequences can have their own attributes and methods. For example, the
new Mesh module supports .delete() and .extent(). So we need a pointer
to tables of methods or attributes for the sequence.
At this point, that's why I haven't pursued this any further. My
implementation handled most of what I describe above, but mainly ended
up relying on specific procedures within each module to handle most of
the real work. I decided it wasn't much different to implement the
sequence within each module anyway; the only thing the generic sequence
type was saving was the creation of a PyType structure.
Ken
More information about the Bf-python
mailing list