Bone Selection Sets: better keymap handling
Previously the keymap registration would cause an error when there was no Pose keymap yet. Now the code adheres to the example code in [the tutorial](https://docs.blender.org/api/blender_python_api_master/info_tutorial_addon.html#keymap).
This commit is contained in:
parent
fad17c652d
commit
8a62f77e64
|
@ -514,6 +514,10 @@ def uniqify(name: str, other_names: list) -> str:
|
|||
return "{}.{:03d}".format(name, min_index)
|
||||
|
||||
|
||||
# store keymaps here to access after registration
|
||||
addon_keymaps = []
|
||||
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
@ -530,10 +534,11 @@ def register():
|
|||
)
|
||||
|
||||
wm = bpy.context.window_manager
|
||||
km = wm.keyconfigs.active.keymaps['Pose']
|
||||
km = wm.keyconfigs.addon.keymaps.new(name='Pose')
|
||||
|
||||
kmi = km.keymap_items.new('wm.call_menu', 'W', 'PRESS', alt=True, shift=True)
|
||||
kmi.properties.name = 'POSE_MT_selection_sets'
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
bpy.types.VIEW3D_MT_select_pose.append(add_sss_button)
|
||||
|
||||
|
@ -545,6 +550,11 @@ def unregister():
|
|||
del bpy.types.Object.selection_sets
|
||||
del bpy.types.Object.active_selection_set
|
||||
|
||||
# handle the keymap
|
||||
for km, kmi in addon_keymaps:
|
||||
km.keymap_items.remove(kmi)
|
||||
addon_keymaps.clear()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
|
Loading…
Reference in New Issue