I’m trying to set a keymap for my operator in the Image Editor but can’t get it to work.
bl_info = {
"name": "Custom Operator",
"category": "Image",
}
import bpy
class CustomOperator(bpy.types.Operator):
"""Object Cursor Array"""
bl_idname = "image_editor.custom_operator"
bl_label = "Custom Operator"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print("EXECUTED")
return {'FINISHED'}
# store keymaps here to access after registration
addon_keymaps = []
def register():
bpy.utils.register_class(CustomOperator)
# handle the keymap
wm = bpy.context.window_manager
# 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='View', space_type='IMAGE_EDITOR')
kmi = km.keymap_items.new(CustomOperator.bl_idname, 'SPACE', 'PRESS', ctrl=True, shift=True)
addon_keymaps.append((km, kmi))
def unregister():
# 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()
If I use it in the Image Editor pressing space and typing “Custom Operator” it work but the keymap Ctrl + Shift + Space don’t work.
For some reason Ctrl + Shift + Space works I’m in the 3D view even though the space_type is ‘IMAGE_EDITOR’…
I’m not undestanting how this keymap configuration works.