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)
This commit is contained in:
Campbell Barton 2009-10-31 16:40:14 +00:00
parent ea265fc697
commit e4881eef52
18 changed files with 285 additions and 338 deletions

@ -46,6 +46,7 @@ def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG):
return verts, faces return verts, faces
from bpy.props import *
class MESH_OT_primitive_torus_add(bpy.types.Operator): class MESH_OT_primitive_torus_add(bpy.types.Operator):
'''Add a torus mesh.''' '''Add a torus mesh.'''
@ -53,12 +54,11 @@ class MESH_OT_primitive_torus_add(bpy.types.Operator):
bl_label = "Add Torus" bl_label = "Add Torus"
bl_register = True bl_register = True
bl_undo = 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), 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)
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), 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)
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), major_segments = IntProperty(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), 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): def execute(self, context):
verts_loc, faces = add_torus(self.major_radius, self.minor_radius, self.major_segments, self.minor_segments) verts_loc, faces = add_torus(self.major_radius, self.minor_radius, self.major_segments, self.minor_segments)

@ -1090,7 +1090,7 @@ def save_3ds(filename, context):
# else: # else:
# Blender.Draw.PupMenu("Error%t|This script requires a full python installation") # Blender.Draw.PupMenu("Error%t|This script requires a full python installation")
# # save_3ds('/test_b.3ds') # # save_3ds('/test_b.3ds')
from bpy.props import *
class EXPORT_OT_autodesk_3ds(bpy.types.Operator): class EXPORT_OT_autodesk_3ds(bpy.types.Operator):
'''Export to 3DS file format (.3ds).''' '''Export to 3DS file format (.3ds).'''
bl_idname = "export.autodesk_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 # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # 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= ""), # filename = StringProperty(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= ""), path = StringProperty(name="File Path", description="File path used for exporting the 3DS file", maxlen= 1024, default= "")
]
def execute(self, context): def execute(self, context):
save_3ds(self.path, context) save_3ds(self.path, context)

@ -3332,7 +3332,7 @@ def write_ui():
# GLOBALS.clear() # GLOBALS.clear()
from bpy.props import *
class EXPORT_OT_fbx(bpy.types.Operator): class EXPORT_OT_fbx(bpy.types.Operator):
'''Selection to an ASCII Autodesk FBX''' '''Selection to an ASCII Autodesk FBX'''
bl_idname = "export.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 # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # 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= ""), path = StringProperty(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), EXP_OBS_SELECTED = BoolProperty(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), # EXP_OBS_SCENE = BoolProperty(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), _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)
bpy.props.BoolProperty(attr="_XROT90", name="Rot X90", description="Rotate all objects 90 degrese about the X axis", default=True), _XROT90 = BoolProperty(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), _YROT90 = BoolProperty(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), _ZROT90 = BoolProperty(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), EXP_EMPTY = BoolProperty(name="Empties", description="Export empty objects", default=True)
bpy.props.BoolProperty(attr="EXP_CAMERA", name="Cameras", description="Export camera objects", default=True), EXP_CAMERA = BoolProperty(name="Cameras", description="Export camera objects", default=True)
bpy.props.BoolProperty(attr="EXP_LAMP", name="Lamps", description="Export lamp objects", default=True), EXP_LAMP = BoolProperty(name="Lamps", description="Export lamp objects", default=True)
bpy.props.BoolProperty(attr="EXP_ARMATURE", name="Armatures", description="Export armature objects", default=True), EXP_ARMATURE = BoolProperty(name="Armatures", description="Export armature objects", default=True)
bpy.props.BoolProperty(attr="EXP_MESH", name="Meshes", description="Export mesh objects", default=True), EXP_MESH = BoolProperty(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), EXP_MESH_APPLY_MOD = BoolProperty(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), EXP_MESH_HQ_NORMALS = BoolProperty(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), EXP_IMAGE_COPY = BoolProperty(name="Copy Image Files", description="Copy image files to the destination path", default=False)
# armature animation # armature animation
bpy.props.BoolProperty(attr="ANIM_ENABLE", name="Enable Animation", description="Export keyframe animation", default=True), ANIM_ENABLE = BoolProperty(name="Enable Animation", description="Export keyframe animation", default=True)
bpy.props.BoolProperty(attr="ANIM_OPTIMIZE", name="Optimize Keyframes", description="Remove double keyframes", default=True), ANIM_OPTIMIZE = BoolProperty(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), 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)
# 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), # ANIM_ACTION_ALL = BoolProperty(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), ANIM_ACTION_ALL = BoolProperty(name="All Actions", description="Use all actions for armatures, if false, use current action", default=False)
# batch # batch
bpy.props.BoolProperty(attr="BATCH_ENABLE", name="Enable Batch", description="Automate exporting multiple scenes or groups to files", default=False), BATCH_ENABLE = BoolProperty(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), 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)
bpy.props.BoolProperty(attr="BATCH_OWN_DIR", name="Own Dir", description="Create a dir for each exported file", default=True), BATCH_OWN_DIR = BoolProperty(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=""), BATCH_FILE_PREFIX = StringProperty(name="Prefix", description="Prefix each file with this name", maxlen= 1024, default="")
]
def poll(self, context): def poll(self, context):
print("Poll") print("Poll")

