[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23848] trunk/blender: added operators for setting rna for each type, this avoids having double " 'quoted'" strings from C which is ugly.
Campbell Barton
ideasman42 at gmail.com
Wed Oct 14 22:09:21 CEST 2009
Revision: 23848
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23848
Author: campbellbarton
Date: 2009-10-14 22:09:21 +0200 (Wed, 14 Oct 2009)
Log Message:
-----------
added operators for setting rna for each type, this avoids having double "'quoted'" strings from C which is ugly.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy_ops.py
trunk/blender/source/blender/editors/object/object_ops.c
trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
trunk/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: trunk/blender/release/scripts/modules/bpy_ops.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_ops.py 2009-10-14 19:19:43 UTC (rev 23847)
+++ trunk/blender/release/scripts/modules/bpy_ops.py 2009-10-14 20:09:21 UTC (rev 23848)
@@ -153,54 +153,80 @@
bpy.ops.mesh.remove_doubles()
return ('FINISHED',)
-class WM_OT_context_set(bpy.types.Operator):
+rna_path_prop = bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= "")
+
+class WM_OT_context_set_boolean(bpy.types.Operator):
'''Set a context value.'''
- __idname__ = "wm.context_set"
+ __idname__ = "wm.context_set_boolean"
__label__ = "Context Set"
- __props__ = [
- bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
- bpy.props.StringProperty(attr="value", name="Value", description="Assignment value (as a string)", maxlen= 1024, default= "")
- ]
-
+ __props__ = [rna_path_prop, bpy.props.BoolProperty(attr="value", name="Value", description="Assignment value", default= True)]
def execute(self, context):
exec("context.%s=%s" % (self.path, self.value)) # security nuts will complain.
return ('FINISHED',)
+class WM_OT_context_set_int(bpy.types.Operator): # same as enum
+ '''Set a context value.'''
+ __idname__ = "wm.context_set_int"
+ __label__ = "Context Set"
+ __props__ = [rna_path_prop, bpy.props.IntProperty(attr="value", name="Value", description="Assignment value", default= 0)]
+ def execute(self, context):
+ exec("context.%s=%d" % (self.path, self.value)) # security nuts will complain.
+ return ('FINISHED',)
+
+class WM_OT_context_set_float(bpy.types.Operator): # same as enum
+ '''Set a context value.'''
+ __idname__ = "wm.context_set_int"
+ __label__ = "Context Set"
+ __props__ = [rna_path_prop, bpy.props.FloatProperty(attr="value", name="Value", description="Assignment value", default= 0.0)]
+ def execute(self, context):
+ exec("context.%s=%f" % (self.path, self.value)) # security nuts will complain.
+ return ('FINISHED',)
+
+class WM_OT_context_set_string(bpy.types.Operator): # same as enum
+ '''Set a context value.'''
+ __idname__ = "wm.context_set_string"
+ __label__ = "Context Set"
+ __props__ = [rna_path_prop, bpy.props.StringProperty(attr="value", name="Value", description="Assignment value", maxlen= 1024, default= "")]
+ def execute(self, context):
+ exec("context.%s='%s'" % (self.path, self.value)) # security nuts will complain.
+ return ('FINISHED',)
+
+class WM_OT_context_set_enum(bpy.types.Operator):
+ '''Set a context value.'''
+ __idname__ = "wm.context_set_enum"
+ __label__ = "Context Set"
+ __props__ = [rna_path_prop, bpy.props.StringProperty(attr="value", name="Value", description="Assignment value (as a string)", maxlen= 1024, default= "")]
+ def execute(self, context):
+ exec("context.%s='%s'" % (self.path, self.value)) # security nuts will complain.
+ return ('FINISHED',)
+
class WM_OT_context_toggle(bpy.types.Operator):
'''Toggle a context value.'''
__idname__ = "wm.context_toggle"
__label__ = "Context Toggle"
- __props__ = [
- bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
- ]
-
+ __props__ = [rna_path_prop]
def execute(self, context):
exec("context.%s=not (context.%s)" % (self.path, self.path)) # security nuts will complain.
return ('FINISHED',)
-class WM_OT_context_toggle_values(bpy.types.Operator):
+class WM_OT_context_toggle_enum(bpy.types.Operator):
'''Toggle a context value.'''
- __idname__ = "wm.context_toggle_values"
+ __idname__ = "wm.context_toggle_enum"
__label__ = "Context Toggle Values"
__props__ = [
- bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
- bpy.props.StringProperty(attr="value_1", name="Value", description="Toggle value (as a string)", maxlen= 1024, default= ""),
- bpy.props.StringProperty(attr="value_2", name="Value", description="Toggle value (as a string)", maxlen= 1024, default= "")
+ rna_path_prop,
+ bpy.props.StringProperty(attr="value_1", name="Value", description="Toggle enum", maxlen= 1024, default= ""),
+ bpy.props.StringProperty(attr="value_2", name="Value", description="Toggle enum", maxlen= 1024, default= "")
]
-
def execute(self, context):
- exec("context.%s = [%s, %s][context.%s!=%s]" % (self.path, self.value_1, self.value_2, self.path, self.value_2)) # security nuts will complain.
+ exec("context.%s = ['%s', '%s'][context.%s!='%s']" % (self.path, self.value_1, self.value_2, self.path, self.value_2)) # security nuts will complain.
return ('FINISHED',)
class WM_OT_context_cycle_enum(bpy.types.Operator):
'''Toggle a context value.'''
__idname__ = "wm.context_cycle_enum"
__label__ = "Context Enum Cycle"
- __props__ = [
- bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""),
- bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)
- ]
-
+ __props__ = [rna_path_prop, bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)]
def execute(self, context):
orig_value = eval("context.%s" % self.path) # security nuts will complain.
@@ -233,8 +259,12 @@
bpy.ops.add(MESH_OT_delete_edgeloop)
-bpy.ops.add(WM_OT_context_set)
+bpy.ops.add(WM_OT_context_set_boolean)
+bpy.ops.add(WM_OT_context_set_int)
+bpy.ops.add(WM_OT_context_set_float)
+bpy.ops.add(WM_OT_context_set_string)
+bpy.ops.add(WM_OT_context_set_enum)
bpy.ops.add(WM_OT_context_toggle)
-bpy.ops.add(WM_OT_context_toggle_values)
+bpy.ops.add(WM_OT_context_toggle_enum)
bpy.ops.add(WM_OT_context_cycle_enum)
Modified: trunk/blender/source/blender/editors/object/object_ops.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_ops.c 2009-10-14 19:19:43 UTC (rev 23847)
+++ trunk/blender/source/blender/editors/object/object_ops.c 2009-10-14 20:09:21 UTC (rev 23848)
@@ -281,15 +281,15 @@
km = WM_keymap_add_item(keymap, "WM_OT_context_cycle_enum", OKEY, KM_PRESS, KM_SHIFT, 0);
RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing_falloff");
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", OKEY, KM_PRESS, 0, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", OKEY, KM_PRESS, 0, 0);
RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing");
- RNA_string_set(km->ptr, "value_1", "'DISABLED'");
- RNA_string_set(km->ptr, "value_2", "'ENABLED'");
+ RNA_string_set(km->ptr, "value_1", "DISABLED");
+ RNA_string_set(km->ptr, "value_2", "ENABLED");
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", OKEY, KM_PRESS, KM_ALT, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", OKEY, KM_PRESS, KM_ALT, 0);
RNA_string_set(km->ptr, "path", "scene.tool_settings.proportional_editing");
- RNA_string_set(km->ptr, "value_1", "'DISABLED'");
- RNA_string_set(km->ptr, "value_2", "'CONNECTED'");
+ RNA_string_set(km->ptr, "value_1", "DISABLED");
+ RNA_string_set(km->ptr, "value_2", "CONNECTED");
}
}
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2009-10-14 19:19:43 UTC (rev 23847)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2009-10-14 20:09:21 UTC (rev 23848)
@@ -174,20 +174,20 @@
/* drawtype */
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", ZKEY, KM_PRESS, 0, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
RNA_string_set(km->ptr, "path", "space_data.viewport_shading");
- RNA_string_set(km->ptr, "value_1", "'SOLID'");
- RNA_string_set(km->ptr, "value_2", "'WIREFRAME'");
+ RNA_string_set(km->ptr, "value_1", "SOLID");
+ RNA_string_set(km->ptr, "value_2", "WIREFRAME");
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", ZKEY, KM_PRESS, KM_ALT, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
RNA_string_set(km->ptr, "path", "space_data.viewport_shading");
- RNA_string_set(km->ptr, "value_1", "'TEXTURED'");
- RNA_string_set(km->ptr, "value_2", "'SOLID'");
+ RNA_string_set(km->ptr, "value_1", "TEXTURED");
+ RNA_string_set(km->ptr, "value_2", "SOLID");
- km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", ZKEY, KM_PRESS, KM_SHIFT, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_SHIFT, 0);
RNA_string_set(km->ptr, "path", "space_data.viewport_shading");
- RNA_string_set(km->ptr, "value_1", "'SHADED'");
- RNA_string_set(km->ptr, "value_2", "'WIREFRAME'");
+ RNA_string_set(km->ptr, "value_1", "SHADED");
+ RNA_string_set(km->ptr, "value_2", "WIREFRAME");
/* selection*/
WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
@@ -225,28 +225,28 @@
WM_keymap_add_item(keymap, "VIEW3D_OT_snap_menu", SKEY, KM_PRESS, KM_SHIFT, 0);
/* context ops */
- km = WM_keymap_add_item(keymap, "WM_OT_context_set", COMMAKEY, KM_PRESS, 0, 0);
+ km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
RNA_string_set(km->ptr, "path", "space_data.pivot_point");
- RNA_string_set(km->ptr, "value", "'BOUNDING_BOX_CENTER'");
+ RNA_string_set(km->ptr, "value", "BOUNDING_BOX_CENTER");
- km = WM_keymap_add_item(keymap, "WM_OT_context_set", COMMAKEY, KM_PRESS, KM_CTRL, 0); /* 2.4x allowed Comma+Shift too, rather not use both */
+ km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); /* 2.4x allowed Comma+Shift too, rather not use both */
RNA_string_set(km->ptr, "path", "space_data.pivot_point");
- RNA_string_set(km->ptr, "value", "'MEDIAN_POINT'");
+ RNA_string_set(km->ptr, "value", "MEDIAN_POINT");
km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", COMMAKEY, KM_PRESS, KM_ALT, 0); /* new in 2.5 */
RNA_string_set(km->ptr, "path", "space_data.pivot_point_align");
- km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, 0, 0);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list