diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 85162182e31..2dff0d1b0e1 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -222,7 +222,7 @@ struct _object *BPY_txt_do_python(struct SpaceText* st) { PyObject *dict, *ret; - printf ("In BPY_txt_do_python\n"); + printf ("\nIn BPY_txt_do_python\n"); if (!st->text) return NULL; @@ -230,7 +230,7 @@ struct _object *BPY_txt_do_python(struct SpaceText* st) * the script with a clean global dictionary or should keep the current one, * possibly already "polluted" by other calls to the Python Interpreter. * The default is to use a clean one. To change this the script writer must - * call Blender.releaseGlobalDict(bool), with bool != 0, in the script */ + * call Blender.releaseGlobalDict(bool), with bool == 0, in the script */ if (EXPP_releaseGlobalDict) { printf("Using a clean Global Dictionary.\n"); diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index c08b0015470..ac5c2f2bb03 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -36,6 +36,10 @@ #include "Draw.h" +/* declared in ../BPY_extern.h, + * used to control global dictionary persistence: */ +extern short EXPP_releaseGlobalDict; + static void Button_dealloc(PyObject *self) { Button *but = (Button*)self; @@ -192,21 +196,21 @@ int BPY_spacetext_is_pywin(SpaceText *st) static PyObject *Method_Exit (PyObject *self, PyObject *args) { SpaceText *st= curarea->spacedata.first; -#ifdef CLEAR_NAMESPACE - PyObject *d; -#endif + if (!PyArg_ParseTuple(args, "")) return EXPP_ReturnPyObjError (PyExc_AttributeError, "expected empty argument list"); exit_pydraw(st); -#ifdef CLEAR_NAMESPACE - d = st->py_globaldict; /* The current window's global namespace dictionary */ - if (d) { - PyDict_Clear(d); - Py_DECREF(d); /* release dictionary */ + + if (EXPP_releaseGlobalDict) { + PyObject *d = st->py_globaldict; + /* d is the current window's global namespace dictionary */ + if (d) { + PyDict_Clear(d); + Py_DECREF(d); /* release dictionary */ + } } -#endif return EXPP_incr_ret (Py_None); } diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index 3f0a345dc98..8db05474ecf 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -123,18 +123,26 @@ static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args) static void getSelectedFile(char *name) { if (EXPP_FS_PyCallback) { + SpaceText *st= curarea->spacedata.first; + PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name); - EXPP_FS_PyCallback = NULL; + + EXPP_FS_PyCallback = NULL; + st->flags &= ST_CLEAR_NAMESPACE; /* free global dictionary */ } } static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) { char *title = "SELECT FILE"; + SpaceText *st = curarea->spacedata.first; + if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback, &title)) return (EXPP_ReturnPyObjError (PyExc_AttributeError, - "\nexpected a callback function (and optionally a string) as argument(s)")); + "\nexpected a callback function (and optionally a string) as argument(s)")); + + st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */ activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile); @@ -145,10 +153,14 @@ static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args) static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args) { char *title = "SELECT IMAGE"; + SpaceText *st = curarea->spacedata.first; + if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback, &title)) return (EXPP_ReturnPyObjError (PyExc_AttributeError, - "\nexpected a callback function (and optionally a string) as argument(s)")); + "\nexpected a callback function (and optionally a string) as argument(s)")); + + st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */ activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);