[Bf-python] Ipo/IpoCurve API revisited
Ken Hughes
khughes at pacific.edu
Sun Mar 26 03:47:00 CEST 2006
Ken Hughes wrote:
> Toni Alatalo wrote:
>
>> On Saturday 11 March 2006 23:33, Ken Hughes wrote:
>>
>>> the direction that the API rewrite was taking (which apparently for now
>>
>>
>> we talked about this a bit with Ken and Jestie on irc - revisiting
>> many issues that were talked on this list last year etc. i try to
>> summarize here a bit.
>>
>>>> (read-only). Makes it possible to do "ipo['LocX']" or "ipo[Ipo.LocX]";
>>>> something like ipocurve[framenum] to do current .evaluate(framenum)
>>>> might
>>
>>
>> again i remembered that someone said that obipo.loc_x would be nicer
>> than obipo.['LocX'] for that and i think i agree.. (classes in py are
>> just syntactic sugar on dicts anyway, like the perl ppl say :)
>
> After thinking about this, I don't know if this will work with tp_getset
> (or at least not easily). I'm trying to interpret PEP 252 but it seems
> that "__slots__" might allow per-instance attributes, if only I can
> figure out how to implement them.
Woo-hoo. Kind of.
I figured out a way to add instance-dependent attributes like ipo.LocX
using the ob_type->tp_getattro entry. I haven't tested
ob_type->tp_setattro yet but assume a similar trick will work. The
downside is that making things like "dir(ipo)" or "ipo.__dict__" show
the attributes (much less "help(ipo)"; haven't even figured that out
yet) is that a new temporary dict needs to be constructed with the
additional PyDescr_NewGetSet() objects.
My personal feeling is that this is much more of a kludge than
"ipo['LocX']". The implementation for that seems very clean. The
key/iterator similarity particularly, in case you want to do something
to all curves (for example, delete all of them):
for x in ipo:
ipo[x] = None
and
ipo['LocX'] = None
I assume that if we do go with attributes instead of dictionaries that
the iterator would just return an IpoCurve:
for icu in ipo:
icu = None
Anyway, maybe this can be discussed in the next Sunday meeting, assuming
all the Orange people have sobered up by then :-)
Ken
More information about the Bf-python
mailing list