@ -133,6 +133,8 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS):
""" """
sce.set_frame(orig_frame) sce.set_frame(orig_frame)
from bpy.props import *
class EXPORT_OT_mdd(bpy.types.Operator): class EXPORT_OT_mdd(bpy.types.Operator):
'''Animated mesh to MDD vertex keyframe file.''' '''Animated mesh to MDD vertex keyframe file.'''
bl_idname = "export.mdd" bl_idname = "export.mdd"
@ -148,12 +150,10 @@ class EXPORT_OT_mdd(bpy.types.Operator):
# List of operator properties, the attributes will be assigned # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # to the class instance from the operator settings before calling.
bl_props = [ path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "tmp.mdd")
bpy.props.StringProperty(attr="path", 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)
bpy.props.IntProperty(attr="fps", 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)
bpy.props.IntProperty(attr="start_frame", 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)
bpy.props.IntProperty(attr="end_frame", name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250),
]
def poll(self, context): def poll(self, context):
return context.active_object != None return context.active_object != None

@ -913,6 +913,9 @@ Currently the exporter lacks these features:
* multiple scene export (only active scene is written) * multiple scene export (only active scene is written)
* particles * particles
''' '''
from bpy.props import *
class EXPORT_OT_obj(bpy.types.Operator): class EXPORT_OT_obj(bpy.types.Operator):
'''Save a Wavefront OBJ File''' '''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 # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # to the class instance from the operator settings before calling.
bl_props = [ path = StringProperty(name="File Path", description="File path used for exporting the OBJ file", maxlen= 1024, default= "")
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the OBJ file", maxlen= 1024, default= ""),
# context group # context group
bpy.props.BoolProperty(attr="use_selection", name="Selection Only", description="", default= False), use_selection = BoolProperty(name="Selection Only", description="", default= False)
bpy.props.BoolProperty(attr="use_all_scenes", name="All Scenes", description="", default= False), use_all_scenes = BoolProperty(name="All Scenes", description="", default= False)
bpy.props.BoolProperty(attr="use_animation", name="All Animation", description="", default= False), use_animation = BoolProperty(name="All Animation", description="", default= False)
# object group # object group
bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="", default= True), use_modifiers = BoolProperty(name="Apply Modifiers", description="", default= True)
bpy.props.BoolProperty(attr="use_rotate90", name="Rotate X90", description="", default= True), use_rotate90 = BoolProperty(name="Rotate X90", description="", default= True)
# extra data group # extra data group
bpy.props.BoolProperty(attr="use_edges", name="Edges", description="", default= True), use_edges = BoolProperty(name="Edges", description="", default= True)
bpy.props.BoolProperty(attr="use_normals", name="Normals", description="", default= False), use_normals = BoolProperty(name="Normals", description="", default= False)
bpy.props.BoolProperty(attr="use_hq_normals", name="High Quality Normals", description="", default= True), use_hq_normals = BoolProperty(name="High Quality Normals", description="", default= True)
bpy.props.BoolProperty(attr="use_uvs", name="UVs", description="", default= True), use_uvs = BoolProperty(name="UVs", description="", default= True)
bpy.props.BoolProperty(attr="use_materials", name="Materials", description="", default= True), use_materials = BoolProperty(name="Materials", description="", default= True)
bpy.props.BoolProperty(attr="copy_images", name="Copy Images", description="", default= False), copy_images = BoolProperty(name="Copy Images", description="", default= False)
bpy.props.BoolProperty(attr="use_triangles", name="Triangulate", description="", default= False), use_triangles = BoolProperty(name="Triangulate", description="", default= False)
bpy.props.BoolProperty(attr="use_vertex_groups", name="Polygroups", description="", default= False), use_vertex_groups = BoolProperty(name="Polygroups", description="", default= False)
bpy.props.BoolProperty(attr="use_nurbs", name="Nurbs", description="", default= False), use_nurbs = BoolProperty(name="Nurbs", description="", default= False)
# grouping group # grouping group
bpy.props.BoolProperty(attr="use_blen_objects", name="Objects as OBJ Objects", description="", default= True), use_blen_objects = BoolProperty(name="Objects as OBJ Objects", description="", default= True)
bpy.props.BoolProperty(attr="group_by_object", name="Objects as OBJ Groups ", description="", default= False), group_by_object = BoolProperty(name="Objects as OBJ Groups ", description="", default= False)
bpy.props.BoolProperty(attr="group_by_material", name="Material Groups", description="", default= False), group_by_material = BoolProperty(name="Material Groups", description="", default= False)
bpy.props.BoolProperty(attr="keep_vertex_order", name="Keep Vertex Order", description="", default= False) keep_vertex_order = BoolProperty(name="Keep Vertex Order", description="", default= False)
]
def execute(self, context): def execute(self, context):

@ -231,6 +231,9 @@ def write(filename, scene, ob, \
Blender.Window.EditMode(1, '', 0) Blender.Window.EditMode(1, '', 0)
""" """
from bpy.props import *
class EXPORT_OT_ply(bpy.types.Operator): class EXPORT_OT_ply(bpy.types.Operator):
'''Export a single object as a stanford PLY with normals, colours and texture coordinates.''' '''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
bl_idname = "export.ply" bl_idname = "export.ply"
@ -239,13 +242,13 @@ class EXPORT_OT_ply(bpy.types.Operator):
# List of operator properties, the attributes will be assigned # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # 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= ""), path = StringProperty(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), use_modifiers = BoolProperty(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), use_normals = BoolProperty(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), use_uvs = BoolProperty(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) use_colors = BoolProperty(name="Export Vertex Colors", description="Exort the active vertex color layer", default= True)
]
def poll(self, context): def poll(self, context):
return context.active_object != None return context.active_object != None

