added new context operator WM_OT_context_cycle_int, use for switching between active shape keys

This commit is contained in:
Campbell Barton 2009-10-21 10:11:03 +00:00
parent 1f33a90f05
commit 3a6da12ab1
2 changed files with 32 additions and 1 deletions

@ -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)

@ -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;