Revision: 23809 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23809 Author: campbellbarton Date: 2009-10-13 17:30:19 +0200 (Tue, 13 Oct 2009)
Log Message: ----------- Context operators for adjusting context values directly to avoid adding operators for adjusting single values which also need duplicate notifiers. wm.context_set(path="scene.tool_settings.someattr", somevalue) wm.context_toggle(path="scene.tool_settings.somebool") wm.context_toggle_values(path="scene.tool_settings.some_enum", value_1="somevalue", value_2="othervalue") # switch between 2 values wm.context_cycle_enum(path="scene.tool_settings.some_enum", reverse=False) the path value is taken from the context so the full path is context.scene.tool_settings... This means in keymaps you can cycle draw modes, change PET- anything with rna access. If its not so nice to map keys to operators like wm.context_set we could use macro's to wrap it and have its own name Use this for PET and setting pivot options - Made userpref key shortcut Ctrl+Alt+U since its not used in 2.4x - added pivot_point_align (Alt+Comma) - added PET wasnt rna wrapped correctly. Modified Paths: -------------- trunk/blender/release/scripts/modules/bpy_ops.py trunk/blender/source/blender/editors/curve/curve_ops.c trunk/blender/source/blender/editors/include/ED_object.h trunk/blender/source/blender/editors/mesh/mesh_ops.c trunk/blender/source/blender/editors/object/object_ops.c trunk/blender/source/blender/editors/physics/particle_edit.c trunk/blender/source/blender/editors/screen/screen_ops.c trunk/blender/source/blender/editors/space_view3d/view3d_ops.c trunk/blender/source/blender/editors/transform/transform_generics.c trunk/blender/source/blender/editors/uvedit/uvedit_ops.c trunk/blender/source/blender/makesdna/DNA_scene_types.h trunk/blender/source/blender/makesrna/intern/rna_scene.c trunk/blender/source/blender/makesrna/intern/rna_space.c Modified: trunk/blender/release/scripts/modules/bpy_ops.py =================================================================== --- trunk/blender/release/scripts/modules/bpy_ops.py 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/release/scripts/modules/bpy_ops.py 2009-10-13 15:30:19 UTC (rev 23809) @@ -145,7 +145,7 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator): '''Export a single object as a stanford PLY with normals, colours and texture coordinates.''' __idname__ = "mesh.delete_edgeloop" - __label__ = "Export PLY" + __label__ = "Delete Edge Loop" def execute(self, context): bpy.ops.tfm.edge_slide(value=1.0) @@ -153,6 +153,100 @@ bpy.ops.mesh.remove_doubles() return ('FINISHED',) +class WM_OT_context_set(bpy.types.Operator): + '''Set a context value.''' + __idname__ = "wm.context_set" + __label__ = "Context Set" + __register__ = True + __undo__ = True + + __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= "") + ] + + 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" + __register__ = True + __undo__ = True + + __props__ = [ + bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= ""), + ] + + 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): + '''Toggle a context value.''' + __idname__ = "wm.context_toggle_values" + __label__ = "Context Toggle Values" + __register__ = True + __undo__ = True + + __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= "") + ] + + 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. + return ('FINISHED',) + +class WM_OT_context_cycle_enum(bpy.types.Operator): + '''Toggle a context value.''' + __idname__ = "wm.context_cycle_enum" + __label__ = "Context Toggle Values" + __register__ = True + __undo__ = True + + __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) + ] + + def execute(self, context): + orig_value = eval("context.%s" % self.path) # security nuts will complain. + + # Have to get rna enum values + rna_struct_str, rna_prop_str = self.path.rsplit('.', 1) + i = rna_prop_str.find('[') + if i != -1: rna_prop_str = rna_prop_str[0:i] # just incse we get "context.foo.bar[0]" + + rna_struct = eval("context.%s.rna_type" % rna_struct_str) + + rna_prop = rna_struct.properties[rna_prop_str] + + if type(rna_prop) != bpy.types.EnumProperty: + raise Exception("expected an enum property") + + enums = rna_struct.properties[rna_prop_str].items.keys() + orig_index = enums.index(orig_value) + + # Have the info we need, advance to the next item + if self.reverse: + if orig_index==0: advance_enum = enums[-1] + else: advance_enum = enums[orig_index-1] + else: + if orig_index==len(enums)-1: advance_enum = enums[0] + else: advance_enum = enums[orig_index+1] + + # set the new value + exec("context.%s=advance_enum" % self.path) + return ('FINISHED',) + bpy.ops.add(MESH_OT_delete_edgeloop) +bpy.ops.add(WM_OT_context_set) +bpy.ops.add(WM_OT_context_toggle) +bpy.ops.add(WM_OT_context_toggle_values) +bpy.ops.add(WM_OT_context_cycle_enum) + Modified: trunk/blender/source/blender/editors/curve/curve_ops.c =================================================================== --- trunk/blender/source/blender/editors/curve/curve_ops.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/curve/curve_ops.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -248,5 +248,7 @@ RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_hide", HKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "unselected", 1); WM_keymap_add_item(keymap, "CURVE_OT_specials_menu", WKEY, KM_PRESS, 0, 0); + + ED_object_generic_keymap(keyconf, keymap, TRUE); } Modified: trunk/blender/source/blender/editors/include/ED_object.h =================================================================== --- trunk/blender/source/blender/editors/include/ED_object.h 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/include/ED_object.h 2009-10-13 15:30:19 UTC (rev 23809) @@ -47,6 +47,9 @@ void ED_operatormacros_object(void); void ED_keymap_object(struct wmKeyConfig *keyconf); +/* generic editmode keys like pet */ +void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int do_pet); + /* send your own notifier for select! */ void ED_base_object_select(struct Base *base, short mode); /* includes notifier */ Modified: trunk/blender/source/blender/editors/mesh/mesh_ops.c =================================================================== --- trunk/blender/source/blender/editors/mesh/mesh_ops.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/mesh/mesh_ops.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -291,5 +291,7 @@ /* UV's */ WM_keymap_add_item(keymap, "UV_OT_mapping_menu", UKEY, KM_PRESS, 0, 0); + + ED_object_generic_keymap(keyconf, keymap, TRUE); } Modified: trunk/blender/source/blender/editors/object/object_ops.c =================================================================== --- trunk/blender/source/blender/editors/object/object_ops.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/object/object_ops.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -273,3 +273,26 @@ WM_keymap_add_item(keymap, "LATTICE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); } +void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int do_pet) +{ + wmKeyMapItem *km; + + /* used by mesh, curve & lattice only */ + if(do_pet) { + /* context ops */ + 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); + 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'"); + + km = WM_keymap_add_item(keymap, "WM_OT_context_toggle_values", 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'"); + } + +} + Modified: trunk/blender/source/blender/editors/physics/particle_edit.c =================================================================== --- trunk/blender/source/blender/editors/physics/particle_edit.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/physics/particle_edit.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -2908,7 +2908,7 @@ ParticleSimulationData sim = {scene, ob, psys, psmd}; ParticleEditSettings *pset= PE_settings(scene); int i, k, n= 0, totpart= psys->totpart; - short mco[2]; + float mco[2]; short dmx= 0, dmy= 0; float co1[3], co2[3], min_d, imat[4][4]; float framestep, timestep= psys_get_timestep(&sim); Modified: trunk/blender/source/blender/editors/screen/screen_ops.c =================================================================== --- trunk/blender/source/blender/editors/screen/screen_ops.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/screen/screen_ops.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -3410,10 +3410,7 @@ WM_keymap_add_item(keymap, "SCREEN_OT_render_view_show", F11KEY, KM_PRESS, 0, 0); /* user prefs */ - #ifdef __APPLE__ - WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_OSKEY, 0); - #endif - WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", COMMAKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "SCREEN_OT_userpref_show", UKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); /* Anim Playback ------------------------------------------------ */ Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ops.c =================================================================== --- trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2009-10-13 12:09:11 UTC (rev 23808) +++ trunk/blender/source/blender/editors/space_view3d/view3d_ops.c 2009-10-13 15:30:19 UTC (rev 23809) @@ -221,6 +221,31 @@ 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); + RNA_string_set(km->ptr, "path", "space_data.pivot_point"); + 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 */ + RNA_string_set(km->ptr, "path", "space_data.pivot_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); + RNA_string_set(km->ptr, "path", "space_data.pivot_point"); + RNA_string_set(km->ptr, "value", "'CURSOR'"); + + km = WM_keymap_add_item(keymap, "WM_OT_context_set", PERIODKEY, KM_PRESS, KM_CTRL, 0); + RNA_string_set(km->ptr, "path", "space_data.pivot_point"); @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs