merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
[blender-staging.git] / source / blender / python / intern / bpy_interface.c
index b3a3c6c1915a060d580b8e851889b9bddb34630a..02eebde8a137a0dc5643301c4c2527255811e25a 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * Contributor(s): Michel Selten, Willian P. Germano, Stephen Swaney,
  * Chris Keith, Chris Want, Ken Hughes, Campbell Barton
@@ -62,6 +62,7 @@
 #include "BKE_text.h"
 #include "BKE_context.h"
 #include "BKE_main.h"
+#include "BKE_global.h" /* only for script checking */
 
 #include "BPY_extern.h"
 
@@ -249,7 +250,10 @@ void BPY_start_python( int argc, char **argv )
 
        Py_Initialize(  );
        
+       /*convert argv to wchar_t*/
        // PySys_SetArgv( argc, argv); // broken in py3, not a huge deal
+       
+       /*temporarily set argv*/
        /* sigh, why do python guys not have a char** version anymore? :( */
        {
                int i;
@@ -556,24 +560,26 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
        PyObject *dict, *mod, *retval;
        int error_ret = 0;
        
-       if (!value || !expr || expr[0]=='\0') return -1;
-       
+       if (!value || !expr) return -1;
+
+       if(expr[0]=='\0') {
+               *value= 0.0;
+               return error_ret;
+       }
+
        bpy_context_set(C, &gilstate);
        
        dict= CreateGlobalDictionary(C, NULL);
-       
-       /* import some modules: builtins,math*/
-       PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
 
        mod = PyImport_ImportModule("math");
        if (mod) {
                PyDict_Merge(dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
-               
-               /* Only keep for backwards compat! - just import all math into root, they are standard */
-               PyDict_SetItemString(dict, "math", mod);
-               PyDict_SetItemString(dict, "m", mod);
                Py_DECREF(mod);
-       } 
+       }
+       else { /* highly unlikely but possibly */
+               PyErr_Print();
+               PyErr_Clear();
+       }
        
        retval = PyRun_String(expr, Py_eval_input, dict, dict);
        
@@ -630,14 +636,19 @@ void BPY_load_user_modules(bContext *C)
 
        for(text=CTX_data_main(C)->text.first; text; text= text->id.next) {
                if(text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) {
-                       PyObject *module= bpy_text_import(text);
-
-                       if (module==NULL) {
-                               PyErr_Print();
-                               PyErr_Clear();
+                       if(!(G.f & G_SCRIPT_AUTOEXEC)) {
+                               printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name+2);
                        }
                        else {
-                               Py_DECREF(module);
+                               PyObject *module= bpy_text_import(text);
+
+                               if (module==NULL) {
+                                       PyErr_Print();
+                                       PyErr_Clear();
+                               }
+                               else {
+                                       Py_DECREF(module);
+                               }
                        }
                }
        }