rna flag PROP_ENUM_FLAG which makes rna props a tuple of enums when converted into a PyObject
only used by wm.invoke_props_popup() currently
This commit is contained in:
@@ -212,8 +212,12 @@ class WM_OT_properties_edit(bpy.types.Operator):
|
||||
self.properties.description = prop_ui.get("description", "")
|
||||
|
||||
wm = context.manager
|
||||
# This crashes, TODO - fix
|
||||
#return wm.invoke_props_popup(self, event)
|
||||
|
||||
wm.invoke_props_popup(self, event)
|
||||
return ('RUNNING_MODAL',)
|
||||
|
||||
|
||||
|
||||
class WM_OT_properties_add(bpy.types.Operator):
|
||||
|
||||
@@ -61,8 +61,7 @@ class SelectPattern(bpy.types.Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.manager
|
||||
wm.invoke_props_popup(self, event)
|
||||
return ('RUNNING_MODAL',)
|
||||
return wm.invoke_props_popup(self, event)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
@@ -54,6 +54,9 @@ class AddPresetBase(bpy.types.Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.manager
|
||||
#crashes, TODO - fix
|
||||
#return wm.invoke_props_popup(self, event)
|
||||
|
||||
wm.invoke_props_popup(self, event)
|
||||
return ('RUNNING_MODAL',)
|
||||
|
||||
|
||||
@@ -359,8 +359,7 @@ class WM_OT_doc_edit(bpy.types.Operator):
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.manager
|
||||
wm.invoke_props_popup(self, event)
|
||||
return ('RUNNING_MODAL',)
|
||||
return wm.invoke_props_popup(self, event)
|
||||
|
||||
|
||||
class WM_OT_reload_scripts(bpy.types.Operator):
|
||||
|
||||
@@ -41,8 +41,7 @@ class ExportSomeData(bpy.types.Operator):
|
||||
return ('RUNNING_MODAL',)
|
||||
elif 0:
|
||||
# Redo popup
|
||||
wm.invoke_props_popup(self, event) #
|
||||
return ('RUNNING_MODAL',)
|
||||
return wm.invoke_props_popup(self, event) #
|
||||
elif 0:
|
||||
return self.execute(context)
|
||||
|
||||
|
||||
@@ -633,11 +633,13 @@ void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin
|
||||
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision);
|
||||
|
||||
int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **identifier);
|
||||
int RNA_enum_bitflag_identifierss(EnumPropertyItem *item, const int value, const char **identifier);
|
||||
int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name);
|
||||
|
||||
void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free);
|
||||
int RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value);
|
||||
int RNA_property_enum_identifier(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier);
|
||||
int RNA_property_enum_bitflag_identifiers(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier);
|
||||
|
||||
StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop);
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ extern EnumPropertyItem nla_mode_blend_items[];
|
||||
|
||||
extern EnumPropertyItem event_value_items[];
|
||||
extern EnumPropertyItem event_type_items[];
|
||||
extern EnumPropertyItem operator_return_items[];
|
||||
|
||||
extern EnumPropertyItem brush_sculpt_tool_items[];
|
||||
|
||||
|
||||
@@ -87,6 +87,8 @@ typedef enum PropertyUnit {
|
||||
#define RNA_SUBTYPE_UNIT(subtype) (subtype & 0x00FF0000)
|
||||
#define RNA_SUBTYPE_UNIT_VALUE(subtype) (subtype>>16)
|
||||
|
||||
#define RNA_ENUM_BITFLAG_SIZE 32
|
||||
|
||||
/* also update rna_property_subtypename when you change this */
|
||||
typedef enum PropertySubType {
|
||||
PROP_NONE = 0,
|
||||
@@ -161,6 +163,9 @@ typedef enum PropertyFlag {
|
||||
PROP_ID_SELF_CHECK = 1<<20,
|
||||
PROP_NEVER_NULL = 1<<18,
|
||||
|
||||
/* flag contains multiple enums */
|
||||
PROP_ENUM_FLAG = 1<<21,
|
||||
|
||||
/* internal flags */
|
||||
PROP_BUILTIN = 1<<7,
|
||||
PROP_EXPORT = 1<<8,
|
||||
|
||||
@@ -972,6 +972,18 @@ int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **id
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RNA_enum_bitflag_identifiers(EnumPropertyItem *item, const int value, const char **identifier)
|
||||
{
|
||||
int index= 0;
|
||||
for (; item->identifier; item++) {
|
||||
if(item->identifier[0] && item->value & value) {
|
||||
identifier[index++] = item->identifier;
|
||||
}
|
||||
}
|
||||
identifier[index]= NULL;
|
||||
return index;
|
||||
}
|
||||
|
||||
int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name)
|
||||
{
|
||||
for (; item->identifier; item++) {
|
||||
@@ -999,6 +1011,22 @@ int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
|
||||
{
|
||||
EnumPropertyItem *item= NULL;
|
||||
int result, free;
|
||||
|
||||
RNA_property_enum_items(C, ptr, prop, &item, NULL, &free);
|
||||
if(item) {
|
||||
result= RNA_enum_bitflag_identifiers(item, value, identifier);
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *RNA_property_ui_name(PropertyRNA *prop)
|
||||
{
|
||||
return rna_ensure_property_name(prop);
|
||||
|
||||
@@ -243,6 +243,13 @@ EnumPropertyItem keymap_modifiers_items[] = {
|
||||
{2, "SECOND", 0, "Second", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
EnumPropertyItem operator_return_items[] = {
|
||||
{OPERATOR_RUNNING_MODAL, "RUNNING_MODAL", 0, "Running Modal", ""},
|
||||
{OPERATOR_CANCELLED, "CANCELLED", 0, "Cancelled", ""},
|
||||
{OPERATOR_FINISHED, "FINISHED", 0, "Finished", ""},
|
||||
{OPERATOR_PASS_THROUGH, "PASS_THROUGH", 0, "Pass Through", ""}, // used as a flag
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
#define KMI_TYPE_KEYBOARD 0
|
||||
#define KMI_TYPE_MOUSE 1
|
||||
#define KMI_TYPE_TWEAK 2
|
||||
|
||||
@@ -146,7 +146,11 @@ void RNA_api_wm(StructRNA *srna)
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
parm= RNA_def_pointer(func, "event", "Event", "", "Event.");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
RNA_def_function_return(func, RNA_def_int(func, "mode", 0, 0, INT_MAX, "Mode", "", 0, INT_MAX)); // XXX, should be an enum/flag thingo
|
||||
|
||||
parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
|
||||
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
|
||||
/* invoke functions, for use with python */
|
||||
func= RNA_def_function(srna, "invoke_popup", "WM_operator_ui_popup");
|
||||
|
||||
@@ -379,6 +379,70 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
|
||||
return 1;
|
||||
}
|
||||
|
||||
static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
|
||||
{
|
||||
PyObject *ret= NULL;
|
||||
|
||||
if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
|
||||
const char *identifier[RNA_ENUM_BITFLAG_SIZE + 1];
|
||||
int index;
|
||||
|
||||
if ((index=RNA_property_enum_bitflag_identifiers(BPy_GetContext(), ptr, prop, val, identifier))) {
|
||||
ret= PyTuple_New(index);
|
||||
index= 0;
|
||||
|
||||
while(identifier[index]) {
|
||||
PyTuple_SET_ITEM(ret, index, PyUnicode_FromString(identifier[index]));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret= PyTuple_New(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const char *identifier;
|
||||
if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
|
||||
ret = PyUnicode_FromString(identifier);
|
||||
} else {
|
||||
EnumPropertyItem *item;
|
||||
int free= FALSE;
|
||||
|
||||
/* don't throw error here, can't trust blender 100% to give the
|
||||
* right values, python code should not generate error for that */
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
if(item && item->identifier) {
|
||||
ret= PyUnicode_FromString(item->identifier);
|
||||
}
|
||||
else {
|
||||
char *ptr_name= RNA_struct_name_get_alloc(ptr, NULL, FALSE);
|
||||
|
||||
/* prefer not fail silently incase of api errors, maybe disable it later */
|
||||
printf("RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'\n", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
|
||||
|
||||
#if 0 // gives python decoding errors while generating docs :(
|
||||
char error_str[256];
|
||||
snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
|
||||
PyErr_Warn(PyExc_RuntimeWarning, error_str);
|
||||
#endif
|
||||
|
||||
if(ptr_name)
|
||||
MEM_freeN(ptr_name);
|
||||
|
||||
ret = PyUnicode_FromString( "" );
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
/*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
|
||||
ret = NULL;*/
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
PyObject *ret;
|
||||
@@ -409,46 +473,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
|
||||
}
|
||||
case PROP_ENUM:
|
||||
{
|
||||
const char *identifier;
|
||||
int val = RNA_property_enum_get(ptr, prop);
|
||||
|
||||
if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
|
||||
ret = PyUnicode_FromString( identifier );
|
||||
} else {
|
||||
EnumPropertyItem *item;
|
||||
int free= FALSE;
|
||||
|
||||
/* don't throw error here, can't trust blender 100% to give the
|
||||
* right values, python code should not generate error for that */
|
||||
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
|
||||
if(item && item->identifier) {
|
||||
ret = PyUnicode_FromString( item->identifier );
|
||||
}
|
||||
else {
|
||||
char *ptr_name= RNA_struct_name_get_alloc(ptr, NULL, FALSE);
|
||||
|
||||
/* prefer not fail silently incase of api errors, maybe disable it later */
|
||||
printf("RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'\n", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
|
||||
|
||||
#if 0 // gives python decoding errors while generating docs :(
|
||||
char error_str[256];
|
||||
snprintf(error_str, sizeof(error_str), "RNA Warning: Current value \"%d\" matches no enum in '%s', '%s', '%s'", val, RNA_struct_identifier(ptr->type), ptr_name, RNA_property_identifier(prop));
|
||||
PyErr_Warn(PyExc_RuntimeWarning, error_str);
|
||||
#endif
|
||||
|
||||
if(ptr_name)
|
||||
MEM_freeN(ptr_name);
|
||||
|
||||
ret = PyUnicode_FromString( "" );
|
||||
}
|
||||
|
||||
if(free)
|
||||
MEM_freeN(item);
|
||||
|
||||
/*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
|
||||
ret = NULL;*/
|
||||
}
|
||||
|
||||
ret= pyrna_enum_to_py(ptr, prop, RNA_property_enum_get(ptr, prop));
|
||||
break;
|
||||
}
|
||||
case PROP_POINTER:
|
||||
@@ -2422,22 +2447,7 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
|
||||
}
|
||||
case PROP_ENUM:
|
||||
{
|
||||
const char *identifier;
|
||||
int val = *(int*)data;
|
||||
|
||||
if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
|
||||
ret = PyUnicode_FromString( identifier );
|
||||
} else {
|
||||
/* prefer not fail silently incase of api errors, maybe disable it later */
|
||||
char error_str[128];
|
||||
sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val);
|
||||
PyErr_Warn(PyExc_RuntimeWarning, error_str);
|
||||
|
||||
ret = PyUnicode_FromString( "" );
|
||||
/*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
|
||||
ret = NULL;*/
|
||||
}
|
||||
|
||||
ret= pyrna_enum_to_py(ptr, prop, *(int*)data);
|
||||
break;
|
||||
}
|
||||
case PROP_POINTER:
|
||||
|
||||
Reference in New Issue
Block a user