I created a drop-down menu, with a operator_menu_enum
referring to an EnumProperty
.
When I select an entry in this menu, it closes, and display the default text
string, instead of displaying the selected entry's string.
How to keep the selected entry displayed in the menu's head after selection ?
Edit : Here is an example script of the way I make the menu :
import bpy
class STUFF_PANEL(bpy.types.Panel):
bl_idname = "SCENE_PT_stuffSelect"
bl_label = "Stuff selection"
bl_space_type = "PROPERTIES"
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator_menu_enum("stuff_list.menu", 'stuffList', text="Stuff list")
if bpy.props.selectedStuff:
row = layout.row()
row.label("Selected stuff :")
row.label(str(bpy.props.selectedStuff[1]))
class STUFF_LIST_OT_Menu(bpy.types.Operator):
bl_idname = "stuff_list.menu"
bl_description = "select something here"
bl_label = "Menu"
def get_stuff(self, context):
return bpy.props.config_stuff_list
stuffList = bpy.props.EnumProperty(
items = get_stuff, name = "Stuff", description = "The stuff list")
def execute(self, context):
bpy.props.selectedStuff = [
n for i, n in enumerate(bpy.props.config_stuff_list)\
if n[0] == self.stuffList][0]
return{'FINISHED'}
def register():
bpy.props.selectedStuff = False
bpy.props.config_stuff_list = [
("1","stuff 1","0"),("2","stuff 2","0"),("3","stuff 3","0")]
bpy.utils.register_module(__name__)
def unregister():
del bpy.props.config_stuff_list
del bpy.props.selectedStuff
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
NameError: name 'bpy' is not defined
, please test the example and make sure it works. $\endgroup$