I am trying to duplicate the mesh selection mode buttons in a side panel. everything works except the button behavior is not the same. I would want shift-click to multi-select and click only allows one selection at a time. Is there a better approach? I tried this but couldn't make it work.
sample code below:
import bpy
class VIEW3D_PT_selection_tools(bpy.types.Panel):
bl_label = "Selection Tools"
bl_idname = "VIEW3D_PT_selection_tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "New Tab"
bl_context = "mesh_edit"
def draw(self, context):
layout = self.layout
row = layout.row(align=True)
row.label(text="Selection Mode:")
# Show buttons with only icons and no space between them
row.prop(context.tool_settings, "mesh_select_mode", index=0, text="", icon='VERTEXSEL', toggle=True)
row.prop(context.tool_settings, "mesh_select_mode", index=1, text="", icon='EDGESEL', toggle=True)
row.prop(context.tool_settings, "mesh_select_mode", index=2, text="", icon='FACESEL', toggle=True)
classes = (VIEW3D_PT_selection_tools,)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()
```