5
$\begingroup$

I want to write an addon, which enables you to switch quickly, via a pie menu, between the editor types. (e.g. Node Editor, 3D View, Graph Editor, etc...) To get my shortcut working, I need to register the same keymap for every space or editor type.

(e.g.:keymap_items.new("wm.call_menu_pie", type = "E",alt=True, value = "PRESS"))

Right now I got it working with only one editor type:

keyconfigs.addon.keymaps.new(name = "Node Editor", space_type = "NODE_EDITOR")

I know, I could simply register my keymap for every single editor type with a loop, but I am sure there is a more convenient and beatiful way to accomplish my objective.

( Maybe something like space_type = "WINDOW"?)

PS: My current registration code looks like this:

addon_keymaps = []
def register_keymaps():
    global addon_keymaps
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name = "Node Editor", space_type = "NODE_EDITOR")
    kmi = km.keymap_items.new("wm.call_menu_pie", type = "E",alt=True, value = "PRESS")
    kmi.properties.name = "view3d.switcher"
    addon_keymaps.append(km)
$\endgroup$
6
$\begingroup$

I randomly discovered the answer to my question on the Blender Python API Documentation

My registration code now looks like this:

addon_keymaps = []
def register_keymaps():
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name = "Window",space_type='EMPTY', region_type='WINDOW')
    kmi = km.keymap_items.new("wm.call_menu_pie", type = "E",alt=True, value = "PRESS")
    kmi.properties.name = "editor_switcher_pie_menu"
    addon_keymaps.append(km)

You can find the final version of my addon on GitHub

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.