0
$\begingroup$

I'am trying to write a small add-on, with the Select Modes for 3D View and UV Editor.

Could do most of the job, but now I'm trying to list the add-on keymap under the add-on tab itself. I've tried a couple of things but didn't work, the keymap window is appearing but I couldn't find a way to list the keymaps there.

import bpy
import rna_keymap_ui 
from bpy.types import Menu

bl_info = {
    "name": "Select Mode Pie",
    "description": "Pie Menu for Select Mode in Edit mode and UV Editor.",
    "author": "Lucas Falcao",
    "version": (0, 7),
    "blender": (3, 4, 0), 
    "doc_url": "https://github.com/lucasfalcao3d/Select-Mode-Pie",
    "category": "3D View",
}

addon_keymaps = []

class VIEW3D_PIE_select_mode(bpy.types.Menu):
    bl_label = "Select Mode"
    bl_idname = "pie.edit_select_mode"

    def draw(self, context):
        layout = self.layout

        pie = layout.menu_pie()

        pie.operator("mesh.select_mode", text="Vertex", icon="VERTEXSEL").type = 'VERT'
        pie.operator("mesh.select_mode", text="Edge", icon="EDGESEL").type = 'EDGE'
        pie.operator("mesh.select_mode", text="Face", icon="FACESEL").type = 'FACE'
        pie.operator("mesh.select_linked", text="Linked", icon="UV_ISLANDSEL").type = 'VERT'

class MESH_OT_select_connected_vertices(bpy.types.Operator):
    bl_idname = "mesh.select_connected_vertices"
    bl_label = "Select Connected Vertices"

    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'

    def execute(self, context):
        bpy.ops.mesh.select_mode(type='VERT')
        bpy.ops.mesh.select_linked()
        bpy.ops.mesh.select_mode(type='EDGE')
        bpy.ops.mesh.select_mode(type='FACE')
        bpy.ops.mesh.select_mode(type='VERT')
        return {'FINISHED'}
        
# Spawn a pie menu for select mode in UV Editor 

class UV_PIE_select_mode(Menu):
    bl_label = "UV Select Mode"
    bl_idname = "pie.uv_select_mode"

    def draw(self, context):
        layout = self.layout
        
        
        tool_settings = context.tool_settings
        pie = layout.menu_pie()
        
        # Do smart things depending on whether uv_select_sync is on.

        if tool_settings.use_uv_select_sync:
            op = pie.operator("wm.context_set_value", text="Vertex", icon='VERTEXSEL')
            op.value = "(True, False, False)"
            op.data_path = "tool_settings.mesh_select_mode"

            op = pie.operator("wm.context_set_value", text="Edge", icon='EDGESEL')
            op.value = "(False, True, False)"
            op.data_path = "tool_settings.mesh_select_mode"

            op = pie.operator("wm.context_set_value", text="Face", icon='FACESEL')
            op.value = "(False, False, True)"
            op.data_path = "tool_settings.mesh_select_mode"            
            
        else:
            op = pie.operator("wm.context_set_string", text="Vertex", icon='UV_VERTEXSEL')
            op.value = 'VERTEX'
            op.data_path = "tool_settings.uv_select_mode"
 
            op = pie.operator("wm.context_set_string", text="Edge", icon='UV_EDGESEL')
            op.value = 'EDGE'
            op.data_path = "tool_settings.uv_select_mode"

            op = pie.operator("wm.context_set_string", text="Face", icon='UV_FACESEL')
            op.value = 'FACE'
            op.data_path = "tool_settings.uv_select_mode"

            op = pie.operator("wm.context_set_string", text="Island", icon='UV_ISLANDSEL')
            op.value = 'ISLAND'
            op.data_path = "tool_settings.uv_select_mode"
            
class MyAddonPreferences(bpy.types.AddonPreferences):
    bl_idname = __name__

    def draw(self, context):
        layout = self.layout

        box = layout.box()
        col = box.column()
        col.label(text="Keymap List:", icon="KEYINGSET")

        wm = bpy.context.window_manager
        kc = wm.keyconfigs.user
        old_km_name = ""
        get_kmi_l = []
        for km_add, kmi_add in addon_keymaps:
            for km_con in kc.keymaps:
                if km_add.name == km_con.name:
                    km = km_con
                    break

            for kmi_con in km.keymap_items:
                if kmi_add.idname == kmi_con.idname:
                    if kmi_add.name == kmi_con.name:
                        get_kmi_l.append((km, kmi_con))

        get_kmi_l = sorted(set(get_kmi_l), key=get_kmi_l.index)

        for km, kmi in get_kmi_l:
            if not km.name == old_km_name:
                col.label(text=str(km.name), icon="DOT")
            col.context_pointer_set("keymap", km)
            rna_keymap_ui.draw_kmi([], kc, km, kmi, col, 0)
            col.separator()
            old_km_name = km.name
            
        
def register():
    bpy.utils.register_class(VIEW3D_PIE_select_mode)
    bpy.utils.register_class(MESH_OT_select_connected_vertices)
    bpy.utils.register_class(UV_PIE_select_mode)
    bpy.utils.register_class(MyAddonPreferences)

    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name="Mesh")
    kmi = km.keymap_items.new("wm.call_menu_pie", "SPACE", "PRESS").properties.name="pie.edit_select_mode"     
        
    wm = bpy.context.window_manager
    km = wm.keyconfigs.addon.keymaps.new(name="UV Editor")
    kmi = km.keymap_items.new("wm.call_menu_pie", "SPACE", "PRESS").properties.name="pie.uv_select_mode"

def unregister():
    bpy.utils.unregister_class(VIEW3D_PIE_select_mode)
    bpy.utils.unregister_class(MESH_OT_select_connected_vertices)
    bpy.utils.register_class(UV_PIE_select_mode)
    bpy.utils.register_class(MyAddonPreferences)

    km = bpy.context.window_manager.keyconfigs.addon.keymaps.get('Mesh')
    if km:
        km.keymap_items.remove(km.keymap_items.get('wm.call_menu_pie'))

if __name__ == "__main__":
    register()
$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .