diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-10-26 12:01:03 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-10-26 12:01:03 +0300 |
commit | e5c13aebea6bb884ad4d54b338152c1867026fa0 (patch) | |
tree | f425bf64043244299190f750f039ecae6d39b8e4 /doc/python_api | |
parent | c8d10d115cc54417f364aa515ba020a9c7b9bd5d (diff) |
Fix T42372: demo addon in doc was not handling keymaps correctly during (un)registration.
First, you should unregister in reverse order you registered your operators, keymaps, etc.
Second, when registering keymaps you have to check keyconfigs are actually available (they are not in background mode).
Diffstat (limited to 'doc/python_api')
-rw-r--r-- | doc/python_api/rst/info_tutorial_addon.rst | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/doc/python_api/rst/info_tutorial_addon.rst b/doc/python_api/rst/info_tutorial_addon.rst index 5637cf2f638..436f74bc441 100644 --- a/doc/python_api/rst/info_tutorial_addon.rst +++ b/doc/python_api/rst/info_tutorial_addon.rst @@ -563,20 +563,26 @@ Bringing it all together # handle the keymap wm = bpy.context.window_manager - km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY') - kmi = km.keymap_items.new(ObjectCursorArray.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True) - kmi.properties.total = 4 - addon_keymaps.append((km, kmi)) + # Note that in background mode (no GUI available), keyconfigs are not available either, so we have to check this + # to avoid nasty errors in background case. + kc = wm.keyconfigs.addon + if kc: + km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY') + kmi = km.keymap_items.new(ObjectCursorArray.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True) + kmi.properties.total = 4 + addon_keymaps.append((km, kmi)) def unregister(): - bpy.utils.unregister_class(ObjectCursorArray) - bpy.types.VIEW3D_MT_object.remove(menu_func) - + # Note: when unregistering, it's usually good practice to do it in reverse order you registered. + # Can avoid strange issues like keymap still referring to operators already unregistered... # handle the keymap for km, kmi in addon_keymaps: km.keymap_items.remove(kmi) addon_keymaps.clear() + bpy.utils.unregister_class(ObjectCursorArray) + bpy.types.VIEW3D_MT_object.remove(menu_func) + if __name__ == "__main__": register() |