added item_enumO() so python menu items can call enum types with string args.

Example sequencer menu
		self.layout.column()
		self.layout.item_enumO("SEQUENCER_OT_effect_strip_add", property='type', value='ADD', text="Effect Strip (Add)")
This commit is contained in:
Campbell Barton 2009-06-07 14:53:08 +00:00
parent eecf7722b6
commit bb06e311a1
4 changed files with 37 additions and 5 deletions

@ -611,6 +611,7 @@ void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int ty
/* items */
void uiItemO(uiLayout *layout, char *name, int icon, char *opname);
void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value);
void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value);
void uiItemsEnumO(uiLayout *layout, char *opname, char *propname);
void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value);
void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value);

@ -124,12 +124,12 @@ void RNA_api_ui_layout(StructRNA *srna)
func= RNA_def_function(srna, "itemO", "uiItemO");
api_ui_item_op_common(func);
/*func= RNA_def_function(srna, "item_enumO", "uiItemEnumO");
func= RNA_def_function(srna, "item_enumO", "uiItemEnumO_string");
api_ui_item_op_common(func);
parm= RNA_def_string(func, "property", "", 0, "", "Identifier of property in operator.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_string(func, "value", "", 0, "", "Enum property value.");
RNA_def_property_flag(parm, PROP_REQUIRED);*/
RNA_def_property_flag(parm, PROP_REQUIRED);
func= RNA_def_function(srna, "items_enumO", "uiItemsEnumO");
parm= RNA_def_string(func, "operator", "", 0, "", "Identifier of the operator.");

@ -597,6 +597,39 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname)
}
}
/* for use in cases where we have */
void uiItemEnumO_string(uiLayout *layout, char *name, int icon, char *opname, char *propname, char *value_str)
{
PointerRNA ptr;
/* for getting the enum */
PropertyRNA *prop;
const EnumPropertyItem *item;
int totitem;
int value;
WM_operator_properties_create(&ptr, opname);
/*RNA_enum_set(&ptr, propname, value);*/
if(prop= RNA_struct_find_property(&ptr, propname)) {
RNA_property_enum_items(&ptr, prop, &item, &totitem);
if(RNA_enum_value_from_id(item, value_str, &value)==0) {
printf("uiItemEnumO_string: %s.%s, enum %s not found.\n", RNA_struct_identifier(ptr.type), propname, value);
return;
}
}
else {
printf("uiItemEnumO_string: %s.%s not found.\n", RNA_struct_identifier(ptr.type), propname);
return;
}
/* same as uiItemEnumO */
if(!name)
name= ui_menu_enumpropname(opname, propname, value);
uiItemFullO(layout, name, icon, opname, ptr.data, layout->root->opcontext);
}
void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char *propname, int value)
{
PointerRNA ptr;

@ -2059,9 +2059,7 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *args)
item= PyObject_GetAttrString(py_class, "__rna__");
if(!item || !BPy_StructRNA_Check(item)) {
if(item) {
Py_DECREF(item);
}
Py_XDECREF(item);
PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no __rna__ property).");
return NULL;
}