Hello,
I’m trying to write a template for specific keymaps to let the user change the shortcuts similarly to Blender’s way, but in the addon’s preferences UI.
Here I list the specific keymaps by their idnames. When the shortcut is not changed, there is a box that appears (placeholder to prevent them from deleting the keymap from the addon’s preferences. But if they change it, it becomes a Restore button. And my problem is that this line row.operator("preferences.keyitem_restore", text="", icon = "BACK").item_id = kmi.id is grayed out, and I don’t understand what’s missing?
class Addon_Keymaps_Items(Operator):
bl_idname = "addon_keymaps_items.keymap_template"
bl_label = "Keymap Item Test"
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
layout = self.layout
layout.ui_units_x = 30.0
layout.label(text = "TEST PANEL", icon = "MENU_PANEL")
wm = context.window_manager
kc = wm.keyconfigs.user
if kc:
for km in kc.keymaps:
for kmi in km.keymap_items:
if (kmi.idname == 'wm.call_menu' and kmi.properties.name == 'TOPBAR_MT_file_new' or
kmi.idname == 'wm.open_mainfile' or
kmi.idname == 'wm.save_mainfile'):
col = layout.column(align=True)
box = col.box()
split = box.split()
row = split.row(align=True)
row.prop(kmi, "show_expanded", text="", emboss=False)
row.prop(kmi, "active", text="", emboss=False)
row.label(text=kmi.name)
row = split.row()
row.prop(kmi, "map_type", text="")
row.prop(kmi, "type", text="", full_event=True)
if (not kmi.is_user_defined) and kmi.is_user_modified:
row.operator("preferences.keyitem_restore", text="", icon = "BACK").item_id = kmi.id
else:
box = row.box()
box.scale_x = 0.75
box.scale_y = 0.55
box.label(text = "", icon = "BLANK1")
