I used UILayout.column_flow(...) and UILayout.operator(...) to arrange buttons horizontally in a panel.
These buttons need to be enabled and disabled independently depending on the context. Currently, buttons with icons are differentiated by displaying CHECKBOX_DEHLT when disabled, and text buttons are on separate lines. But they're not cool. Is there any trick? I would like to avoid creating my own icons or embossing.
I've prepared a template for you to answer.
import bpy
class LayoutDemoPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Layout Demo"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Test"
def draw(self, context):
layout = self.layout
#---------------------------------------
# Here is question
col = layout.column_flow(columns=2)
col.enabled = False
col.operator("view3d.test_operator1", text="Ico Sphere")
col.enabled = True
col.operator("view3d.test_operator2", text="Monkey")
#---------------------------------------
class VIEW3D_OT_test_operator1(bpy.types.Operator):
bl_idname = "view3d.test_operator1"
bl_label = "Operator1"
def execute(self, context):
bpy.ops.mesh.primitive_ico_sphere_add()
return {'FINISHED'}
class VIEW3D_OT_test_operator2(bpy.types.Operator):
bl_idname = "view3d.test_operator2"
bl_label = "Operator2"
def execute(self, context):
bpy.ops.mesh.primitive_monkey_add()
return {'FINISHED'}
classes = (
LayoutDemoPanel,
VIEW3D_OT_test_operator1,
VIEW3D_OT_test_operator2,
)
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()
