rna flag PROP_ENUM_FLAG which makes rna props a tuple of enums when converted into...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 7 Dec 2009 00:16:57 +0000 (00:16 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 7 Dec 2009 00:16:57 +0000 (00:16 +0000)
only used by wm.invoke_props_popup() currently

12 files changed:
release/scripts/modules/rna_prop_ui.py
release/scripts/op/object.py
release/scripts/op/presets.py
release/scripts/op/wm.py
release/scripts/templates/operator.py
source/blender/makesrna/RNA_access.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_wm.c
source/blender/makesrna/intern/rna_wm_api.c
source/blender/python/intern/bpy_rna.c

index 51281c480b93825c5a0f1b7c1d9a30b24732930a..ca452da7f73dc33493b83d710564e968133af146 100644 (file)
@@ -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):
index db50412464b418e6dd6b26c4e39a2e565c16fbf4..8a02d10838b1aa1e36376b7b166a16ba65b6568b 100644 (file)
@@ -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
index 84a60765fa4f67f5592f0365524eb986218c3920..0ce19f712ab0b5028255d77e4710363ed9cc2f8e 100644 (file)
@@ -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',)
 
index c5fc18964bf98187aa4d40221ad5ae002cc5cc49..7000eaffebfca48defa4654cfd20e0101b6eebf8 100644 (file)
@@ -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):
index 5e8a2f33cb7d719d2d2b17952262051553834668..72a6ae53f5f398210613649b05c09ba3b764190b 100644 (file)
@@ -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)
 
index 959109f7bbb770cd3aaa3371c2079a5543f3a0c3..263183cadd87149ed282e977c8113aa27b31f8fa 100644 (file)
@@ -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);
 
index b33dbe6f20d65ed24b1ea48f6af87b5ef308029b..479397a21801370ce0b0562350e2dacd0d3ee420 100644 (file)
@@ -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[];
 
index 27dd1069c1c1b26e579e64ff476c2fb311335a7a..8743bb39d5706e746028b4e47b37c458dafda830 100644 (file)
@@ -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,
index 5ee811d4c464214a28b1d20099342d0f56411907..360f43428d1f9c8f7298e625f08b7797ad35a138 100644 (file)
@@ -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);
index 35f2a31b7efcbf82b57576c1c9084c92d9761b66..2e4c069003140b84d43f266f9fd4805fc164d3de 100644 (file)
@@ -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
index 50b0e37b7cd0bd2fd51f7698c4d4b997287a3c59..ce26072e91b2af5988841497ba884d23b23bbd9e 100644 (file)
@@ -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");
index 9370ec91d379e35119ca5f5cca94467df7f6cf85..9136a1663658dc4ae1108cc6a6ee6871a0bd62c8 100644 (file)
@@ -379,41 +379,31 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
        return 1;
 }
 
-PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
+static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
 {
-       PyObject *ret;
-       int type = RNA_property_type(prop);
+       PyObject *ret= NULL;
 
-       if (RNA_property_array_check(ptr, prop)) {
-               return pyrna_py_from_array(ptr, prop);
-       }
-       
-       /* see if we can coorce into a python type - PropertyType */
-       switch (type) {
-       case PROP_BOOLEAN:
-               ret = PyBool_FromLong( RNA_property_boolean_get(ptr, prop) );
-               break;
-       case PROP_INT:
-               ret = PyLong_FromSsize_t( (Py_ssize_t)RNA_property_int_get(ptr, prop) );
-               break;
-       case PROP_FLOAT:
-               ret = PyFloat_FromDouble( RNA_property_float_get(ptr, prop) );
-               break;
-       case PROP_STRING:
-       {
-               char *buf;
-               buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
-               ret = PyUnicode_FromString( buf );
-               MEM_freeN(buf);
-               break;
+       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);
+               }
        }
-       case PROP_ENUM:
-       {
+       else {
                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 );
+                       ret = PyUnicode_FromString(identifier);
                } else {
                        EnumPropertyItem *item;
                        int free= FALSE;
@@ -422,11 +412,11 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
                         * 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 );
+                               ret= PyUnicode_FromString(item->identifier);
                        }
                        else {
-                       char *ptr_name= RNA_struct_name_get_alloc(ptr, NULL, FALSE);
-                       
+                               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));
 
@@ -436,8 +426,8 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
                                PyErr_Warn(PyExc_RuntimeWarning, error_str);
 #endif
 
-                   if(ptr_name) 
-                           MEM_freeN(ptr_name);
+                               if(ptr_name)
+                                       MEM_freeN(ptr_name);
 
                                ret = PyUnicode_FromString( "" );
                        }
@@ -448,7 +438,42 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
                        /*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;
+       int type = RNA_property_type(prop);
 
+       if (RNA_property_array_check(ptr, prop)) {
+               return pyrna_py_from_array(ptr, prop);
+       }
+       
+       /* see if we can coorce into a python type - PropertyType */
+       switch (type) {
+       case PROP_BOOLEAN:
+               ret = PyBool_FromLong( RNA_property_boolean_get(ptr, prop) );
+               break;
+       case PROP_INT:
+               ret = PyLong_FromSsize_t( (Py_ssize_t)RNA_property_int_get(ptr, prop) );
+               break;
+       case PROP_FLOAT:
+               ret = PyFloat_FromDouble( RNA_property_float_get(ptr, prop) );
+               break;
+       case PROP_STRING:
+       {
+               char *buf;
+               buf = RNA_property_string_get_alloc(ptr, prop, NULL, -1);
+               ret = PyUnicode_FromString( buf );
+               MEM_freeN(buf);
+               break;
+       }
+       case PROP_ENUM:
+       {
+               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: