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

Campbell Barton ideasman42 at gmail.com
Thu Sep 9 01:18:07 CEST 2010


Hi, Unless your interested in the python api, this message is just to
say there are some changes to make before the next beta and Id like to
postpone the upcoming beta a few days.
Ton & Nathan are ok with this so mailing the list since last meeting
we agreed on a beta mid-week.

*** PyAPI Enthusiasts read on! ***

The reason for this is how we define properties in python is currently
inconsistent, I was never really happy with it, and it basically
evolved to be the way it is now but without much design.
Recently users on IRC have been asking me about this and having to
explain this to others made me realize we really need to fix this.

Dan Eicher, Nathan and I discussed this, Ill try summarize the topic
briefly and give a solution Nathan and I are happy with.

There are 2 things I dont like about the current property definition system.
1) inconsistency between operators and types

class Operator(bpy.types.Operator):
    myprop = bpy.props.BoolProperty()

  .... and existing classes

bpy.types.Scene.BoolProperty(attr="myprop")

The main difference with this is one use of BoolProperty returns a
property, another doesn't but adds it into the class from which its
called.


2) class methods in python are available on instances.
this is OK ends up being confusing since we CAN have properties only
on 1 object.

So...
   bpy.types.Scene.BoolProperty(attr="myprop")
Is the same as...
   context.scene.BoolProperty(attr="myprop")
But it looks like it might do...
   context.scene["pyprop"] = True  # current python method to add a
property to a single object

--- Proposed solution

Follow the way operators work, treat properties as class attributes so...
   bpy.types.Scene.BoolProperty(attr="myprop")
   bpy.types.Scene.RemoveProperty(attr="myprop")
 ...is replaced by
   bpy.types.Scene.myprop = bpy.props.BoolProperty()
   del bpy.types.Scene.myprop

class NetRenderSettings(bpy.types.IDPropertyGroup):
    pass
NetRenderSettings.StringProperty( attr="server_address", name="Server address")
... is replaced by
class NetRenderSettings(bpy.types.IDPropertyGroup):
    server_address = bpy.props.StringProperty( attr="", name="Server address")
...or this should work too
class NetRenderSettings(bpy.types.IDPropertyGroup):
    pass
NetRenderSettings.server_address = bpy.props.StringProperty( attr="",
name="Server address")



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.

-- 
- Campbell


More information about the Bf-committers mailing list