@ -1196,6 +1196,8 @@ def x3d_export_ui(filename):
# if __name__ == '__main__': # if __name__ == '__main__':
# Blender.Window.FileSelector(x3d_export_ui,"Export X3D", Blender.Get('filename').replace('.blend', '.x3d')) # 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): class EXPORT_OT_x3d(bpy.types.Operator):
'''Export selection to Extensible 3D file (.x3d)''' '''Export selection to Extensible 3D file (.x3d)'''
bl_idname = "export.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 # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # to the class instance from the operator settings before calling.
path = StringProperty(name="File Path", description="File path used for exporting the X3D file", maxlen= 1024, default= "")
bl_props = [
bpy.props.StringProperty(attr="path", 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)
bpy.props.BoolProperty(attr="apply_modifiers", name="Apply Modifiers", description="Use transformed mesh data from each object.", default=True), compress = BoolProperty(name="Compress", description="GZip the resulting file, requires a full python install.", default=False)
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),
]
def execute(self, context): def execute(self, context):
x3d_export(self.path, context, self.apply_modifiers, self.triangulate, self.compress) x3d_export(self.path, context, self.apply_modifiers, self.triangulate, self.compress)

@ -1121,6 +1121,8 @@ else:
print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME) print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME)
''' '''
from bpy.props import *
class IMPORT_OT_autodesk_3ds(bpy.types.Operator): class IMPORT_OT_autodesk_3ds(bpy.types.Operator):
'''Import from 3DS file format (.3ds)''' '''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 # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # 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 = [ # 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),
bpy.props.StringProperty(attr="path", name="File Path", description="File path used for importing the 3DS file", maxlen= 1024, default= ""), # 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),
# 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),
]
def execute(self, context): def execute(self, context):
load_3ds(self.path, context, 0.0, False, False) load_3ds(self.path, context, 0.0, False, False)

@ -1553,6 +1553,8 @@ else:
print 'TOTAL TIME: %.6f' % (sys.time() - TIME) print 'TOTAL TIME: %.6f' % (sys.time() - TIME)
''' '''
from bpy.props import *
class IMPORT_OT_obj(bpy.types.Operator): class IMPORT_OT_obj(bpy.types.Operator):
'''Load a Wavefront OBJ File.''' '''Load a Wavefront OBJ File.'''
bl_idname = "import.obj" bl_idname = "import.obj"
@ -1561,23 +1563,23 @@ class IMPORT_OT_obj(bpy.types.Operator):
# List of operator properties, the attributes will be assigned # List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling. # 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), CREATE_SMOOTH_GROUPS = BoolProperty(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), CREATE_FGONS = BoolProperty(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), CREATE_EDGES = BoolProperty(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), SPLIT_OBJECTS = BoolProperty(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), SPLIT_GROUPS = BoolProperty(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), 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 # 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 # 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), # KEEP_VERT_ORDER = BoolProperty(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), ROTATE_X90 = BoolProperty(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), 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)
bpy.props.BoolProperty(attr="POLYGROUPS", name="Poly Groups", description="Import OBJ groups as vertex groups.", default= True), POLYGROUPS = BoolProperty(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), IMAGE_SEARCH = BoolProperty(name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default= True)
]
def execute(self, context): def execute(self, context):
# print("Selected: " + context.active_object.name) # print("Selected: " + context.active_object.name)

@ -626,9 +626,8 @@ class MESH_OT_skin(bpy.types.Operator):
bl_undo = True bl_undo = True
''' '''
bl_props = [ loft_method = EnumProperty(attr="loft_method", items=[(), ()], description="", default= True)
bpy.props.EnumProperty(attr="loft_method", items=[(), ()], description="", default= True),
]
''' '''
def execute(self, context): def execute(self, context):

@ -13,11 +13,6 @@ class RENDER_OT_netclientanim(bpy.types.Operator):
bl_idname = "render.netclientanim" bl_idname = "render.netclientanim"
bl_label = "Animation on network" 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): def poll(self, context):
return True return True
@ -44,11 +39,6 @@ class RENDER_OT_netclientsend(bpy.types.Operator):
bl_idname = "render.netclientsend" bl_idname = "render.netclientsend"
bl_label = "Send job" 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): def poll(self, context):
return True return True
@ -73,11 +63,6 @@ class RENDER_OT_netclientstatus(bpy.types.Operator):
bl_idname = "render.netclientstatus" bl_idname = "render.netclientstatus"
bl_label = "Client Status" 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): def poll(self, context):
return True return True
@ -118,11 +103,6 @@ class RENDER_OT_netclientblacklistslave(bpy.types.Operator):
bl_idname = "render.netclientblacklistslave" bl_idname = "render.netclientblacklistslave"
bl_label = "Client Blacklist Slave" 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): def poll(self, context):
return True return True
@ -153,11 +133,6 @@ class RENDER_OT_netclientwhitelistslave(bpy.types.Operator):
bl_idname = "render.netclientwhitelistslave" bl_idname = "render.netclientwhitelistslave"
bl_label = "Client Whitelist Slave" 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): def poll(self, context):
return True return True
@ -189,11 +164,6 @@ class RENDER_OT_netclientslaves(bpy.types.Operator):
bl_idname = "render.netclientslaves" bl_idname = "render.netclientslaves"
bl_label = "Client Slaves" 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): def poll(self, context):
return True return True
@ -239,11 +209,6 @@ class RENDER_OT_netclientcancel(bpy.types.Operator):
bl_idname = "render.netclientcancel" bl_idname = "render.netclientcancel"
bl_label = "Client Cancel" 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): def poll(self, context):
netsettings = context.scene.network_render netsettings = context.scene.network_render
return netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0 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_idname = "render.netclientcancelall"
bl_label = "Client Cancel All" 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): def poll(self, context):
return True return True
@ -305,11 +265,6 @@ class netclientdownload(bpy.types.Operator):
bl_idname = "render.netclientdownload" bl_idname = "render.netclientdownload"
bl_label = "Client Download" 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): def poll(self, context):
netsettings = context.scene.network_render netsettings = context.scene.network_render
return netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0 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_idname = "render.netclientscan"
bl_label = "Client Scan" 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): def poll(self, context):
return True return True
@ -393,11 +343,6 @@ class netclientweb(bpy.types.Operator):
bl_idname = "render.netclientweb" bl_idname = "render.netclientweb"
bl_label = "Open Master Monitor" 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): def poll(self, context):
return True return True

@ -182,10 +182,10 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
bpy.ops.mesh.remove_doubles() bpy.ops.mesh.remove_doubles()
return ('FINISHED',) 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="") 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) description="Cycle backwards", default=False)
@ -220,11 +220,11 @@ class WM_OT_context_set_boolean(bpy.types.Operator):
'''Set a context value.''' '''Set a context value.'''
bl_idname = "wm.context_set_boolean" bl_idname = "wm.context_set_boolean"
bl_label = "Context Set" bl_label = "Context Set"
bl_props = [
rna_path_prop, path = rna_path_prop
BoolProperty(attr="value", name="Value", value = BoolProperty(name="Value",
description="Assignment value", default=True)] description="Assignment value", default=True)
execute = execute_context_assign execute = execute_context_assign
@ -232,10 +232,10 @@ class WM_OT_context_set_int(bpy.types.Operator): # same as enum
'''Set a context value.''' '''Set a context value.'''
bl_idname = "wm.context_set_int" bl_idname = "wm.context_set_int"
bl_label = "Context Set" bl_label = "Context Set"
bl_props = [
rna_path_prop, path = rna_path_prop
IntProperty(attr="value", name="Value", value = IntProperty(name="Value", description="Assign value", default=0)
description="Assignment value", default=0)]
execute = execute_context_assign execute = execute_context_assign
@ -243,10 +243,11 @@ class WM_OT_context_set_float(bpy.types.Operator): # same as enum
'''Set a context value.''' '''Set a context value.'''
bl_idname = "wm.context_set_int" bl_idname = "wm.context_set_int"
bl_label = "Context Set" bl_label = "Context Set"
bl_props = [
rna_path_prop, path = rna_path_prop
FloatProperty(attr="value", name="Value", value = FloatProperty(name="Value",
description="Assignment value", default=0.0)] description="Assignment value", default=0.0)
execute = execute_context_assign execute = execute_context_assign
@ -254,10 +255,10 @@ class WM_OT_context_set_string(bpy.types.Operator): # same as enum
'''Set a context value.''' '''Set a context value.'''
bl_idname = "wm.context_set_string" bl_idname = "wm.context_set_string"
bl_label = "Context Set" bl_label = "Context Set"
bl_props = [
rna_path_prop, path = rna_path_prop
StringProperty(attr="value", name="Value", value = StringProperty(name="Value",
description="Assignment value", maxlen=1024, default="")] description="Assign value", maxlen=1024, default="")
execute = execute_context_assign execute = execute_context_assign
@ -266,11 +267,11 @@ class WM_OT_context_set_enum(bpy.types.Operator):
'''Set a context value.''' '''Set a context value.'''
bl_idname = "wm.context_set_enum" bl_idname = "wm.context_set_enum"
bl_label = "Context Set" bl_label = "Context Set"
bl_props = [
rna_path_prop, path = rna_path_prop
StringProperty(attr="value", name="Value", value = StringProperty(name="Value",
description="Assignment value (as a string)", description="Assignment value (as a string)",
maxlen=1024, default="")] maxlen=1024, default="")
execute = execute_context_assign execute = execute_context_assign
@ -279,7 +280,7 @@ class WM_OT_context_toggle(bpy.types.Operator):
'''Toggle a context value.''' '''Toggle a context value.'''
bl_idname = "wm.context_toggle" bl_idname = "wm.context_toggle"
bl_label = "Context Toggle" bl_label = "Context Toggle"
bl_props = [rna_path_prop] path = rna_path_prop
def execute(self, context): def execute(self, context):
@ -294,13 +295,13 @@ class WM_OT_context_toggle_enum(bpy.types.Operator):
'''Toggle a context value.''' '''Toggle a context value.'''
bl_idname = "wm.context_toggle_enum" bl_idname = "wm.context_toggle_enum"
bl_label = "Context Toggle Values" 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", \ path = rna_path_prop
description="Toggle enum", maxlen=1024, default="")] 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): def execute(self, context):
@ -318,7 +319,8 @@ class WM_OT_context_cycle_int(bpy.types.Operator):
vertex keys, groups' etc.''' vertex keys, groups' etc.'''
bl_idname = "wm.context_cycle_int" bl_idname = "wm.context_cycle_int"
bl_label = "Context Int Cycle" 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): def execute(self, context):
@ -348,7 +350,9 @@ class WM_OT_context_cycle_enum(bpy.types.Operator):
'''Toggle a context value.''' '''Toggle a context value.'''
bl_idname = "wm.context_cycle_enum" bl_idname = "wm.context_cycle_enum"
bl_label = "Context Enum Cycle" 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): def execute(self, context):
@ -392,10 +396,10 @@ class WM_OT_context_cycle_enum(bpy.types.Operator):
exec("context.%s=advance_enum" % self.path) exec("context.%s=advance_enum" % self.path)
return ('FINISHED',) 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="") 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="") description="", maxlen=1024, default="")
@ -403,7 +407,8 @@ class WM_OT_doc_view(bpy.types.Operator):
'''Load online reference docs''' '''Load online reference docs'''
bl_idname = "wm.doc_view" bl_idname = "wm.doc_view"
bl_label = "View Documentation" bl_label = "View Documentation"
bl_props = [doc_id]
doc_id = doc_id
_prefix = 'http://www.blender.org/documentation/250PythonDoc' _prefix = 'http://www.blender.org/documentation/250PythonDoc'
def _nested_class_string(self, class_string): def _nested_class_string(self, class_string):
@ -444,7 +449,10 @@ class WM_OT_doc_edit(bpy.types.Operator):
'''Load online reference docs''' '''Load online reference docs'''
bl_idname = "wm.doc_edit" bl_idname = "wm.doc_edit"
bl_label = "Edit Documentation" 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" _url = "http://www.mindrones.com/blender/svn/xmlrpc.php"
def _send_xmlrpc(self, data_dict): def _send_xmlrpc(self, data_dict):

