[Bf-committers] Custom Properties - python issues
Hart's Antler
bhartsho at yahoo.com
Sat Jan 1 10:41:56 CET 2011
1. KeyError: 'the length of IDProperty names is limited to 31 characters'object['x'*32] = 'why not make the limit 32 or 64?, 31 is an odd number - not possible to use md5sum hashes either as a workaround'
2. inner single quotes are invalid## this failslayout.prop( object, "['my-custom-prop']" ) # a better warning should be printed, or single quotes should be supported## this works - double quotes must be usedlayout.prop( object, '["my-custom-prop"]' )
3. dicts are allowed, but layout.prop(...) can not show each subkey on its own## (the dict can be viewed as a string from Custom Properties Panel, but thats not very useful for the user) ##object['x'] = {'a':1, 'b':2}box.prop( object, '["x"]["a"]' ) # error: rna_uiItemR: property not found: Object.["x"]["a"]box.prop( object, '["x"]' ) # this also fails
4. booleans not supported by custom propertiesobject['my-custom-prop'] = True # converted to 1 without any warninglayout.prop( object, '["my-custom-prop"]', toggle=True ) # toggle is ignored, numeric entry is displayed instead
## workaround ##class mypanel(bpy.types.Panel): bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object" bl_label = "toggle custom prop example" @classmethod def poll(cls, context): return True def draw(self, context): layout = self.layout ob = context.active_object tag = 'my-custom-prop' if tag not in ob.keys(): ob[tag] = True v = ob[tag] if v: icon = 'CHECKBOX_HLT' else: icon = 'CHECKBOX_DEHLT' op = layout.operator( 'toggle_prop', text=tag, icon=icon ) op.propname = tag
class toggle_prop_op(bpy.types.Operator): '''operator: prop toggle helper''' bl_idname = "toggle_prop" bl_label = "toggle" bl_options = {'REGISTER', 'UNDO'} propname = StringProperty(name="property name", description="...", maxlen=32, default="") @classmethod def poll(cls, context): return True def invoke(self, context, event): ob = context.active_object ob[ self.propname ] = not ob[ self.propname ] return {'FINISHED'}
More information about the Bf-committers
mailing list