5
$\begingroup$

I am unable to find a good reference on where to use these following methods of bpy.types.UILayout even in official bpy documentation.

  1. operator_enum
  2. operator_menu_enum
  3. props_enum
  4. prop_menu_enum
  5. prop_enum
  6. prop_tabs_enum

Can anyone please help in understanding where each of it can be used?

$\endgroup$

1 Answer 1

13
$\begingroup$

prop_*

The prop_* methods are for controlling the value of a property on a data object.

prop_enum

layout.prop_enum(light, "type", 'POINT')
layout.prop_enum(light, "type", 'SUN')

Creates one button. Pressing the button sets the property to the given value (eg. the first button does light.type = 'POINT'). The button lights up to show when the property is equal to the given value.

props_enum

layout.props_enum(light, "type")

Creates a button for each enum value. That is, it loops over all the enum values and does prop_enum for each one.

prop_tabs_enum

layout.prop_tabs_enum(light, "type")

Similar to props_enum, but creates a horizontal row of tabs for each enum value.

prop

layout.prop(light, "type")

The generic property control. For enums, creates a combo box (drop down menu).

prop_menu_enum

layout.prop_menu_enum(light, "type")

Another combo box, but not the same as prop?



operator_*

operator_* methods, on the other hand, are for calling an operator, passing the value of an enum as a parameter.

operator_enum

layout.operator_enum("object.light_add", "type")

Creates a button for each enum value. Clicking a button calls the operator with that parameter (eg. the first button calls bpy.ops.object.light_add(type='POINT')).

operator_menu_enum

layout.operator_menu_enum("object.light_add", "type")

Creates a drop down menu. Clicking an entry in the drop down menu calls the operator with that parameter.

$\endgroup$
2
  • 1
    $\begingroup$ +1 ....this should be part of the documentation! $\endgroup$
    – Chris
    Dec 4, 2022 at 14:12
  • 1
    $\begingroup$ prop_menu_enum seems like it is well suited for flag enums (enums where multiple values are valid) $\endgroup$
    – Gorgious
    Dec 4, 2022 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .