added operators for setting rna for each type, this avoids having double "'quoted...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 14 Oct 2009 20:09:21 +0000 (20:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 14 Oct 2009 20:09:21 +0000 (20:09 +0000)
release/scripts/modules/bpy_ops.py
source/blender/editors/object/object_ops.c
source/blender/editors/space_view3d/view3d_ops.c
source/blender/windowmanager/intern/wm_operators.c

index 0360964be3fba206d6f3c347cf1c987e9676063f..6772a3771cb9f614434e8501f51cf59604336b05 100644 (file)
@@ -153,54 +153,80 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
                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 @@ class WM_OT_context_cycle_enum(bpy.types.Operator):
 
 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)
 
index eea36f630b7e2517a90159b93d3ed5198c988a28..775f9937095f662a550498c77265aad1d0ec5a84 100644 (file)
@@ -281,15 +281,15 @@ void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keym
                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");
        }
 
 }
index 0ac62652b52fa96b7592aa465058f0aaa65b6057..4b692e572e2ca55cb96a0be096c45bfe45bbe294 100644 (file)
@@ -174,20 +174,20 @@ void view3d_keymap(wmKeyConfig *keyconf)
        
        /* 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 @@ void view3d_keymap(wmKeyConfig *keyconf)
        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);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
        RNA_string_set(km->ptr, "path", "space_data.pivot_point");
-       RNA_string_set(km->ptr, "value", "'CURSOR'");
+       RNA_string_set(km->ptr, "value", "CURSOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, KM_CTRL, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
        RNA_string_set(km->ptr, "path", "space_data.pivot_point");
-       RNA_string_set(km->ptr, "value", "'INDIVIDUAL_CENTERS'");
+       RNA_string_set(km->ptr, "value", "INDIVIDUAL_CENTERS");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, KM_ALT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_ALT, 0);
        RNA_string_set(km->ptr, "path", "space_data.pivot_point");
-       RNA_string_set(km->ptr, "value", "'ACTIVE_ELEMENT'");
+       RNA_string_set(km->ptr, "value", "ACTIVE_ELEMENT");
 
 
        transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
index 2ed32808f4810acbd7607b3cf27fbd356ee8d545..5ad138c3890b8556ebce9595f31ea21cce9ecfe7 100644 (file)
@@ -2220,52 +2220,52 @@ void wm_window_keymap(wmKeyConfig *keyconf)
        /* Space switching */
 
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'LOGIC_EDITOR'");
+       RNA_string_set(km->ptr, "value", "LOGIC_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F3KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'NODE_EDITOR'");
+       RNA_string_set(km->ptr, "value", "NODE_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F4KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was data browser */
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F4KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was data browser */
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'CONSOLE'");
+       RNA_string_set(km->ptr, "value", "CONSOLE");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F5KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F5KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'VIEW_3D'");
+       RNA_string_set(km->ptr, "value", "VIEW_3D");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F6KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F6KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'GRAPH_EDITOR'");
+       RNA_string_set(km->ptr, "value", "GRAPH_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F7KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F7KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'PROPERTIES'");
+       RNA_string_set(km->ptr, "value", "PROPERTIES");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F8KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F8KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'SEQUENCE_EDITOR'");
+       RNA_string_set(km->ptr, "value", "SEQUENCE_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F9KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F9KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'OUTLINER'");
+       RNA_string_set(km->ptr, "value", "OUTLINER");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F9KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F9KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'OUTLINER'");
+       RNA_string_set(km->ptr, "value", "OUTLINER");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F10KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F10KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'IMAGE_EDITOR'");
+       RNA_string_set(km->ptr, "value", "IMAGE_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F11KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F11KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'TEXT_EDITOR'");
+       RNA_string_set(km->ptr, "value", "TEXT_EDITOR");
 
-       km = WM_keymap_add_item(keymap, "WM_OT_context_set", F12KEY, KM_PRESS, KM_SHIFT, 0);
+       km = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F12KEY, KM_PRESS, KM_SHIFT, 0);
        RNA_string_set(km->ptr, "path", "area.type");
-       RNA_string_set(km->ptr, "value", "'DOPESHEET_EDITOR'");
+       RNA_string_set(km->ptr, "value", "DOPESHEET_EDITOR");
 }