rna functions were getting away with passing the string "True" instead of True, chang...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 22 Nov 2009 21:51:12 +0000 (21:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 22 Nov 2009 21:51:12 +0000 (21:51 +0000)
allow rna function return values as an exception since so many poll functions do... "return (context.blah and context.foo)", that makign all return bool's isnt that nice.

release/scripts/ui/properties_particle.py
source/blender/python/intern/bpy_rna.c

index 276643b32ff5e3cb98cc02c57a7e88acba1780ff..9315b209861fa8e17bfe596bd2ac93e56fd9f57f 100644 (file)
@@ -221,7 +221,7 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel):
         sub.itemR(cloth, "pin_stiffness", text="Stiffness")
         sub.itemR(cloth, "mass")
         sub.itemR(cloth, "bending_stiffness", text="Bending")
-        sub.itemR(cloth, "internal_friction", slider="True")
+        sub.itemR(cloth, "internal_friction", slider=True)
 
         col = split.column()
 
@@ -410,9 +410,9 @@ class PARTICLE_PT_physics(ParticleButtonsPanel):
             col = sub.column(align=True)
             col.active = boids.allow_flight
             col.itemR(boids, "air_max_speed")
-            col.itemR(boids, "air_min_speed", slider="True")
-            col.itemR(boids, "air_max_acc", slider="True")
-            col.itemR(boids, "air_max_ave", slider="True")
+            col.itemR(boids, "air_min_speed", slider=True)
+            col.itemR(boids, "air_max_acc", slider=True)
+            col.itemR(boids, "air_max_ave", slider=True)
             col.itemR(boids, "air_personal_space")
             row = col.row()
             row.active = (boids.allow_land or boids.allow_climb) and boids.allow_flight
@@ -423,8 +423,8 @@ class PARTICLE_PT_physics(ParticleButtonsPanel):
             col.active = boids.allow_land or boids.allow_climb
             col.itemR(boids, "land_max_speed")
             col.itemR(boids, "land_jump_speed")
-            col.itemR(boids, "land_max_acc", slider="True")
-            col.itemR(boids, "land_max_ave", slider="True")
+            col.itemR(boids, "land_max_acc", slider=True)
+            col.itemR(boids, "land_max_ave", slider=True)
             col.itemR(boids, "land_personal_space")
             col.itemR(boids, "land_stick_force")
 
index d25a240990b85e92a3537c9a6687d3fca54904a7..cdf4f518b51570efecbc087d12b49790f4916d09 100644 (file)
@@ -591,9 +591,16 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
                switch (type) {
                case PROP_BOOLEAN:
                {
-                       int param = PyObject_IsTrue( value );
+                       int param;
+                       /* prefer not to have an exception here
+                        * however so many poll functions return None or a valid Object.
+                        * its a hassle to convert these into a bool before returning, */
+                       if(RNA_property_flag(prop) & PROP_RETURN)
+                               param = PyObject_IsTrue( value );
+                       else
+                               param = PyLong_AsSsize_t( value );
                        
-                       if( param < 0 ) {
+                       if( param < 0 || param > 1) {
                                PyErr_Format(PyExc_TypeError, "%.200s expected True/False or 0/1", error_prefix);
                                return -1;
                        } else {
@@ -681,7 +688,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
                                PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptype));
                                return -1;
                        } else if((flag & PROP_NEVER_NULL) && value == Py_None) {
-                               PyErr_Format(PyExc_TypeError, "property can't be assigned a None value");
+                               PyErr_Format(PyExc_TypeError, "%.200s does not suppory a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptype));
                                return -1;
                        } else {
                                BPy_StructRNA *param= (BPy_StructRNA*)value;
@@ -813,9 +820,9 @@ static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *va
                switch (type) {
                case PROP_BOOLEAN:
                        {
-                               int param = PyObject_IsTrue( value );
+                               int param = PyLong_AsSsize_t( value );
                
-                               if( param < 0 ) {
+                               if( param < 0 || param > 1) {
                                        PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
                                        ret = -1;
                                } else {