From 4a385adbf339f585cc1802a1e5d277ff99438146 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Oct 2010 23:47:43 +0000 Subject: python api: - bpy.app.debug can now be set, removed bpy.data.debug (since this is not blendfile data) - added bpy.app.tempdir, this is needed because the userpref temp dir isn't always set, $TEMP may be used instead and scripts need temp dir access. --- source/blender/makesrna/intern/rna_define.c | 3 +- source/blender/makesrna/intern/rna_main.c | 18 -------- source/blender/python/intern/bpy_app.c | 70 +++++++++++++++++++++++++---- source/blender/python/intern/bpy_rna.c | 2 +- 4 files changed, 64 insertions(+), 29 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 1fed1663952..0a8e0bad7f0 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -474,11 +474,12 @@ void RNA_struct_free(BlenderRNA *brna, StructRNA *srna) PropertyRNA *prop, *nextprop; PropertyRNA *parm, *nextparm; + /* if(srna->flag & STRUCT_RUNTIME) { if(RNA_struct_py_type_get(srna)) { fprintf(stderr, "RNA_struct_free '%s' freed while holding a python reference\n", srna->identifier); } - } + } */ for(prop=srna->cont.properties.first; prop; prop=nextprop) { nextprop= prop->next; diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 99758b8f0fe..e626abd85c7 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -36,19 +36,6 @@ #include "BKE_global.h" /* all the list begin functions are added manually here, Main is not in SDNA */ -static int rna_Main_debug_get(PointerRNA *ptr) -{ - return G.f & G_DEBUG; -} - - -static void rna_Main_debug_set(PointerRNA *ptr, const int value) -{ - if (value) - G.f |= G_DEBUG; - else - G.f &= ~G_DEBUG; -} static int rna_Main_is_dirty_get(PointerRNA *ptr) { @@ -317,11 +304,6 @@ void RNA_def_main(BlenderRNA *brna) RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL); RNA_def_property_ui_text(prop, "File is Saved", "Has the current session been saved to disk as a .blend file"); - prop= RNA_def_property(srna, "debug", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_funcs(prop, "rna_Main_debug_get", "rna_Main_debug_set"); - RNA_def_property_ui_text(prop, "Debug", "Print debugging information in console"); - - for(i=0; lists[i].name; i++) { prop= RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE); diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 78658a611a3..f506f91292f 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -44,7 +44,6 @@ static PyStructSequence_Field app_info_fields[] = { {"version", "The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"}, {"version_string", "The Blender version formatted as a string"}, {"binary_path", "The location of blenders executable, useful for utilities that spawn new instances"}, - {"debug", "Boolean, set when blender is running in debug mode (started with -d)"}, {"background", "Boolean, True when blender is running without a user interface (started with -b)"}, /* buildinfo */ @@ -85,7 +84,6 @@ static PyObject *make_app_info(void) SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION)); SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION)); SetStrItem(bprogname); - SetObjItem(PyBool_FromLong(G.f & G_DEBUG)); SetObjItem(PyBool_FromLong(G.background)); /* build info */ @@ -96,11 +94,11 @@ static PyObject *make_app_info(void) SetStrItem(build_platform); SetStrItem(build_type); #else - SetStrItem("Unknown"); - SetStrItem("Unknown"); - SetStrItem("Unknown"); - SetStrItem("Unknown"); - SetStrItem("Unknown"); + SetStrItem("Unknown"); + SetStrItem("Unknown"); + SetStrItem("Unknown"); + SetStrItem("Unknown"); + SetStrItem("Unknown"); #endif #undef SetIntItem @@ -114,10 +112,60 @@ static PyObject *make_app_info(void) return app_info; } +/* a few getsets because it makes sense for them to be in bpy.app even though + * they are not static */ +static PyObject *bpy_app_debug_get(PyObject *self, void *closure) +{ + (void)(self); + (void)(closure); + + return PyBool_FromLong(G.f & G_DEBUG); +} + +static int bpy_app_debug_set(PyObject *self, PyObject *value, void *closure) +{ + int param= PyObject_IsTrue(value); + + (void)(self); + (void)(closure); + + if(param < 0) { + PyErr_SetString(PyExc_TypeError, "bpy.app.debug can only be True/False"); + return -1; + } + + if(param) G.f |= G_DEBUG; + else G.f &= ~G_DEBUG; + + return 0; +} + +static PyObject *bpy_app_tempdir_get(PyObject *self, void *closure) +{ + extern char btempdir[]; + (void)(self); + (void)(closure); + + return PyUnicode_FromString(btempdir); +} + +PyGetSetDef bpy_app_debug_getset= {"debug", bpy_app_debug_get, bpy_app_debug_set, "Boolean, set when blender is running in debug mode (started with -d)", NULL}; +PyGetSetDef bpy_app_tempdir_getset= {"tempdir", bpy_app_tempdir_get, NULL, "String, the temp directory used by blender (read-only)", NULL}; + +static void py_struct_seq_getset_init(void) +{ + /* tricky dynamic members, not to py-spec! */ + + PyDict_SetItemString(BlenderAppType.tp_dict, bpy_app_debug_getset.name, PyDescr_NewGetSet(&BlenderAppType, &bpy_app_debug_getset)); + PyDict_SetItemString(BlenderAppType.tp_dict, bpy_app_tempdir_getset.name, PyDescr_NewGetSet(&BlenderAppType, &bpy_app_tempdir_getset)); +} +/* end dynamic bpy.app */ + + PyObject *BPY_app_struct(void) { PyObject *ret; - + PyStructSequence_InitType(&BlenderAppType, &app_info_desc); ret= make_app_info(); @@ -125,6 +173,10 @@ PyObject *BPY_app_struct(void) /* prevent user from creating new instances */ BlenderAppType.tp_init = NULL; BlenderAppType.tp_new = NULL; - + + /* kindof a hack ontop of PyStructSequence */ + py_struct_seq_getset_init(); + return ret; } + diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 166213fa07c..b49a48699fa 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -964,7 +964,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *p else param = PyLong_AsLong( value ); - if( param < 0 || param > 1) { + if(param < 0) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop)); return -1; } else { -- cgit v1.2.3