From e4881eef529262ec131ab22688e44fb9af2f0bb9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 31 Oct 2009 16:40:14 +0000 Subject: [PATCH] define operator properties in the class, similar to django fields # Before [ bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""), bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True), bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True), bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True), bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True) ] # After path = StringProperty(attr="", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "") use_modifiers = BoolProperty(attr="", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True) use_normals = BoolProperty(attr="", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True) use_uvs = BoolProperty(attr="", name="Export UVs", description="Exort the active UV layer", default= True) use_colors = BoolProperty(attr="", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True) --- release/scripts/io/add_mesh_torus.py | 12 +- release/scripts/io/export_3ds.py | 10 +- release/scripts/io/export_fbx.py | 60 +++---- release/scripts/io/export_mdd.py | 12 +- release/scripts/io/export_obj.py | 52 +++--- release/scripts/io/export_ply.py | 17 +- release/scripts/io/export_x3d.py | 16 +- release/scripts/io/import_3ds.py | 14 +- release/scripts/io/import_obj.py | 34 ++-- release/scripts/io/mesh_skin.py | 5 +- release/scripts/io/netrender/operators.py | 55 ------- release/scripts/modules/bpy_ops.py | 80 +++++----- release/scripts/templates/operator.py | 12 +- release/scripts/ui/space_userpref.py | 10 +- release/scripts/ui/space_view3d.py | 12 +- .../blender/python/intern/bpy_operator_wrap.c | 70 ++------ source/blender/python/intern/bpy_rna.c | 150 ++++++++++-------- source/blender/python/intern/bpy_rna.h | 2 + 18 files changed, 285 insertions(+), 338 deletions(-) diff --git a/release/scripts/io/add_mesh_torus.py b/release/scripts/io/add_mesh_torus.py index 1f5d4a25229..b16d372b319 100644 --- a/release/scripts/io/add_mesh_torus.py +++ b/release/scripts/io/add_mesh_torus.py @@ -46,6 +46,7 @@ def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG): return verts, faces +from bpy.props import * class MESH_OT_primitive_torus_add(bpy.types.Operator): '''Add a torus mesh.''' @@ -53,12 +54,11 @@ class MESH_OT_primitive_torus_add(bpy.types.Operator): bl_label = "Add Torus" bl_register = True bl_undo = True - bl_props = [ - bpy.props.FloatProperty(attr="major_radius", name="Major Radius", description="Number of segments for the main ring of the torus", default= 1.0, min= 0.01, max= 100.0), - bpy.props.FloatProperty(attr="minor_radius", name="Minor Radius", description="Number of segments for the minor ring of the torus", default= 0.25, min= 0.01, max= 100.0), - bpy.props.IntProperty(attr="major_segments", name="Major Segments", description="Number of segments for the main ring of the torus", default= 48, min= 3, max= 256), - bpy.props.IntProperty(attr="minor_segments", name="Minor Segments", description="Number of segments for the minor ring of the torus", default= 16, min= 3, max= 256), - ] + + major_radius = FloatProperty(name="Major Radius", description="Number of segments for the main ring of the torus", default= 1.0, min= 0.01, max= 100.0) + minor_radius = FloatProperty(name="Minor Radius", description="Number of segments for the minor ring of the torus", default= 0.25, min= 0.01, max= 100.0) + major_segments = IntProperty(name="Major Segments", description="Number of segments for the main ring of the torus", default= 48, min= 3, max= 256) + minor_segments = IntProperty(name="Minor Segments", description="Number of segments for the minor ring of the torus", default= 16, min= 3, max= 256) def execute(self, context): verts_loc, faces = add_torus(self.major_radius, self.minor_radius, self.major_segments, self.minor_segments) diff --git a/release/scripts/io/export_3ds.py b/release/scripts/io/export_3ds.py index c31847a99a7..35ea1b5adeb 100644 --- a/release/scripts/io/export_3ds.py +++ b/release/scripts/io/export_3ds.py @@ -1090,7 +1090,7 @@ def save_3ds(filename, context): # else: # Blender.Draw.PupMenu("Error%t|This script requires a full python installation") # # save_3ds('/test_b.3ds') - +from bpy.props import * class EXPORT_OT_autodesk_3ds(bpy.types.Operator): '''Export to 3DS file format (.3ds).''' bl_idname = "export.autodesk_3ds" @@ -1099,10 +1099,10 @@ class EXPORT_OT_autodesk_3ds(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - # bpy.props.StringProperty(attr="filename", name="File Name", description="File name used for exporting the 3DS file", maxlen= 1024, default= ""), - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the 3DS file", maxlen= 1024, default= ""), - ] + + # filename = StringProperty(name="File Name", description="File name used for exporting the 3DS file", maxlen= 1024, default= ""), + path = StringProperty(name="File Path", description="File path used for exporting the 3DS file", maxlen= 1024, default= "") + def execute(self, context): save_3ds(self.path, context) diff --git a/release/scripts/io/export_fbx.py b/release/scripts/io/export_fbx.py index 4c3fd727169..47374e5fd67 100644 --- a/release/scripts/io/export_fbx.py +++ b/release/scripts/io/export_fbx.py @@ -3332,7 +3332,7 @@ def write_ui(): # GLOBALS.clear() - +from bpy.props import * class EXPORT_OT_fbx(bpy.types.Operator): '''Selection to an ASCII Autodesk FBX''' bl_idname = "export.fbx" @@ -3341,35 +3341,35 @@ class EXPORT_OT_fbx(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the FBX file", maxlen= 1024, default= ""), - - bpy.props.BoolProperty(attr="EXP_OBS_SELECTED", name="Selected Objects", description="Export selected objects on visible layers", default=True), -# bpy.props.BoolProperty(attr="EXP_OBS_SCENE", name="Scene Objects", description="Export all objects in this scene", default=True), - bpy.props.FloatProperty(attr="_SCALE", name="Scale", description="Scale all data, (Note! some imports dont support scaled armatures)", min=0.01, max=1000.0, soft_min=0.01, soft_max=1000.0, default=1.0), - bpy.props.BoolProperty(attr="_XROT90", name="Rot X90", description="Rotate all objects 90 degrese about the X axis", default=True), - bpy.props.BoolProperty(attr="_YROT90", name="Rot Y90", description="Rotate all objects 90 degrese about the Y axis", default=False), - bpy.props.BoolProperty(attr="_ZROT90", name="Rot Z90", description="Rotate all objects 90 degrese about the Z axis", default=False), - bpy.props.BoolProperty(attr="EXP_EMPTY", name="Empties", description="Export empty objects", default=True), - bpy.props.BoolProperty(attr="EXP_CAMERA", name="Cameras", description="Export camera objects", default=True), - bpy.props.BoolProperty(attr="EXP_LAMP", name="Lamps", description="Export lamp objects", default=True), - bpy.props.BoolProperty(attr="EXP_ARMATURE", name="Armatures", description="Export armature objects", default=True), - bpy.props.BoolProperty(attr="EXP_MESH", name="Meshes", description="Export mesh objects", default=True), - bpy.props.BoolProperty(attr="EXP_MESH_APPLY_MOD", name="Modifiers", description="Apply modifiers to mesh objects", default=True), - bpy.props.BoolProperty(attr="EXP_MESH_HQ_NORMALS", name="HQ Normals", description="Generate high quality normals", default=True), - bpy.props.BoolProperty(attr="EXP_IMAGE_COPY", name="Copy Image Files", description="Copy image files to the destination path", default=False), - # armature animation - bpy.props.BoolProperty(attr="ANIM_ENABLE", name="Enable Animation", description="Export keyframe animation", default=True), - bpy.props.BoolProperty(attr="ANIM_OPTIMIZE", name="Optimize Keyframes", description="Remove double keyframes", default=True), - bpy.props.FloatProperty(attr="ANIM_OPTIMIZE_PRECISSION", name="Precision", description="Tolerence for comparing double keyframes (higher for greater accuracy)", min=1, max=16, soft_min=1, soft_max=16, default=6.0), -# bpy.props.BoolProperty(attr="ANIM_ACTION_ALL", name="Current Action", description="Use actions currently applied to the armatures (use scene start/end frame)", default=True), - bpy.props.BoolProperty(attr="ANIM_ACTION_ALL", name="All Actions", description="Use all actions for armatures, if false, use current action", default=False), - # batch - bpy.props.BoolProperty(attr="BATCH_ENABLE", name="Enable Batch", description="Automate exporting multiple scenes or groups to files", default=False), - bpy.props.BoolProperty(attr="BATCH_GROUP", name="Group > File", description="Export each group as an FBX file, if false, export each scene as an FBX file", default=False), - bpy.props.BoolProperty(attr="BATCH_OWN_DIR", name="Own Dir", description="Create a dir for each exported file", default=True), - bpy.props.StringProperty(attr="BATCH_FILE_PREFIX", name="Prefix", description="Prefix each file with this name", maxlen= 1024, default=""), - ] + + path = StringProperty(name="File Path", description="File path used for exporting the FBX file", maxlen= 1024, default= "") + + EXP_OBS_SELECTED = BoolProperty(name="Selected Objects", description="Export selected objects on visible layers", default=True) +# EXP_OBS_SCENE = BoolProperty(name="Scene Objects", description="Export all objects in this scene", default=True) + _SCALE = FloatProperty(name="Scale", description="Scale all data, (Note! some imports dont support scaled armatures)", min=0.01, max=1000.0, soft_min=0.01, soft_max=1000.0, default=1.0) + _XROT90 = BoolProperty(name="Rot X90", description="Rotate all objects 90 degrese about the X axis", default=True) + _YROT90 = BoolProperty(name="Rot Y90", description="Rotate all objects 90 degrese about the Y axis", default=False) + _ZROT90 = BoolProperty(name="Rot Z90", description="Rotate all objects 90 degrese about the Z axis", default=False) + EXP_EMPTY = BoolProperty(name="Empties", description="Export empty objects", default=True) + EXP_CAMERA = BoolProperty(name="Cameras", description="Export camera objects", default=True) + EXP_LAMP = BoolProperty(name="Lamps", description="Export lamp objects", default=True) + EXP_ARMATURE = BoolProperty(name="Armatures", description="Export armature objects", default=True) + EXP_MESH = BoolProperty(name="Meshes", description="Export mesh objects", default=True) + EXP_MESH_APPLY_MOD = BoolProperty(name="Modifiers", description="Apply modifiers to mesh objects", default=True) + EXP_MESH_HQ_NORMALS = BoolProperty(name="HQ Normals", description="Generate high quality normals", default=True) + EXP_IMAGE_COPY = BoolProperty(name="Copy Image Files", description="Copy image files to the destination path", default=False) + # armature animation + ANIM_ENABLE = BoolProperty(name="Enable Animation", description="Export keyframe animation", default=True) + ANIM_OPTIMIZE = BoolProperty(name="Optimize Keyframes", description="Remove double keyframes", default=True) + ANIM_OPTIMIZE_PRECISSION = FloatProperty(name="Precision", description="Tolerence for comparing double keyframes (higher for greater accuracy)", min=1, max=16, soft_min=1, soft_max=16, default=6.0) +# ANIM_ACTION_ALL = BoolProperty(name="Current Action", description="Use actions currently applied to the armatures (use scene start/end frame)", default=True) + ANIM_ACTION_ALL = BoolProperty(name="All Actions", description="Use all actions for armatures, if false, use current action", default=False) + # batch + BATCH_ENABLE = BoolProperty(name="Enable Batch", description="Automate exporting multiple scenes or groups to files", default=False) + BATCH_GROUP = BoolProperty(name="Group > File", description="Export each group as an FBX file, if false, export each scene as an FBX file", default=False) + BATCH_OWN_DIR = BoolProperty(name="Own Dir", description="Create a dir for each exported file", default=True) + BATCH_FILE_PREFIX = StringProperty(name="Prefix", description="Prefix each file with this name", maxlen= 1024, default="") + def poll(self, context): print("Poll") diff --git a/release/scripts/io/export_mdd.py b/release/scripts/io/export_mdd.py index 9a2ba6fe67d..ebf5b32fa88 100644 --- a/release/scripts/io/export_mdd.py +++ b/release/scripts/io/export_mdd.py @@ -133,6 +133,8 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS): """ sce.set_frame(orig_frame) +from bpy.props import * + class EXPORT_OT_mdd(bpy.types.Operator): '''Animated mesh to MDD vertex keyframe file.''' bl_idname = "export.mdd" @@ -148,12 +150,10 @@ class EXPORT_OT_mdd(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "tmp.mdd"), - bpy.props.IntProperty(attr="fps", name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25), - bpy.props.IntProperty(attr="start_frame", name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1), - bpy.props.IntProperty(attr="end_frame", name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250), - ] + path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "tmp.mdd") + fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25) + start_frame = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1) + end_frame = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250) def poll(self, context): return context.active_object != None diff --git a/release/scripts/io/export_obj.py b/release/scripts/io/export_obj.py index 641ebec3150..7a0031229f7 100644 --- a/release/scripts/io/export_obj.py +++ b/release/scripts/io/export_obj.py @@ -913,6 +913,9 @@ Currently the exporter lacks these features: * multiple scene export (only active scene is written) * particles ''' + +from bpy.props import * + class EXPORT_OT_obj(bpy.types.Operator): '''Save a Wavefront OBJ File''' @@ -922,35 +925,34 @@ class EXPORT_OT_obj(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the OBJ file", maxlen= 1024, default= ""), + path = StringProperty(name="File Path", description="File path used for exporting the OBJ file", maxlen= 1024, default= "") - # context group - bpy.props.BoolProperty(attr="use_selection", name="Selection Only", description="", default= False), - bpy.props.BoolProperty(attr="use_all_scenes", name="All Scenes", description="", default= False), - bpy.props.BoolProperty(attr="use_animation", name="All Animation", description="", default= False), + # context group + use_selection = BoolProperty(name="Selection Only", description="", default= False) + use_all_scenes = BoolProperty(name="All Scenes", description="", default= False) + use_animation = BoolProperty(name="All Animation", description="", default= False) - # object group - bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="", default= True), - bpy.props.BoolProperty(attr="use_rotate90", name="Rotate X90", description="", default= True), + # object group + use_modifiers = BoolProperty(name="Apply Modifiers", description="", default= True) + use_rotate90 = BoolProperty(name="Rotate X90", description="", default= True) - # extra data group - bpy.props.BoolProperty(attr="use_edges", name="Edges", description="", default= True), - bpy.props.BoolProperty(attr="use_normals", name="Normals", description="", default= False), - bpy.props.BoolProperty(attr="use_hq_normals", name="High Quality Normals", description="", default= True), - bpy.props.BoolProperty(attr="use_uvs", name="UVs", description="", default= True), - bpy.props.BoolProperty(attr="use_materials", name="Materials", description="", default= True), - bpy.props.BoolProperty(attr="copy_images", name="Copy Images", description="", default= False), - bpy.props.BoolProperty(attr="use_triangles", name="Triangulate", description="", default= False), - bpy.props.BoolProperty(attr="use_vertex_groups", name="Polygroups", description="", default= False), - bpy.props.BoolProperty(attr="use_nurbs", name="Nurbs", description="", default= False), + # extra data group + use_edges = BoolProperty(name="Edges", description="", default= True) + use_normals = BoolProperty(name="Normals", description="", default= False) + use_hq_normals = BoolProperty(name="High Quality Normals", description="", default= True) + use_uvs = BoolProperty(name="UVs", description="", default= True) + use_materials = BoolProperty(name="Materials", description="", default= True) + copy_images = BoolProperty(name="Copy Images", description="", default= False) + use_triangles = BoolProperty(name="Triangulate", description="", default= False) + use_vertex_groups = BoolProperty(name="Polygroups", description="", default= False) + use_nurbs = BoolProperty(name="Nurbs", description="", default= False) - # grouping group - bpy.props.BoolProperty(attr="use_blen_objects", name="Objects as OBJ Objects", description="", default= True), - bpy.props.BoolProperty(attr="group_by_object", name="Objects as OBJ Groups ", description="", default= False), - bpy.props.BoolProperty(attr="group_by_material", name="Material Groups", description="", default= False), - bpy.props.BoolProperty(attr="keep_vertex_order", name="Keep Vertex Order", description="", default= False) - ] + # grouping group + use_blen_objects = BoolProperty(name="Objects as OBJ Objects", description="", default= True) + group_by_object = BoolProperty(name="Objects as OBJ Groups ", description="", default= False) + group_by_material = BoolProperty(name="Material Groups", description="", default= False) + keep_vertex_order = BoolProperty(name="Keep Vertex Order", description="", default= False) + def execute(self, context): diff --git a/release/scripts/io/export_ply.py b/release/scripts/io/export_ply.py index 67cd6a85599..fedf50d6a4e 100644 --- a/release/scripts/io/export_ply.py +++ b/release/scripts/io/export_ply.py @@ -231,6 +231,9 @@ def write(filename, scene, ob, \ Blender.Window.EditMode(1, '', 0) """ +from bpy.props import * + + class EXPORT_OT_ply(bpy.types.Operator): '''Export a single object as a stanford PLY with normals, colours and texture coordinates.''' bl_idname = "export.ply" @@ -239,13 +242,13 @@ class EXPORT_OT_ply(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""), - bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True), - bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True), - bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True), - bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True) - ] + + path = StringProperty(name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "") + use_modifiers = BoolProperty(name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True) + use_normals = BoolProperty(name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True) + use_uvs = BoolProperty(name="Export UVs", description="Exort the active UV layer", default= True) + use_colors = BoolProperty(name="Export Vertex Colors", description="Exort the active vertex color layer", default= True) + def poll(self, context): return context.active_object != None diff --git a/release/scripts/io/export_x3d.py b/release/scripts/io/export_x3d.py index ad9abc5162a..a360e2cd17f 100644 --- a/release/scripts/io/export_x3d.py +++ b/release/scripts/io/export_x3d.py @@ -1196,6 +1196,8 @@ def x3d_export_ui(filename): # if __name__ == '__main__': # Blender.Window.FileSelector(x3d_export_ui,"Export X3D", Blender.Get('filename').replace('.blend', '.x3d')) +from bpy.props import * + class EXPORT_OT_x3d(bpy.types.Operator): '''Export selection to Extensible 3D file (.x3d)''' bl_idname = "export.x3d" @@ -1203,14 +1205,12 @@ class EXPORT_OT_x3d(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the X3D file", maxlen= 1024, default= ""), - - bpy.props.BoolProperty(attr="apply_modifiers", name="Apply Modifiers", description="Use transformed mesh data from each object.", default=True), - bpy.props.BoolProperty(attr="triangulate", name="Triangulate", description="Triangulate quads.", default=False), - bpy.props.BoolProperty(attr="compress", name="Compress", description="GZip the resulting file, requires a full python install.", default=False), - ] + path = StringProperty(name="File Path", description="File path used for exporting the X3D file", maxlen= 1024, default= "") + + apply_modifiers = BoolProperty(name="Apply Modifiers", description="Use transformed mesh data from each object.", default=True) + triangulate = BoolProperty(name="Triangulate", description="Triangulate quads.", default=False) + compress = BoolProperty(name="Compress", description="GZip the resulting file, requires a full python install.", default=False) + def execute(self, context): x3d_export(self.path, context, self.apply_modifiers, self.triangulate, self.compress) diff --git a/release/scripts/io/import_3ds.py b/release/scripts/io/import_3ds.py index 38eef583ecd..581192bcfbf 100644 --- a/release/scripts/io/import_3ds.py +++ b/release/scripts/io/import_3ds.py @@ -1121,6 +1121,8 @@ else: print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME) ''' +from bpy.props import * + class IMPORT_OT_autodesk_3ds(bpy.types.Operator): '''Import from 3DS file format (.3ds)''' @@ -1129,14 +1131,12 @@ class IMPORT_OT_autodesk_3ds(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. + + path = StringProperty(name="File Path", description="File path used for importing the 3DS file", maxlen= 1024, default= ""), - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for importing the 3DS file", maxlen= 1024, default= ""), - -# bpy.props.FloatProperty(attr="size_constraint", name="Size Constraint", description="Scale the model by 10 until it reacehs the size constraint. Zero Disables.", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=10.0), -# bpy.props.BoolProperty(attr="search_images", name="Image Search", description="Search subdirectories for any assosiated images (Warning, may be slow)", default=True), -# bpy.props.BoolProperty(attr="apply_matrix", name="Transform Fix", description="Workaround for object transformations importing incorrectly", default=False), - ] +# size_constraint = FloatProperty(name="Size Constraint", description="Scale the model by 10 until it reacehs the size constraint. Zero Disables.", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=10.0), +# search_images = BoolProperty(name="Image Search", description="Search subdirectories for any assosiated images (Warning, may be slow)", default=True), +# apply_matrix = BoolProperty(name="Transform Fix", description="Workaround for object transformations importing incorrectly", default=False), def execute(self, context): load_3ds(self.path, context, 0.0, False, False) diff --git a/release/scripts/io/import_obj.py b/release/scripts/io/import_obj.py index eaa76942a11..2e3473edb25 100644 --- a/release/scripts/io/import_obj.py +++ b/release/scripts/io/import_obj.py @@ -1553,6 +1553,8 @@ else: print 'TOTAL TIME: %.6f' % (sys.time() - TIME) ''' +from bpy.props import * + class IMPORT_OT_obj(bpy.types.Operator): '''Load a Wavefront OBJ File.''' bl_idname = "import.obj" @@ -1561,23 +1563,23 @@ class IMPORT_OT_obj(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for importing the OBJ file", maxlen= 1024, default= ""), + + path = StringProperty(name="File Path", description="File path used for importing the OBJ file", maxlen= 1024, default= "") - bpy.props.BoolProperty(attr="CREATE_SMOOTH_GROUPS", name="Smooth Groups", description="Surround smooth groups by sharp edges", default= True), - bpy.props.BoolProperty(attr="CREATE_FGONS", name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default= True), - bpy.props.BoolProperty(attr="CREATE_EDGES", name="Lines as Edges", description="Import lines and faces with 2 verts as edge", default= True), - bpy.props.BoolProperty(attr="SPLIT_OBJECTS", name="Object", description="Import OBJ Objects into Blender Objects", default= True), - bpy.props.BoolProperty(attr="SPLIT_GROUPS", name="Group", description="Import OBJ Groups into Blender Objects", default= True), - bpy.props.BoolProperty(attr="SPLIT_MATERIALS", name="Material", description="Import each material into a seperate mesh (Avoids > 16 per mesh error)", default= True), - # old comment: only used for user feedback - # disabled this option because in old code a handler for it disabled SPLIT* params, it's not passed to load_obj - # bpy.props.BoolProperty(attr="KEEP_VERT_ORDER", name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True), - bpy.props.BoolProperty(attr="ROTATE_X90", name="-X90", description="Rotate X 90.", default= True), - bpy.props.FloatProperty(attr="CLAMP_SIZE", name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.01, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0), - bpy.props.BoolProperty(attr="POLYGROUPS", name="Poly Groups", description="Import OBJ groups as vertex groups.", default= True), - bpy.props.BoolProperty(attr="IMAGE_SEARCH", name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default= True), - ] + CREATE_SMOOTH_GROUPS = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default= True) + CREATE_FGONS = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default= True) + CREATE_EDGES = BoolProperty(name="Lines as Edges", description="Import lines and faces with 2 verts as edge", default= True) + SPLIT_OBJECTS = BoolProperty(name="Object", description="Import OBJ Objects into Blender Objects", default= True) + SPLIT_GROUPS = BoolProperty(name="Group", description="Import OBJ Groups into Blender Objects", default= True) + SPLIT_MATERIALS = BoolProperty(name="Material", description="Import each material into a seperate mesh (Avoids > 16 per mesh error)", default= True) + # old comment: only used for user feedback + # disabled this option because in old code a handler for it disabled SPLIT* params, it's not passed to load_obj + # KEEP_VERT_ORDER = BoolProperty(name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True) + ROTATE_X90 = BoolProperty(name="-X90", description="Rotate X 90.", default= True) + CLAMP_SIZE = FloatProperty(name="Clamp Scale", description="Clamp the size to this maximum (Zero to Disable)", min=0.01, max=1000.0, soft_min=0.0, soft_max=1000.0, default=0.0) + POLYGROUPS = BoolProperty(name="Poly Groups", description="Import OBJ groups as vertex groups.", default= True) + IMAGE_SEARCH = BoolProperty(name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default= True) + def execute(self, context): # print("Selected: " + context.active_object.name) diff --git a/release/scripts/io/mesh_skin.py b/release/scripts/io/mesh_skin.py index c7528c984b2..9db66e16444 100644 --- a/release/scripts/io/mesh_skin.py +++ b/release/scripts/io/mesh_skin.py @@ -626,9 +626,8 @@ class MESH_OT_skin(bpy.types.Operator): bl_undo = True ''' - bl_props = [ - bpy.props.EnumProperty(attr="loft_method", items=[(), ()], description="", default= True), - ] + loft_method = EnumProperty(attr="loft_method", items=[(), ()], description="", default= True) + ''' def execute(self, context): diff --git a/release/scripts/io/netrender/operators.py b/release/scripts/io/netrender/operators.py index 468cbba6564..e14b4a36fc7 100644 --- a/release/scripts/io/netrender/operators.py +++ b/release/scripts/io/netrender/operators.py @@ -13,11 +13,6 @@ class RENDER_OT_netclientanim(bpy.types.Operator): bl_idname = "render.netclientanim" bl_label = "Animation on network" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -44,11 +39,6 @@ class RENDER_OT_netclientsend(bpy.types.Operator): bl_idname = "render.netclientsend" bl_label = "Send job" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -73,11 +63,6 @@ class RENDER_OT_netclientstatus(bpy.types.Operator): bl_idname = "render.netclientstatus" bl_label = "Client Status" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -118,11 +103,6 @@ class RENDER_OT_netclientblacklistslave(bpy.types.Operator): bl_idname = "render.netclientblacklistslave" bl_label = "Client Blacklist Slave" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -153,11 +133,6 @@ class RENDER_OT_netclientwhitelistslave(bpy.types.Operator): bl_idname = "render.netclientwhitelistslave" bl_label = "Client Whitelist Slave" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -189,11 +164,6 @@ class RENDER_OT_netclientslaves(bpy.types.Operator): bl_idname = "render.netclientslaves" bl_label = "Client Slaves" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -239,11 +209,6 @@ class RENDER_OT_netclientcancel(bpy.types.Operator): bl_idname = "render.netclientcancel" bl_label = "Client Cancel" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): netsettings = context.scene.network_render return netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0 @@ -273,11 +238,6 @@ class RENDER_OT_netclientcancelall(bpy.types.Operator): bl_idname = "render.netclientcancelall" bl_label = "Client Cancel All" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -305,11 +265,6 @@ class netclientdownload(bpy.types.Operator): bl_idname = "render.netclientdownload" bl_label = "Client Download" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): netsettings = context.scene.network_render return netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0 @@ -355,11 +310,6 @@ class netclientscan(bpy.types.Operator): bl_idname = "render.netclientscan" bl_label = "Client Scan" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True @@ -393,11 +343,6 @@ class netclientweb(bpy.types.Operator): bl_idname = "render.netclientweb" bl_label = "Open Master Monitor" - # List of operator properties, the attributes will be assigned - # to the class instance from the operator settings before calling. - - bl_props = [] - def poll(self, context): return True diff --git a/release/scripts/modules/bpy_ops.py b/release/scripts/modules/bpy_ops.py index eb793b1b7bc..1f6d6bf8526 100644 --- a/release/scripts/modules/bpy_ops.py +++ b/release/scripts/modules/bpy_ops.py @@ -182,10 +182,10 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator): bpy.ops.mesh.remove_doubles() return ('FINISHED',) -rna_path_prop = StringProperty(attr="path", name="Context Attributes", +rna_path_prop = StringProperty(name="Context Attributes", description="rna context string", maxlen=1024, default="") -rna_reverse_prop = BoolProperty(attr="reverse", name="Reverse", +rna_reverse_prop = BoolProperty(name="Reverse", description="Cycle backwards", default=False) @@ -220,11 +220,11 @@ class WM_OT_context_set_boolean(bpy.types.Operator): '''Set a context value.''' bl_idname = "wm.context_set_boolean" bl_label = "Context Set" - bl_props = [ - rna_path_prop, - BoolProperty(attr="value", name="Value", - description="Assignment value", default=True)] - + + path = rna_path_prop + value = BoolProperty(name="Value", + description="Assignment value", default=True) + execute = execute_context_assign @@ -232,10 +232,10 @@ class WM_OT_context_set_int(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_int" bl_label = "Context Set" - bl_props = [ - rna_path_prop, - IntProperty(attr="value", name="Value", - description="Assignment value", default=0)] + + path = rna_path_prop + value = IntProperty(name="Value", description="Assign value", default=0) + execute = execute_context_assign @@ -243,10 +243,11 @@ class WM_OT_context_set_float(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_int" bl_label = "Context Set" - bl_props = [ - rna_path_prop, - FloatProperty(attr="value", name="Value", - description="Assignment value", default=0.0)] + + path = rna_path_prop + value = FloatProperty(name="Value", + description="Assignment value", default=0.0) + execute = execute_context_assign @@ -254,10 +255,10 @@ class WM_OT_context_set_string(bpy.types.Operator): # same as enum '''Set a context value.''' bl_idname = "wm.context_set_string" bl_label = "Context Set" - bl_props = [ - rna_path_prop, - StringProperty(attr="value", name="Value", - description="Assignment value", maxlen=1024, default="")] + + path = rna_path_prop + value = StringProperty(name="Value", + description="Assign value", maxlen=1024, default="") execute = execute_context_assign @@ -266,11 +267,11 @@ class WM_OT_context_set_enum(bpy.types.Operator): '''Set a context value.''' bl_idname = "wm.context_set_enum" bl_label = "Context Set" - bl_props = [ - rna_path_prop, - StringProperty(attr="value", name="Value", + + path = rna_path_prop + value = StringProperty(name="Value", description="Assignment value (as a string)", - maxlen=1024, default="")] + maxlen=1024, default="") execute = execute_context_assign @@ -279,7 +280,7 @@ class WM_OT_context_toggle(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_toggle" bl_label = "Context Toggle" - bl_props = [rna_path_prop] + path = rna_path_prop def execute(self, context): @@ -294,13 +295,13 @@ class WM_OT_context_toggle_enum(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_toggle_enum" bl_label = "Context Toggle Values" - bl_props = [ - rna_path_prop, - StringProperty(attr="value_1", name="Value", \ - description="Toggle enum", maxlen=1024, default=""), - StringProperty(attr="value_2", name="Value", \ - description="Toggle enum", maxlen=1024, default="")] + path = rna_path_prop + value_1 = StringProperty(name="Value", \ + description="Toggle enum", maxlen=1024, default="") + + value_2 = StringProperty(name="Value", \ + description="Toggle enum", maxlen=1024, default="") def execute(self, context): @@ -318,7 +319,8 @@ class WM_OT_context_cycle_int(bpy.types.Operator): vertex keys, groups' etc.''' bl_idname = "wm.context_cycle_int" bl_label = "Context Int Cycle" - bl_props = [rna_path_prop, rna_reverse_prop] + path = rna_path_prop + reverse = rna_reverse_prop def execute(self, context): @@ -348,7 +350,9 @@ class WM_OT_context_cycle_enum(bpy.types.Operator): '''Toggle a context value.''' bl_idname = "wm.context_cycle_enum" bl_label = "Context Enum Cycle" - bl_props = [rna_path_prop, rna_reverse_prop] + + path = rna_path_prop + reverse = rna_reverse_prop def execute(self, context): @@ -392,10 +396,10 @@ class WM_OT_context_cycle_enum(bpy.types.Operator): exec("context.%s=advance_enum" % self.path) return ('FINISHED',) -doc_id = StringProperty(attr="doc_id", name="Doc ID", +doc_id = StringProperty(name="Doc ID", description="ID for the documentation", maxlen=1024, default="") -doc_new = StringProperty(attr="doc_new", name="Doc New", +doc_new = StringProperty(name="Doc New", description="", maxlen=1024, default="") @@ -403,7 +407,8 @@ class WM_OT_doc_view(bpy.types.Operator): '''Load online reference docs''' bl_idname = "wm.doc_view" bl_label = "View Documentation" - bl_props = [doc_id] + + doc_id = doc_id _prefix = 'http://www.blender.org/documentation/250PythonDoc' def _nested_class_string(self, class_string): @@ -444,7 +449,10 @@ class WM_OT_doc_edit(bpy.types.Operator): '''Load online reference docs''' bl_idname = "wm.doc_edit" bl_label = "Edit Documentation" - bl_props = [doc_id, doc_new] + + doc_id = doc_id + doc_new = doc_new + _url = "http://www.mindrones.com/blender/svn/xmlrpc.php" def _send_xmlrpc(self, data_dict): diff --git a/release/scripts/templates/operator.py b/release/scripts/templates/operator.py index 30d4ad83dc6..c03d5850237 100644 --- a/release/scripts/templates/operator.py +++ b/release/scripts/templates/operator.py @@ -1,6 +1,10 @@ +import bpy + def write_some_data(context, path, use_some_setting): pass - + +from bpy.props import * + class ExportSomeData(bpy.types.Operator): '''This appiers in the tooltip of the operator and in the generated docs.''' bl_idname = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed @@ -10,10 +14,8 @@ class ExportSomeData(bpy.types.Operator): # to the class instance from the operator settings before calling. # TODO, add better example props - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""), - bpy.props.BoolProperty(attr="use_some_setting", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True), - ] + path = StringProperty(name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "") + use_some_setting = BoolProperty(name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True) def poll(self, context): return context.active_object != None diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index c03c9ff2a2f..b5fdf2fcea0 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -554,12 +554,15 @@ bpy.types.register(USERPREF_PT_system) bpy.types.register(USERPREF_PT_file) bpy.types.register(USERPREF_PT_input) +from bpy.props import * + + class WM_OT_keyconfig_export(bpy.types.Operator): "Export key configuration to a python script." bl_idname = "wm.keyconfig_export" bl_label = "Export Key Configuration..." - bl_props = [ - bpy.props.StringProperty(attr="path", name="File Path", description="File path to write file to.")] + + path = bpy.props.StringProperty(name="File Path", description="File path to write file to.") def _string_value(self, value): result = "" @@ -657,7 +660,8 @@ class WM_OT_keymap_restore(bpy.types.Operator): "Restore key map" bl_idname = "wm.keymap_restore" bl_label = "Restore Key Map" - bl_props = [bpy.props.BoolProperty(attr="all", name="All Keymaps", description="Restore all keymaps to default.")] + + all = BoolProperty(attr="all", name="All Keymaps", description="Restore all keymaps to default.") def execute(self, context): wm = context.manager diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index 0a132355bf9..f0d1a0dcc6c 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -1439,6 +1439,8 @@ class VIEW3D_PT_etch_a_ton(bpy.types.Panel): # Operators +from bpy.props import * + class OBJECT_OT_select_pattern(bpy.types.Operator): '''Select object matching a naming pattern.''' @@ -1446,11 +1448,11 @@ class OBJECT_OT_select_pattern(bpy.types.Operator): bl_label = "Select Pattern" bl_register = True bl_undo = True - bl_props = [ - bpy.props.StringProperty(attr="pattern", name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen= 32, default= "*"), - bpy.props.BoolProperty(attr="case_sensitive", name="Case Sensitive", description="Do a case sensitive compare", default= False), - bpy.props.BoolProperty(attr="extend", name="Extend", description="Extend the existing selection", default= True), - ] + + pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen= 32, default= "*") + case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default= False) + extend = BoolProperty(name="Extend", description="Extend the existing selection", default= True) + def execute(self, context): diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 959213b77aa..aeb99779d33 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -41,7 +41,6 @@ #include "../generic/bpy_internal_import.h" // our own imports -#define PYOP_ATTR_PROP "bl_props" #define PYOP_ATTR_UINAME "bl_label" #define PYOP_ATTR_IDNAME "bl_idname" /* the name given by python */ #define PYOP_ATTR_IDNAME_BL "_bl_idname" /* our own name converted into blender syntax, users wont see this */ @@ -300,46 +299,18 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata) PyErr_Clear(); } - - - props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP); - - if (props) { - PyObject *dummy_args = PyTuple_New(0); - int i; - - for(i=0; isrna, NULL); - - py_ret = pyfunc(py_srna_cobject, dummy_args, py_kw); - if (py_ret) { - Py_DECREF(py_ret); - } else { - fprintf(stderr, "BPy Operator \"%s\" registration error: %s item %d could not run\n", ot->idname, PYOP_ATTR_PROP, i); - PyLineSpit(); - PyErr_Print(); - PyErr_Clear(); - } - Py_DECREF(py_srna_cobject); - - } else { - /* cant return NULL from here */ // XXX a bit ugly - PyErr_Print(); - PyErr_Clear(); - } - - // expect a tuple with a CObject and a dict + /* Can't use this because it returns a dict proxy + * + * item= PyObject_GetAttrString(py_class, "__dict__"); + */ + item= ((PyTypeObject*)py_class)->tp_dict; + if(item) { + if(pyrna_deferred_register_props(ot->srna, item)!=0) { + PyErr_Print(); + PyErr_Clear(); } - Py_DECREF(dummy_args); - Py_DECREF(props); - } else { + } + else { PyErr_Clear(); } } @@ -359,7 +330,6 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) static struct BPY_class_attr_check pyop_class_attr_values[]= { {PYOP_ATTR_IDNAME, 's', -1, OP_MAX_TYPENAME-3, 0}, /* -3 because a.b -> A_OT_b */ {PYOP_ATTR_UINAME, 's', -1,-1, BPY_CLASS_ATTR_OPTIONAL}, - {PYOP_ATTR_PROP, 'l', -1,-1, BPY_CLASS_ATTR_OPTIONAL}, {PYOP_ATTR_DESCRIPTION, 's', -1,-1, BPY_CLASS_ATTR_NONE_OK}, {"execute", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL}, {"invoke", 'f', 3, -1, BPY_CLASS_ATTR_OPTIONAL}, @@ -400,24 +370,6 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class) WM_operatortype_remove(idname); } - /* If we have properties set, check its a list of dicts */ - item= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP); - if (item) { - for(i=0; i 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -2831,6 +2828,10 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:BoolProperty", kwlist, &id, &name, &description, &def)) + return NULL; + prop= RNA_def_boolean(srna, id, def, name, description); RNA_def_property_duplicate_pointers(prop); Py_RETURN_NONE; @@ -2843,13 +2844,10 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL}; - char *id, *name="", *description=""; + char *id=NULL, *name="", *description=""; int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, def=0; PropertyRNA *prop; StructRNA *srna; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiiiii:IntProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -2861,6 +2859,10 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiiiii:IntProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def)) + return NULL; + prop= RNA_def_int(srna, id, def, min, max, name, description, soft_min, soft_max); RNA_def_property_duplicate_pointers(prop); Py_RETURN_NONE; @@ -2873,13 +2875,10 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL}; - char *id, *name="", *description=""; + char *id=NULL, *name="", *description=""; float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, def=0.0f; PropertyRNA *prop; StructRNA *srna; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffff:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -2891,6 +2890,10 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffff:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def)) + return NULL; + prop= RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max); RNA_def_property_duplicate_pointers(prop); Py_RETURN_NONE; @@ -2903,13 +2906,10 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL}; - char *id, *name="", *description="", *def=""; + char *id=NULL, *name="", *description="", *def=""; int maxlen=0; PropertyRNA *prop; StructRNA *srna; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -2921,6 +2921,10 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def)) + return NULL; + prop= RNA_def_string(srna, id, def, maxlen, name, description); RNA_def_property_duplicate_pointers(prop); Py_RETURN_NONE; @@ -2979,15 +2983,12 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, const char *def, in PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "items", "name", "description", "default", NULL}; - char *id, *name="", *description="", *def=""; + char *id=NULL, *name="", *description="", *def=""; int defvalue=0; PyObject *items= Py_None; EnumPropertyItem *eitems; PropertyRNA *prop; StructRNA *srna; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sss:EnumProperty", kwlist, &id, &items, &name, &description, &def)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -2999,6 +3000,10 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sss:EnumProperty", kwlist, &id, &items, &name, &description, &def)) + return NULL; + eitems= enum_items_from_py(items, def, &defvalue); if(!eitems) return NULL; @@ -3035,13 +3040,10 @@ static StructRNA *pointer_type_from_py(PyObject *value) PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "type", "name", "description", NULL}; - char *id, *name="", *description=""; + char *id=NULL, *name="", *description=""; PropertyRNA *prop; StructRNA *srna, *ptype; PyObject *type= Py_None; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:PointerProperty", kwlist, &id, &type, &name, &description)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -3053,6 +3055,10 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:PointerProperty", kwlist, &id, &type, &name, &description)) + return NULL; + ptype= pointer_type_from_py(type); if(!ptype) return NULL; @@ -3070,13 +3076,10 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = {"attr", "type", "name", "description", NULL}; - char *id, *name="", *description=""; + char *id=NULL, *name="", *description=""; PropertyRNA *prop; StructRNA *srna, *ptype; PyObject *type= Py_None; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:CollectionProperty", kwlist, &id, &type, &name, &description)) - return NULL; if (PyTuple_Size(args) > 0) { PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. @@ -3088,6 +3091,10 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { + + if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:CollectionProperty", kwlist, &id, &type, &name, &description)) + return NULL; + ptype= pointer_type_from_py(type); if(!ptype) return NULL; @@ -3102,50 +3109,58 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } -static int deferred_register_props(PyObject *py_class, StructRNA *srna) +int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) { - PyObject *props, *dummy_args, *item; - int i; - - props= PyObject_GetAttrString(py_class, "bl_props"); - - if(!props) { - PyErr_Clear(); - return 1; - } + PyObject *dummy_args, *item, *key; + Py_ssize_t pos = 0; dummy_args = PyTuple_New(0); - - for(i=0; itp_dict; + if(item) { + if(pyrna_deferred_register_props(srna_new, item)!=0) { + return NULL; + } + } + else { + PyErr_Clear(); + } Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index d006b168f45..d480fd3ec9b 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -91,6 +91,8 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *pyrna_basetype_register(PyObject *self, PyObject *args); PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args); +int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict); + /* called before stopping python */ void pyrna_alloc_types(void); void pyrna_free_types(void);