Modified python rna property types (BPy_PropertyRNA), so PySequence_Check() returns...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 29 Oct 2009 10:03:34 +0000 (10:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 29 Oct 2009 10:03:34 +0000 (10:03 +0000)
this means you can do...
C = {"selected_editable_objects":bpy.data.objects}
...when defining pythons context, without doing list(bpy.data.objects)

source/blender/editors/object/object_add.c
source/blender/editors/object/object_relations.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/python/intern/bpy_interface.c
source/blender/python/intern/bpy_rna.c

index 44f80d54666aae56924f635c0beac148ec3407ab..9b7b23f10262d67679f6d2242d48a9ac6d901a7c 100644 (file)
@@ -737,7 +737,6 @@ static void copy_object__forwardModifierLinks(void *userData, Object *ob,
 /* after copying objects, copied data should get new pointers */
 static void copy_object_set_idnew(bContext *C, int dupflag)
 {
-       Object *ob;
        Material *ma, *mao;
        ID *id;
 #if 0 // XXX old animation system
index a4c9942833e7ca6fd41d6d7a78cc4a044bbd4f28..6849cefbbd9bb6dab00e939bc8a175d48d99ddf1 100644 (file)
@@ -976,7 +976,7 @@ static int track_set_exec(bContext *C, wmOperator *op)
                }
                CTX_DATA_END;
        }
-       DAG_scene_sort(CTX_data_scene(C));
+       DAG_scene_sort(scene);
        ED_anim_dag_flush_update(C);    
        
        return OPERATOR_FINISHED;
index d2d4b7ac2c46b9982a9c7c4785af8ff46555ec09..339ba55bfd15f5b9d8f9f67528bbf1bb0c648283 100644 (file)
@@ -2489,8 +2489,8 @@ static int find_next_prev_edit(Scene *scene, int cfra, int side)
        return best_seq ? best_seq->startdisp : cfra;
 }
 
-static int next_prev_edit_internal(Scene *scene, int side) {
-       Editing *ed= seq_give_editing(scene, FALSE);
+static int next_prev_edit_internal(Scene *scene, int side)
+{
        int change=0;
        int cfra = CFRA;
        int nfra= find_next_prev_edit(scene, cfra, side);
index dc7f6947f38025448aafcef19f0339cb856d0e8c..d0c70a9ee9696db0560346592a7700ddb0f3ada7 100644 (file)
@@ -971,28 +971,36 @@ int bpy_context_get(bContext *C, const char *member, bContextDataResult *result)
                CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data);
                done= 1;
        }
-       else if (PyList_Check(item)) {
-               int len= PyList_Size(item);
-               int i;
-               for(i = 0; i < len; i++) {
-                       PyObject *list_item = PyList_GET_ITEM(item, i); // XXX check type
-
-                       if(BPy_StructRNA_Check(list_item)) {
-                               /*
-                               CollectionPointerLink *link= MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
-                               link->ptr= ((BPy_StructRNA *)item)->ptr;
-                               BLI_addtail(&result->list, link);
-                               */
-                               ptr= &(((BPy_StructRNA *)list_item)->ptr);
-                               CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data);
-                       }
-                       else {
-                               printf("List item not a valid type\n");
+       else if (PySequence_Check(item)) {
+               PyObject *seq_fast= PySequence_Fast(item, "bpy_context_get sequence conversion");
+               if (seq_fast==NULL) {
+                       PyErr_Print();
+                       PyErr_Clear();
+               }
+               else {
+                       int len= PySequence_Fast_GET_SIZE(seq_fast);
+                       int i;
+                       for(i = 0; i < len; i++) {
+                               PyObject *list_item= PySequence_Fast_GET_ITEM(seq_fast, i);
+
+                               if(BPy_StructRNA_Check(list_item)) {
+                                       /*
+                                       CollectionPointerLink *link= MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
+                                       link->ptr= ((BPy_StructRNA *)item)->ptr;
+                                       BLI_addtail(&result->list, link);
+                                       */
+                                       ptr= &(((BPy_StructRNA *)list_item)->ptr);
+                                       CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data);
+                               }
+                               else {
+                                       printf("List item not a valid type\n");
+                               }
+
                        }
+                       Py_DECREF(seq_fast);
 
+                       done= 1;
                }
-
-               done= 1;
        }
 
        if(done==0) {
index b067d30e36efeaf3a4d2e06636dbc1875c56a4a5..0d338cd463102f714187e2049a06f687f0fea184 100644 (file)
@@ -1124,11 +1124,24 @@ static int pyrna_prop_contains(BPy_PropertyRNA * self, PyObject *value)
        return 0;
 }
 
+static PyObject *pyrna_prop_item(BPy_PropertyRNA * self, Py_ssize_t index)
+{
+       /* reuse subscript functions */
+       if (RNA_property_type(self->prop) == PROP_COLLECTION) {
+               return prop_subscript_collection_int(self, index);
+       } else if (RNA_property_array_check(&self->ptr, self->prop)) {
+               return prop_subscript_array_int(self, index);
+       }
+
+       PyErr_SetString(PyExc_TypeError, "rna type is not an array or a collection");
+       return NULL;
+}
+
 static PySequenceMethods pyrna_prop_as_sequence = {
        NULL,           /* Cant set the len otherwise it can evaluate as false */
        NULL,           /* sq_concat */
        NULL,           /* sq_repeat */
-       NULL,           /* sq_item */
+       (ssizeargfunc)pyrna_prop_item, /* sq_item */ /* Only set this so PySequence_Check() returns True */
        NULL,           /* sq_slice */
        NULL,           /* sq_ass_item */
        NULL,           /* sq_ass_slice */