Revision: 25455 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25455 Author: theeth Date: 2009-12-17 23:14:43 +0100 (Thu, 17 Dec 2009)
Log Message: ----------- Keymap conflict detection operator. Takes into account the hierarchical structures of keymaps as well as wildcards (KM_ANY) in event definitions, user remaps (emulate numpad, action/select mouse buttons, ...) and event values that overlap (click, press and release) For now, doesn't do anything other than print conflicts in the console. As a result, I cleaned up a lot of keymaps that had double definitions, moved some keymap items in more appropriate places, fixed wrong definitions and removed kmi that were added for testing a long long time ago. Out of all the remaining conflicts, after removing obvious non-issues, here's what remains: http://www.pasteall.org/9898 Modified Paths: -------------- trunk/blender/release/scripts/ui/space_userpref.py trunk/blender/source/blender/editors/curve/curve_ops.c trunk/blender/source/blender/editors/mesh/mesh_ops.c trunk/blender/source/blender/editors/object/object_ops.c trunk/blender/source/blender/editors/space_file/space_file.c trunk/blender/source/blender/editors/space_image/space_image.c trunk/blender/source/blender/editors/space_text/space_text.c trunk/blender/source/blender/editors/space_view3d/view3d_ops.c trunk/blender/source/blender/editors/transform/transform_ops.c trunk/blender/source/blender/makesrna/intern/rna_internal.h trunk/blender/source/blender/makesrna/intern/rna_wm.c trunk/blender/source/blender/makesrna/intern/rna_wm_api.c trunk/blender/source/blender/windowmanager/WM_api.h trunk/blender/source/blender/windowmanager/intern/wm_event_system.c trunk/blender/source/blender/windowmanager/intern/wm_keymap.c Modified: trunk/blender/release/scripts/ui/space_userpref.py =================================================================== --- trunk/blender/release/scripts/ui/space_userpref.py 2009-12-17 21:53:33 UTC (rev 25454) +++ trunk/blender/release/scripts/ui/space_userpref.py 2009-12-17 22:14:43 UTC (rev 25455) @@ -1467,9 +1467,10 @@ row.separator() def draw_filtered(self, kc, layout): + filter = kc.filter.lower() for km in kc.keymaps: - filtered_items = [kmi for kmi in km.items if kmi.name.lower().find(kc.filter.lower()) != -1] + filtered_items = [kmi for kmi in km.items if filter in kmi.name.lower()] if len(filtered_items) != 0: km = km.active() @@ -1539,7 +1540,133 @@ from bpy.props import * +class WM_OT_keyconfig_test(bpy.types.Operator): + "Test keyconfig for conflicts." + bl_idname = "wm.keyconfig_test" + bl_label = "Test Key Configuration for Conflicts" + + def testEntry(self, kc, entry, src = None, parent = None): + result = False + def kmistr(kmi): + if km.modal: + s = ["kmi = km.add_modal_item(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)] + else: + s = ["kmi = km.add_item(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)] + if kmi.any: + s.append(", any=True") + else: + if kmi.shift: + s.append(", shift=True") + if kmi.ctrl: + s.append(", ctrl=True") + if kmi.alt: + s.append(", alt=True") + if kmi.oskey: + s.append(", oskey=True") + if kmi.key_modifier and kmi.key_modifier != 'NONE': + s.append(", key_modifier=\'%s\'" % kmi.key_modifier) + + s.append(")\n") + + props = kmi.properties + + if props is not None: + for pname in dir(props): + if props.is_property_set(pname) and not props.is_property_hidden(pname): + value = eval("props.%s" % pname) + value = _string_value(value) + if value != "": + s.append("kmi.properties.%s = %s\n" % (pname, value)) + + return "".join(s).strip() + + idname, spaceid, regionid, children = entry + + km = kc.find_keymap(idname, space_type = spaceid, region_type = regionid) + + if km: + km = km.active() + + if src: + for item in km.items: + if src.compare(item): + print("===========") + print(parent.name) + print(kmistr(src)) + print(km.name) + print(kmistr(item)) + result = True + + for child in children: + if self.testEntry(kc, child, src, parent): + result = True + else: + for i in range(len(km.items)): + src = km.items[i] + + for child in children: + if self.testEntry(kc, child, src, km): + result = True + + for j in range(len(km.items) - i - 1): + item = km.items[j + i + 1] + if src.compare(item): + print("===========") + print(km.name) + print(kmistr(src)) + print(kmistr(item)) + result = True + + for child in children: + if self.testEntry(kc, child): + result = True + + return result + + def testConfig(self, kc): + result = False + for entry in KM_HIERARCHY: + if self.testEntry(kc, entry): + result = True + return result + + def execute(self, context): + wm = context.manager + kc = wm.default_keyconfig + + if self.testConfig(kc): + print("CONFLICT") + + return ('FINISHED',) + +def _string_value(value): + result = "" + if isinstance(value, str): + if value != "": + result = "\'%s\'" % value + elif isinstance(value, bool): + if value: + result = "True" + else: + result = "False" + elif isinstance(value, float): + result = "%.10f" % value + elif isinstance(value, int): + result = "%d" % value + elif getattr(value, '__len__', False): + if len(value): + result = "[" + for i in range(0, len(value)): + result += _string_value(value[i]) + if i != len(value)-1: + result += ", " + result += "]" + else: + print("Export key configuration: can't write ", value) + + return result + class WM_OT_keyconfig_export(bpy.types.Operator): "Export key configuration to a python script." bl_idname = "wm.keyconfig_export" @@ -1547,33 +1674,6 @@ path = bpy.props.StringProperty(name="File Path", description="File path to write file to.") - def _string_value(self, value): - result = "" - if isinstance(value, str): - if value != "": - result = "\'%s\'" % value - elif isinstance(value, bool): - if value: - result = "True" - else: - result = "False" - elif isinstance(value, float): - result = "%.10f" % value - elif isinstance(value, int): - result = "%d" % value - elif getattr(value, '__len__', False): - if len(value): - result = "[" - for i in range(0, len(value)): - result += self._string_value(value[i]) - if i != len(value)-1: - result += ", " - result += "]" - else: - print("Export key configuration: can't write ", value) - - return result - def execute(self, context): if not self.properties.path: raise Exception("File path not set.") @@ -1620,7 +1720,7 @@ for pname in dir(props): if props.is_property_set(pname) and not props.is_property_hidden(pname): value = eval("props.%s" % pname) - value = self._string_value(value) + value = _string_value(value) if value != "": f.write("kmi.properties.%s = %s\n" % (pname, value)) @@ -1714,6 +1814,7 @@ return ('FINISHED',) bpy.ops.add(WM_OT_keyconfig_export) +bpy.ops.add(WM_OT_keyconfig_test) bpy.ops.add(WM_OT_keymap_edit) bpy.ops.add(WM_OT_keymap_restore) bpy.ops.add(WM_OT_keyitem_add) Modified: trunk/blender/source/blender/editors/curve/curve_ops.c =================================================================== --- trunk/blender/source/blender/editors/curve/curve_ops.c 2009-12-17 21:53:33 UTC (rev 25454) +++ trunk/blender/source/blender/editors/curve/curve_ops.c 2009-12-17 22:14:43 UTC (rev 25455) @@ -238,7 +238,7 @@ WM_keymap_add_item(keymap, "CURVE_OT_delete", DELKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "CURVE_OT_tilt_clear", TKEY, KM_PRESS, KM_ALT, 0); - RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", TFM_TILT); + WM_keymap_add_item(keymap, "TRANSFORM_OT_tilt", TKEY, KM_PRESS, KM_CTRL, 0); RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, "mode", TFM_CURVE_SHRINKFATTEN); RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1); RNA_enum_set(WM_keymap_add_item(keymap, "CURVE_OT_handle_type_set", HKEY, KM_PRESS, 0, 0)->ptr, "type", 3); Modified: trunk/blender/source/blender/editors/mesh/mesh_ops.c =================================================================== --- trunk/blender/source/blender/editors/mesh/mesh_ops.c 2009-12-17 21:53:33 UTC (rev 25454) +++ trunk/blender/source/blender/editors/mesh/mesh_ops.c 2009-12-17 22:14:43 UTC (rev 25455) @@ -255,7 +255,6 @@ WM_keymap_add_item(keymap, "MESH_OT_extrude_move", EKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_spin", RKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_screw", NINEKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "MESH_OT_beauty_fill", FKEY, KM_PRESS, KM_ALT, 0); @@ -263,20 +262,11 @@ WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "MESH_OT_edge_flip", FKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_extrude_repeat", FOURKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_edge_rotate", FIVEKEY, KM_PRESS, KM_CTRL, 0); - - WM_keymap_add_item(keymap, "MESH_OT_loop_to_region",SIXKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_region_to_loop",SIXKEY, KM_PRESS, KM_ALT, 0); - - WM_keymap_add_item(keymap, "MESH_OT_uvs_rotate",SEVENKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_uvs_mirror",SEVENKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_colors_rotate",EIGHTKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "MESH_OT_colors_mirror",EIGHTKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "MESH_OT_rip_move",VKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_merge", MKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "TRANSFORM_OT_shrink_fatten", SKEY, KM_PRESS, KM_ALT, 0); + /* add/remove */ WM_keymap_add_item(keymap, "MESH_OT_edge_face_add", FKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MESH_OT_skin", FKEY, KM_PRESS, KM_CTRL|KM_ALT, 0); /* python */ Modified: trunk/blender/source/blender/editors/object/object_ops.c =================================================================== @@ 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