@ -1,6 +1,10 @@
import bpy
def write_some_data(context, path, use_some_setting): def write_some_data(context, path, use_some_setting):
pass pass
from bpy.props import *
class ExportSomeData(bpy.types.Operator): class ExportSomeData(bpy.types.Operator):
'''This appiers in the tooltip of the operator and in the generated docs.''' '''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 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. # to the class instance from the operator settings before calling.
# TODO, add better example props # TODO, add better example props
bl_props = [ path = StringProperty(name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= "")
bpy.props.StringProperty(attr="path", 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)
bpy.props.BoolProperty(attr="use_some_setting", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
]
def poll(self, context): def poll(self, context):
return context.active_object != None return context.active_object != None

@ -554,12 +554,15 @@ bpy.types.register(USERPREF_PT_system)
bpy.types.register(USERPREF_PT_file) bpy.types.register(USERPREF_PT_file)
bpy.types.register(USERPREF_PT_input) bpy.types.register(USERPREF_PT_input)
from bpy.props import *
class WM_OT_keyconfig_export(bpy.types.Operator): class WM_OT_keyconfig_export(bpy.types.Operator):
"Export key configuration to a python script." "Export key configuration to a python script."
bl_idname = "wm.keyconfig_export" bl_idname = "wm.keyconfig_export"
bl_label = "Export Key Configuration..." 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): def _string_value(self, value):
result = "" result = ""
@ -657,7 +660,8 @@ class WM_OT_keymap_restore(bpy.types.Operator):
"Restore key map" "Restore key map"
bl_idname = "wm.keymap_restore" bl_idname = "wm.keymap_restore"
bl_label = "Restore Key Map" 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): def execute(self, context):
wm = context.manager wm = context.manager

@ -1439,6 +1439,8 @@ class VIEW3D_PT_etch_a_ton(bpy.types.Panel):
# Operators # Operators
from bpy.props import *
class OBJECT_OT_select_pattern(bpy.types.Operator): class OBJECT_OT_select_pattern(bpy.types.Operator):
'''Select object matching a naming pattern.''' '''Select object matching a naming pattern.'''
@ -1446,11 +1448,11 @@ class OBJECT_OT_select_pattern(bpy.types.Operator):
bl_label = "Select Pattern" bl_label = "Select Pattern"
bl_register = True bl_register = True
bl_undo = True bl_undo = True
bl_props = [
bpy.props.StringProperty(attr="pattern", name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen= 32, default= "*"), pattern = StringProperty(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), case_sensitive = BoolProperty(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), extend = BoolProperty(name="Extend", description="Extend the existing selection", default= True)
]
def execute(self, context): def execute(self, context):

@ -41,7 +41,6 @@
#include "../generic/bpy_internal_import.h" // our own imports #include "../generic/bpy_internal_import.h" // our own imports
#define PYOP_ATTR_PROP "bl_props"
#define PYOP_ATTR_UINAME "bl_label" #define PYOP_ATTR_UINAME "bl_label"
#define PYOP_ATTR_IDNAME "bl_idname" /* the name given by python */ #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 */ #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(); PyErr_Clear();
} }
/* Can't use this because it returns a dict proxy
*
props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP); * item= PyObject_GetAttrString(py_class, "__dict__");
*/
if (props) { item= ((PyTypeObject*)py_class)->tp_dict;
PyObject *dummy_args = PyTuple_New(0); if(item) {
int i; if(pyrna_deferred_register_props(ot->srna, item)!=0) {
PyErr_Print();
for(i=0; i<PyList_Size(props); i++) { PyErr_Clear();
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
item = PyList_GET_ITEM(props, i);
if (PyArg_ParseTuple(item, "O!O!:PYTHON_OT_wrapper", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *);
pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
py_srna_cobject = PyCObject_FromVoidPtr(ot->srna, 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
} }
Py_DECREF(dummy_args); }
Py_DECREF(props); else {
} else {
PyErr_Clear(); 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[]= { 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_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_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}, {PYOP_ATTR_DESCRIPTION, 's', -1,-1, BPY_CLASS_ATTR_NONE_OK},
{"execute", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL}, {"execute", 'f', 2, -1, BPY_CLASS_ATTR_OPTIONAL},
{"invoke", 'f', 3, -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); 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<PyList_Size(item); i++) {
PyObject *py_args = PyList_GET_ITEM(item, i);
PyObject *py_func_ptr, *py_kw; /* place holders */
if (!PyArg_ParseTuple(py_args, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
PyErr_Format(PyExc_ValueError, "Cant register operator class - %s.properties must contain values from FloatProperty", idname);
return NULL;
}
}
Py_DECREF(item);
}
else {
PyErr_Clear();
}
Py_INCREF(py_class); Py_INCREF(py_class);
WM_operatortype_append_ptr(PYTHON_OT_wrapper, py_class); WM_operatortype_append_ptr(PYTHON_OT_wrapper, py_class);

@ -2813,13 +2813,10 @@ static PyObject *bpy_prop_deferred_return(void *func, PyObject *kw)
PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "name", "description", "default", NULL}; static char *kwlist[] = {"attr", "name", "description", "default", NULL};
char *id, *name="", *description=""; char *id=NULL, *name="", *description="";
int def=0; int def=0;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna; StructRNA *srna;
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssi:BoolProperty", kwlist, &id, &name, &description, &def))
return NULL;
if (PyTuple_Size(args) > 0) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); prop= RNA_def_boolean(srna, id, def, name, description);
RNA_def_property_duplicate_pointers(prop); RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE; 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) PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL}; 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; int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, def=0;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna; 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) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); prop= RNA_def_int(srna, id, def, min, max, name, description, soft_min, soft_max);
RNA_def_property_duplicate_pointers(prop); RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE; 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) PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL}; 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; float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, def=0.0f;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna; 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) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); prop= RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max);
RNA_def_property_duplicate_pointers(prop); RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE; 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) PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL}; static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL};
char *id, *name="", *description="", *def=""; char *id=NULL, *name="", *description="", *def="";
int maxlen=0; int maxlen=0;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna; StructRNA *srna;
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def))
return NULL;
if (PyTuple_Size(args) > 0) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); prop= RNA_def_string(srna, id, def, maxlen, name, description);
RNA_def_property_duplicate_pointers(prop); RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE; 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) PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "items", "name", "description", "default", NULL}; static char *kwlist[] = {"attr", "items", "name", "description", "default", NULL};
char *id, *name="", *description="", *def=""; char *id=NULL, *name="", *description="", *def="";
int defvalue=0; int defvalue=0;
PyObject *items= Py_None; PyObject *items= Py_None;
EnumPropertyItem *eitems; EnumPropertyItem *eitems;
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna; StructRNA *srna;
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sss:EnumProperty", kwlist, &id, &items, &name, &description, &def))
return NULL;
if (PyTuple_Size(args) > 0) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); eitems= enum_items_from_py(items, def, &defvalue);
if(!eitems) if(!eitems)
return NULL; return NULL;
@ -3035,13 +3040,10 @@ static StructRNA *pointer_type_from_py(PyObject *value)
PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "type", "name", "description", NULL}; static char *kwlist[] = {"attr", "type", "name", "description", NULL};
char *id, *name="", *description=""; char *id=NULL, *name="", *description="";
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna, *ptype; StructRNA *srna, *ptype;
PyObject *type= Py_None; PyObject *type= Py_None;
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:PointerProperty", kwlist, &id, &type, &name, &description))
return NULL;
if (PyTuple_Size(args) > 0) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); ptype= pointer_type_from_py(type);
if(!ptype) if(!ptype)
return NULL; return NULL;
@ -3070,13 +3076,10 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
{ {
static char *kwlist[] = {"attr", "type", "name", "description", NULL}; static char *kwlist[] = {"attr", "type", "name", "description", NULL};
char *id, *name="", *description=""; char *id=NULL, *name="", *description="";
PropertyRNA *prop; PropertyRNA *prop;
StructRNA *srna, *ptype; StructRNA *srna, *ptype;
PyObject *type= Py_None; PyObject *type= Py_None;
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ss:CollectionProperty", kwlist, &id, &type, &name, &description))
return NULL;
if (PyTuple_Size(args) > 0) { if (PyTuple_Size(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this. 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 */ return NULL; /* self's type was compatible but error getting the srna */
} }
else if(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); ptype= pointer_type_from_py(type);
if(!ptype) if(!ptype)
return NULL; return NULL;
@ -3102,50 +3109,58 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; 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; PyObject *dummy_args, *item, *key;
int i; Py_ssize_t pos = 0;
props= PyObject_GetAttrString(py_class, "bl_props");
if(!props) {
PyErr_Clear();
return 1;
}
dummy_args = PyTuple_New(0); dummy_args = PyTuple_New(0);
for(i=0; i<PyList_Size(props); i++) { while (PyDict_Next(class_dict, &pos, &key, &item)) {
PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret; PyObject *py_func_ptr, *py_kw, *py_srna_cobject, *py_ret;
item = PyList_GET_ITEM(props, i); /* We only care about results from C which
* are for sure types, save some time with error */
if(PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) { if(PyTuple_CheckExact(item)) {
PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *); if(PyArg_ParseTuple(item, "O!O!", &PyCObject_Type, &py_func_ptr, &PyDict_Type, &py_kw)) {
pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
py_srna_cobject = PyCObject_FromVoidPtr(srna, NULL);
py_ret = pyfunc(py_srna_cobject, dummy_args, py_kw);
Py_DECREF(py_srna_cobject);
if(py_ret) { PyObject *(*pyfunc)(PyObject *, PyObject *, PyObject *);
Py_DECREF(py_ret); pyfunc = PyCObject_AsVoidPtr(py_func_ptr);
py_srna_cobject = PyCObject_FromVoidPtr(srna, NULL);
/* not 100% nice :/, modifies the dict passed, should be ok */
PyDict_SetItemString(py_kw, "attr", key);
py_ret = pyfunc(py_srna_cobject, dummy_args, py_kw);
Py_DECREF(py_srna_cobject);
if(py_ret) {
Py_DECREF(py_ret);
}
else {
PyErr_Print();
PyErr_Clear();
PyLineSpit();
PyErr_Format(PyExc_ValueError, "StructRNA \"%.200s\" registration error: %.200s could not run\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
Py_DECREF(dummy_args);
return -1;
}
} }
else { else {
Py_DECREF(dummy_args); /* Since this is a class dict, ignore args that can't be passed */
return 0;
/* for testing only */
/* PyObSpit("Why doesn't this work??", item);
PyErr_Print(); */
PyErr_Clear();
} }
} }
else {
PyErr_Clear();
PyErr_SetString(PyExc_AttributeError, "expected list of dicts for bl_props.");
Py_DECREF(dummy_args);
return 0;
}
} }
Py_DECREF(dummy_args); Py_DECREF(dummy_args);
return 1; return 0;
} }
/*-------------------- Type Registration ------------------------*/ /*-------------------- Type Registration ------------------------*/
@ -3508,8 +3523,19 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class)
// Py_DECREF(py_class); // shuld be able to do this XXX since the old rna adds a new ref. // Py_DECREF(py_class); // shuld be able to do this XXX since the old rna adds a new ref.
} }
if(!deferred_register_props(py_class, srna_new)) /* Can't use this because it returns a dict proxy
return NULL; *
* item= PyObject_GetAttrString(py_class, "__dict__");
*/
item= ((PyTypeObject*)py_class)->tp_dict;
if(item) {
if(pyrna_deferred_register_props(srna_new, item)!=0) {
return NULL;
}
}
else {
PyErr_Clear();
}
Py_RETURN_NONE; Py_RETURN_NONE;
} }

@ -91,6 +91,8 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw);
PyObject *pyrna_basetype_register(PyObject *self, PyObject *args); PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);
PyObject *pyrna_basetype_unregister(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 */ /* called before stopping python */
void pyrna_alloc_types(void); void pyrna_alloc_types(void);
void pyrna_free_types(void); void pyrna_free_types(void);