I have a problem with my keymaps

You can’t save changes done to keymaps on the addon layer. This is because they are recreated every time blender is restarted.

Blender creates an invisible user layer for every existing keymap item (kmi). When a default kmi (by addon or blender) is modified by a user, it is the kmi on the user layer which is being saved when preferences are saved.

In your preferences, you are listing the addon kmi and try to allow the user make changes on the addon layer. You should instead list the user kmi. When a user disables the kmi from your preferences, it needs to happen on the user layer, which then will be saved.

You also need to use a context pointer which tells blender to propagate the changes made from the ui to the rna.

Here’s for the prefs.py. I’ve made the necessary changes:


    def add_keymap_to_ui(self, context, layout, k_name, idname):
        # keymap_item = context.window_manager.keyconfigs.addon.keymaps[k_name].keymap_items
        keymap_item = context.window_manager.keyconfigs.user.keymaps[k_name].keymap_items
        row = layout.row()
        km = context.window_manager.keyconfigs.user.keymaps[k_name]  # added
        layout.context_pointer_set("keymap", km)  # added
        row.prop(keymap_item[idname], 'active', text="",full_event=True)
        row.prop(keymap_item[idname], 'type', text=keymap_item[idname].name, full_event=True) 

3 Likes