# how to make “operator_menu_enum” keep the selected value displayed

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()
if bpy.props.selectedStuff:
row = layout.row()
row.label("Selected stuff :")
row.label(str(bpy.props.selectedStuff[1]))

bl_description = "select something here"

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()

• Could you pose a simple example script? – ideasman42 Sep 25 '13 at 1:53
• Ok, edited my question with an example of how I use the APi to make the menu. – Polosson Sep 25 '13 at 17:04
• NameError: name 'bpy' is not defined, please test the example and make sure it works. – ideasman42 Sep 25 '13 at 17:28
• Checked the example, looks like you may be better off not to use the API like this, can you explain what this is for? – ideasman42 Sep 26 '13 at 1:31
• This is part of a script which allows user to modify a configuration file, within the UI. (using python 'configparser' and so on). More precisely, this part correspond to a section of the config file which contains a list of json values, so the user have to choose a value to be able to modify the json content. – Polosson Sep 26 '13 at 11:19

This feature isn't supported by operator_menu_enum, the purpose of this is to be a submenu containing options. Not a persistent drop-down selection box, you may be better off to add an update callback to an enum property, then selecting an option can run some python code.

What you wan't can be done, but I think you're looking in the wrong place.

You could replace the row.operator_menu_enum line with this.

    if bpy.props.selectedStuff:
label = str(bpy.props.selectedStuff[1])
else:
label = "Stuff list"


it looks like this is not using the API correctly. You can't easily access operator properties from a panel (when the operator isn't running), you're better off to add a property-group to the scene that contains all your tool properties, then have the operators invoke function initialize from these settings (this is how most Blender operators do this).

### Note:

• Setting attributes in bpy.props is bad practice, just store this in the script. (as a class attribute for example)
• Your 'simple answer' works great at the moment, if I have enough time I'll go more in-depth with the other one. Thx! – Polosson Sep 26 '13 at 11:34