added new context operator WM_OT_context_cycle_int, use for switching between active...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 21 Oct 2009 10:11:03 +0000 (10:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 21 Oct 2009 10:11:03 +0000 (10:11 +0000)
release/scripts/modules/bpy_ops.py
source/blender/editors/object/object_ops.c

index 61c6dc24ad73d33f72c42b3a34da8a39c3813918..3471ca7be90e31e982bb71ca7602df9b82afd4b5 100644 (file)
@@ -154,6 +154,7 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
                return ('FINISHED',)
 
 rna_path_prop = bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= "")
+rna_reverse_prop = bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)
 
 def execute_context_assign(self, context):
        exec("context.%s=self.value" % self.path)
@@ -216,11 +217,30 @@ class WM_OT_context_toggle_enum(bpy.types.Operator):
                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_int(bpy.types.Operator):
+       '''Set a context value. Useful for cycling active material, vertex keys, groups' etc.'''
+       __idname__ = "wm.context_cycle_int"
+       __label__ = "Context Int Cycle"
+       __props__ = [rna_path_prop, rna_reverse_prop]
+       def execute(self, context):
+               self.value = eval("context.%s" % self.path)
+               if self.reverse:        self.value -= 1
+               else:           self.value += 1
+               execute_context_assign(self, context)
+               
+               if self.value != eval("context.%s" % self.path):
+                       # relies on rna clamping int's out of the range
+                       if self.reverse:        self.value =  (1<<32)
+                       else:           self.value = -(1<<32)
+                       execute_context_assign(self, context)
+                       
+               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__ = [rna_path_prop, bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)]
+       __props__ = [rna_path_prop, rna_reverse_prop]
        def execute(self, context):
                orig_value = eval("context.%s" % self.path) # security nuts will complain.
                
@@ -251,6 +271,7 @@ class WM_OT_context_cycle_enum(bpy.types.Operator):
                exec("context.%s=advance_enum" % self.path)
                return ('FINISHED',)
 
+
 bpy.ops.add(MESH_OT_delete_edgeloop)
 
 bpy.ops.add(WM_OT_context_set_boolean)
@@ -261,4 +282,5 @@ bpy.ops.add(WM_OT_context_set_enum)
 bpy.ops.add(WM_OT_context_toggle)
 bpy.ops.add(WM_OT_context_toggle_enum)
 bpy.ops.add(WM_OT_context_cycle_enum)
+bpy.ops.add(WM_OT_context_cycle_int)
 
index f9fe5ca28fa837b3d7b263e5e2855ce71718e505..624825a18ac4e074dc43b07af7c52e66007dd246 100644 (file)
@@ -291,6 +291,15 @@ void ED_keymap_object(wmKeyConfig *keyconf)
        WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
 
+       /* if 2.4x keys use these can be replaced, could also use page up/down keys to switch vgroups */
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PAGEUPKEY, KM_PRESS, 0, 0);
+       RNA_string_set(kmi->ptr, "path", "object.active_shape_key_index");
+       RNA_boolean_set(kmi->ptr, "reverse", TRUE);
+
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PAGEDOWNKEY, KM_PRESS, 0, 0);
+       RNA_string_set(kmi->ptr, "path", "object.active_shape_key_index");
+
+
        /* Lattice */
        keymap= WM_keymap_find(keyconf, "Lattice", 0, 0);
        keymap->poll= ED_operator_editlattice;