I'm working on a Panel where a user shall be able to choose between different options using a dropdown box. What I'd like to do for convenience reasons is to define an EnumProperty directly in the Panel class. Here is an example, I modified the UI Panel Simple template that ships with Blender slightly and added Addon definition:
import bpy
bl_info = {
"name": "Hello World Panel with Enum Prop",
"author": "Rainer Trummer",
"version": (0, 1, 0),
"blender": (2, 76, 0),
"description": "Enum Property is registered, but cannot be accessed",
"category": "Interface"
}
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "VIEW3D_PT_hello"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_context = "object"
# EnumProperty definition
test = bpy.props.EnumProperty(items =
[
('ONE', 'one', 'first one'),
('TWO', 'two', 'second one')
]
)
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text = "Hello world!", icon = 'WORLD_DATA')
# the following line fails when hovering over the panel
# with the mouse cursor
row.prop(self, 'test')
def register():
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
You can run this code from the text editor. There are no errors thrown at first, but the Property never appears in the UI. When you hover over the Panel in the 3D View, the console prints the following error:
However, I can happily access the property from the console:
but only if the panel code is within an addon. Running JUST the panel code without the bl_info block does not register the property.
I know I can put the Enum somewhere else, like into bpy.types.scene, but I don't understand why this approach here would not work. It DOES work with operators, doesn't it? Why not with Panels?