I had a random idea for an addon today and it revolves around being able to store custom properties on individual keymap items- but a PointerProperty to a PropertyGroup doesn’t seem to work with keymap items. Anyone have any experience with this and know a way around it (or, to satisfy my own curiosity- what makes a PointerProperty work with any other type of object I put one on).
As an example- this script works (taken from the 2.80 docs for PropertyGroup):
import bpy
class MaterialSettings(bpy.types.PropertyGroup):
my_int: bpy.props.IntProperty()
my_float: bpy.props.FloatProperty()
my_string: bpy.props.StringProperty()
bpy.utils.register_class(MaterialSettings)
bpy.types.Material.my_settings = bpy.props.PointerProperty(type=MaterialSettings)
# test the new settings work
material = bpy.data.materials[0]
material.my_settings.my_int = 5
material.my_settings.my_float = 3.0
material.my_settings.my_string = "Foo"
but this script throws an exception saying ‘tuple’ has no attribute ‘my_int’:
import bpy
class KeymapItemSettings(bpy.types.PropertyGroup):
my_int: bpy.props.IntProperty()
my_float: bpy.props.FloatProperty()
my_string: bpy.props.StringProperty()
bpy.utils.register_class(KeymapItemSettings)
bpy.types.KeyMapItem.my_settings = bpy.props.PointerProperty(type=KeymapItemSettings)
# test the new settings work
kmi = bpy.context.window_manager.keyconfigs.addon.keymaps[0].keymap_items[0]
kmi.my_settings.my_int = 5
kmi.my_settings.my_float = 3.0
kmi.my_settings.my_string = "Foo"