Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 17:18:39 +0000 (03:18 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 7 Sep 2017 17:18:39 +0000 (03:18 +1000)
release/scripts/modules/nodeitems_utils.py
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_ops.c
source/blender/python/intern/bpy_rna.c

index 4be6e340760844065fae3e15e8fc88e84e6fd81f..7dc456f6c984d9477557ae333a73a74fc9b7d98c 100644 (file)
@@ -59,8 +59,11 @@ class NodeItem:
             return self._label
         else:
             # if no custom label is defined, fall back to the node type UI name
-            cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
-            return cls.bl_rna.name
+            cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
+            if cls is not None:
+                return cls.bl_rna.name
+            else:
+                return "Unknown"
 
     @property
     def translation_context(self):
@@ -68,8 +71,11 @@ class NodeItem:
             return bpy.app.translations.contexts.default
         else:
             # if no custom label is defined, fall back to the node type UI name
-            cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
-            return cls.bl_rna.translation_context
+            cls = bpy.types.Node.bl_rna_get_subclass(self.nodetype)
+            if cls is not None:
+                return cls.bl_rna.translation_context
+            else:
+                return bpy.app.translations.contexts.default
 
     # NB: is a staticmethod because called with an explicit self argument
     # NodeItemCustom sets this as a variable attribute in __init__
index 75b947d455e506222b58141be185f14ad8d9af84..cc3faf82db0a00a35d13d7d123ade7892f469127 100644 (file)
@@ -1438,87 +1438,82 @@ static bool ui_selectcontext_begin(
                const bool is_array = RNA_property_array_check(prop);
                const int rna_type = RNA_property_type(prop);
 
-               if (!UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path)) {
-                       goto finally;
-               }
-
-               selctx_data->elems_len = BLI_listbase_count(&lb);
-               if (selctx_data->elems_len == 0) {
-                       goto finally;
-               }
-
-               selctx_data->elems = MEM_mallocN(sizeof(uiSelectContextElem) * selctx_data->elems_len, __func__);
+               if (UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path) &&
+                   !BLI_listbase_is_empty(&lb))
+               {
+                       selctx_data->elems_len = BLI_listbase_count(&lb);
+                       selctx_data->elems = MEM_mallocN(sizeof(uiSelectContextElem) * selctx_data->elems_len, __func__);
 
-               for (i = 0, link = lb.first; i < selctx_data->elems_len; i++, link = link->next) {
-                       uiSelectContextElem *other = &selctx_data->elems[i];
-                       /* TODO,. de-duplicate copy_to_selected_button */
-                       if (link->ptr.data != ptr.data) {
-                               if (use_path_from_id) {
-                                       /* Path relative to ID. */
-                                       lprop = NULL;
-                                       RNA_id_pointer_create(link->ptr.id.data, &idptr);
-                                       RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
-                               }
-                               else if (path) {
-                                       /* Path relative to elements from list. */
-                                       lprop = NULL;
-                                       RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
-                               }
-                               else {
-                                       lptr = link->ptr;
-                                       lprop = prop;
-                               }
+                       for (i = 0, link = lb.first; i < selctx_data->elems_len; i++, link = link->next) {
+                               uiSelectContextElem *other = &selctx_data->elems[i];
+                               /* TODO,. de-duplicate copy_to_selected_button */
+                               if (link->ptr.data != ptr.data) {
+                                       if (use_path_from_id) {
+                                               /* Path relative to ID. */
+                                               lprop = NULL;
+                                               RNA_id_pointer_create(link->ptr.id.data, &idptr);
+                                               RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
+                                       }
+                                       else if (path) {
+                                               /* Path relative to elements from list. */
+                                               lprop = NULL;
+                                               RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
+                                       }
+                                       else {
+                                               lptr = link->ptr;
+                                               lprop = prop;
+                                       }
 
-                               /* lptr might not be the same as link->ptr! */
-                               if ((lptr.data != ptr.data) &&
-                                   (lprop == prop) &&
-                                   RNA_property_editable(&lptr, lprop))
-                               {
-                                       other->ptr = lptr;
-                                       if (is_array) {
-                                               if (rna_type == PROP_FLOAT) {
-                                                       other->val_f = RNA_property_float_get_index(&lptr, lprop, index);
-                                               }
-                                               else if (rna_type == PROP_INT) {
-                                                       other->val_i = RNA_property_int_get_index(&lptr, lprop, index);
-                                               }
-                                               /* ignored for now */
+                                       /* lptr might not be the same as link->ptr! */
+                                       if ((lptr.data != ptr.data) &&
+                                           (lprop == prop) &&
+                                           RNA_property_editable(&lptr, lprop))
+                                       {
+                                               other->ptr = lptr;
+                                               if (is_array) {
+                                                       if (rna_type == PROP_FLOAT) {
+                                                               other->val_f = RNA_property_float_get_index(&lptr, lprop, index);
+                                                       }
+                                                       else if (rna_type == PROP_INT) {
+                                                               other->val_i = RNA_property_int_get_index(&lptr, lprop, index);
+                                                       }
+                                                       /* ignored for now */
 #if 0
-                                               else if (rna_type == PROP_BOOLEAN) {
-                                                       other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index);
-                                               }
+                                                       else if (rna_type == PROP_BOOLEAN) {
+                                                               other->val_b = RNA_property_boolean_get_index(&lptr, lprop, index);
+                                                       }
 #endif
-                                       }
-                                       else {
-                                               if (rna_type == PROP_FLOAT) {
-                                                       other->val_f = RNA_property_float_get(&lptr, lprop);
-                                               }
-                                               else if (rna_type == PROP_INT) {
-                                                       other->val_i = RNA_property_int_get(&lptr, lprop);
                                                }
-                                               /* ignored for now */
+                                               else {
+                                                       if (rna_type == PROP_FLOAT) {
+                                                               other->val_f = RNA_property_float_get(&lptr, lprop);
+                                                       }
+                                                       else if (rna_type == PROP_INT) {
+                                                               other->val_i = RNA_property_int_get(&lptr, lprop);
+                                                       }
+                                                       /* ignored for now */
 #if 0
-                                               else if (rna_type == PROP_BOOLEAN) {
-                                                       other->val_b = RNA_property_boolean_get(&lptr, lprop);
-                                               }
-                                               else if (rna_type == PROP_ENUM) {
-                                                       other->val_i = RNA_property_enum_get(&lptr, lprop);
-                                               }
+                                                       else if (rna_type == PROP_BOOLEAN) {
+                                                               other->val_b = RNA_property_boolean_get(&lptr, lprop);
+                                                       }
+                                                       else if (rna_type == PROP_ENUM) {
+                                                               other->val_i = RNA_property_enum_get(&lptr, lprop);
+                                                       }
 #endif
-                                       }
+                                               }
 
-                                       continue;
+                                               continue;
+                                       }
                                }
+
+                               selctx_data->elems_len -= 1;
+                               i -= 1;
                        }
 
-                       selctx_data->elems_len -= 1;
-                       i -= 1;
+                       success = (selctx_data->elems_len != 0);
                }
        }
 
-       success = (selctx_data->elems_len != 0);
-
-finally:
        if (selctx_data->elems_len == 0) {
                MEM_SAFE_FREE(selctx_data->elems);
        }
index 95ea2b87cba64c65ae34fc634a3a556a1d4ed951..40ca2d41372a375d2d1b45ff4fe66f6a477b3d3f 100644 (file)
@@ -621,51 +621,51 @@ static bool copy_to_selected_button(bContext *C, bool all, bool poll)
                char *path = NULL;
                bool use_path_from_id;
                CollectionPointerLink *link;
-               ListBase lb;
-
-               if (!UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path))
-                       return success;
+               ListBase lb = {NULL};
 
-               for (link = lb.first; link; link = link->next) {
-                       if (link->ptr.data != ptr.data) {
-                               if (use_path_from_id) {
-                                       /* Path relative to ID. */
-                                       lprop = NULL;
-                                       RNA_id_pointer_create(link->ptr.id.data, &idptr);
-                                       RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
-                               }
-                               else if (path) {
-                                       /* Path relative to elements from list. */
-                                       lprop = NULL;
-                                       RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
-                               }
-                               else {
-                                       lptr = link->ptr;
-                                       lprop = prop;
-                               }
+               if (UI_context_copy_to_selected_list(C, &ptr, prop, &lb, &use_path_from_id, &path) &&
+                   !BLI_listbase_is_empty(&lb))
+               {
+                       for (link = lb.first; link; link = link->next) {
+                               if (link->ptr.data != ptr.data) {
+                                       if (use_path_from_id) {
+                                               /* Path relative to ID. */
+                                               lprop = NULL;
+                                               RNA_id_pointer_create(link->ptr.id.data, &idptr);
+                                               RNA_path_resolve_property(&idptr, path, &lptr, &lprop);
+                                       }
+                                       else if (path) {
+                                               /* Path relative to elements from list. */
+                                               lprop = NULL;
+                                               RNA_path_resolve_property(&link->ptr, path, &lptr, &lprop);
+                                       }
+                                       else {
+                                               lptr = link->ptr;
+                                               lprop = prop;
+                                       }
 
-                               if (lptr.data == ptr.data) {
-                                       /* lptr might not be the same as link->ptr! */
-                                       continue;
-                               }
+                                       if (lptr.data == ptr.data) {
+                                               /* lptr might not be the same as link->ptr! */
+                                               continue;
+                                       }
 
-                               if (lprop == prop) {
-                                       if (RNA_property_editable(&lptr, lprop)) {
-                                               if (poll) {
-                                                       success = true;
-                                                       break;
-                                               }
-                                               else {
-                                                       if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
-                                                               RNA_property_update(C, &lptr, prop);
+                                       if (lprop == prop) {
+                                               if (RNA_property_editable(&lptr, lprop)) {
+                                                       if (poll) {
                                                                success = true;
+                                                               break;
+                                                       }
+                                                       else {
+                                                               if (RNA_property_copy(&lptr, &ptr, prop, (all) ? -1 : index)) {
+                                                                       RNA_property_update(C, &lptr, prop);
+                                                                       success = true;
+                                                               }
                                                        }
                                                }
                                        }
                                }
                        }
                }
-
                MEM_SAFE_FREE(path);
                BLI_freelistN(&lb);
        }
index 2ffb2ba5291b9cc4c816b0ef1579a0dc090033d1..1368b610b53e1021cd26d8d74d524b7da76d4305 100644 (file)
@@ -3716,6 +3716,66 @@ static PyObject *pyrna_struct_type_recast(BPy_StructRNA *self)
        return pyrna_struct_CreatePyObject(&r_ptr);
 }
 
+/**
+ * \note Return value is borrowed, caller must incref.
+ */
+static PyObject *pyrna_struct_bl_rna_find_subclass_recursive(PyObject *cls, const char *id)
+{
+       PyObject *ret_test = NULL;
+       PyObject *subclasses = ((PyTypeObject *)cls)->tp_subclasses;
+       if (subclasses) {
+               /* Unfortunately we can't use the dict key because Python class names
+                * don't match the bl_idname used internally. */
+               BLI_assert(PyDict_CheckExact(subclasses));
+               PyObject *key = NULL;
+               Py_ssize_t pos = 0;
+               PyObject *value = NULL;
+               while (PyDict_Next(subclasses, &pos, &key, &value)) {
+                       BLI_assert(PyWeakref_CheckRef(value));
+                       PyObject *subcls = PyWeakref_GET_OBJECT(value);
+                       if (subcls != Py_None) {
+                               BPy_StructRNA *py_srna = (BPy_StructRNA *)PyDict_GetItem(
+                                       ((PyTypeObject *)subcls)->tp_dict, bpy_intern_str_bl_rna);
+                               if (py_srna) {
+                                       StructRNA *srna = py_srna->ptr.data;
+                                       if (STREQ(id, RNA_struct_identifier(srna))) {
+                                               ret_test = subcls;
+                                               break;
+                                       }
+                               }
+                               ret_test = pyrna_struct_bl_rna_find_subclass_recursive(subcls, id);
+                               if (ret_test) {
+                                       break;
+                               }
+                       }
+               }
+       }
+       return ret_test;
+}
+
+PyDoc_STRVAR(pyrna_struct_bl_rna_get_subclass_doc,
+".. classmethod:: bl_rna_get_subclass(id, default=None)\n"
+"\n"
+"   :arg id: The RNA type identifier.\n"
+"   :type vector: string\n"
+"   :return: The class or default when not found.\n"
+"   :rtype: type\n"
+);
+static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args)
+{
+       char *id;
+       PyObject *ret_default = Py_None;
+
+       if (!PyArg_ParseTuple(args, "s|O:bl_rna_get_subclass", &id, &ret_default)) {
+               return NULL;
+       }
+       PyObject *ret = pyrna_struct_bl_rna_find_subclass_recursive(cls, id);
+       if (ret == NULL) {
+               ret = ret_default;
+       }
+       return Py_INCREF_RET(ret);
+}
+
 static void pyrna_dir_members_py__add_keys(PyObject *list, PyObject *dict)
 {
        PyObject *list_tmp;
@@ -5014,6 +5074,7 @@ static struct PyMethodDef pyrna_struct_methods[] = {
        {"path_resolve", (PyCFunction)pyrna_struct_path_resolve, METH_VARARGS, pyrna_struct_path_resolve_doc},
        {"path_from_id", (PyCFunction)pyrna_struct_path_from_id, METH_VARARGS, pyrna_struct_path_from_id_doc},
        {"type_recast", (PyCFunction)pyrna_struct_type_recast, METH_NOARGS, pyrna_struct_type_recast_doc},
+       {"bl_rna_get_subclass", (PyCFunction) pyrna_struct_bl_rna_get_subclass, METH_VARARGS | METH_CLASS, pyrna_struct_bl_rna_get_subclass_doc},
        {"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL},
 
        /* experimental */