How to Initialize keymaps for this gizmo group?

For gizmo function is a classmethod setup_keymap(keyconfig). How to properly initialize for gizmo in this function Keymaps?

#this is my Gizmo class
class GIZMO_GGT_object(GizmoGroup):
    bl_idname = "gizmo.pivot"
    bl_label = "Gizmo for pivot"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'WINDOW'
    bl_options = {'3D', 'PERSISTENT'} #'TOOL_INIT' , 'SHOW_MODAL_ALL', 'SELECT'

    @classmethod
    def setup_keymap(keyconfig):
        #?
    @classmethod
    def poll(cls, context):
    def setup(self, context):
    def draw_prepare(self, context):

I did one like this:

# Registration
addon_keymaps = []

def register():
    bpy.utils.register_class(precision_draw_tools_bm)
    bpy.utils.register_class(precision_draw_tools_cm)
    #bpy.types.VIEW3D_MT_edit_mesh_vertices.append(draw_menu)
    # 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='Window', space_type='EMPTY')
        kmi = km.keymap_items.new(precision_draw_tools_cm.bl_idname, type = 'P', value = 'PRESS', ctrl=False, shift=True)
        addon_keymaps.append((km, kmi))
        km = wm.keyconfigs.addon.keymaps.new(name='Window', space_type='EMPTY')
        kmi = km.keymap_items.new(precision_draw_tools_bm.bl_idname, type = 'P', value = 'PRESS', ctrl=True, shift=True)
        addon_keymaps.append((km, kmi))

And the unregister like this:

def unregister():
    # handle the keymap
    for km, kmi in addon_keymaps:
        km.keymap_items.remove(kmi)
    addon_keymaps.clear()
    bpy.utils.unregister_class(precision_draw_tools_cm)
    bpy.utils.unregister_class(precision_draw_tools_bm)

Is this any help to you?

I for Addons initialize keymap, but i need inicializade keymap for custom gizmo, and I thought that this can be done through this function. I think I found in API that can help me specifically with this gizmo tweak https://docs.blender.org/api/blender2.8/bpy.ops.gizmogroup.html?highlight=gizmogroup#module-bpy.ops.gizmogroup . You as a more experienced programmer, how would you use this for gizmo? I unfortunately not found where would similar used.
EDIT
https://github.com/julianeisel/blender/blob/e2b0647272c7fcb94bdf3bddd6bc086b7130d757/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py#L108
I also found this. I try to activate gizmo only by dragging, but I want to be able to select the vertex behind the gizmo. I have already asked a question on this subject. I think I’m around)))

Unfortunately my knowledge of Gizmos is very limited, perhaps someone else has better ideas than me. Sorry, I am doing all I can here…

Cheers, Clock.

1 Like