[Bf-committers] PyRNA type definition changes (postpone beta until end of week)

Campbell Barton ideasman42 at gmail.com
Thu Sep 9 20:16:39 CEST 2010


On Thu, Sep 9, 2010 at 5:52 AM, Campbell Barton <ideasman42 at gmail.com> wrote:
> On Thu, Sep 9, 2010 at 2:41 AM, Bassam Kurdali <bkurdali at freefactory.org> wrote:
>> Hi Campbell
>> <--snip>
>>>
>>> Another change to help our api be less confusing is to have operator
>>> properties directly accessible.
>>>
>>> class Operator(bpy.types.Operator):
>>>     myprop = bpy.props.BoolProperty()
>>>    def execute(self, context):
>>> ... this line
>>>         print(self.properties.myprop)
>>> ...could be written as
>>>         print(self.myprop)
>>>
>>> At the moment print(self.myprop) will print the property definition,
>>> but not the property (which is what you want!)
>>> I'd like to keep self.properties available since its how operators
>>> work internally and can be passed as keyword arguments, so this change
>>> is mostly for convent access.
>>>
>> The question that came to mind here (as I mentioned on irc) is that if
>> you *did* want to print/access the property definition, how would you do
>> so if self.myprop just returns the value?
>> cheers
>> Bassam
>> PS- thanks for the mail, it cleared up some things that had been long
>> confusing me re. the api.
>
> operators define StructRNA types once registered so you can do...
>
>>>> bpy.types.IMPORT_SCENE_OT_obj.bl_rna.properties["ROTATE_X90"]
> <bpy_struct, BooleanProperty("ROTATE_X90")>
>
> just like...
>>>> bpy.types.Scene.bl_rna.properties["frame_start"]
> <bpy_struct, IntProperty("frame_start")>
>
> having bl_rna is ugly but needed ATM since the python class and the
> rna type a different (perhaps they could be made into the same type
> but its not trivial).

This proposal has been completed in svn, and I think its ready for
testing (before beta)

In brief:
  # done using a metaclass bpy_types.py:RNA_IDProp_Meta
- bpy.types.Scene.foo = BoolProperty(...)
  # done using property()'s replace the rna property definition after
registration, these forward attribute access to self.properties

- self.properties.foo --> self.foo
- removed bpy.types.Scene.***Property() , class methods.


*TODO's - not urgent *
- figure out why C defined metaclasses crash (spend almost a day on
this already, used a python defined class to get this working)
- use a better intermediate object for storing unregistered property
definitions. currently a tuple  (func, {kw})
- current method for operators forwarding getset's to 'property()'
attribute can be improved, though tried overriding getattr/setattr in
C and python, couldn't get either working right since they call
themselves recursively.

-- 
- Campbell


More information about the Bf-committers mailing list