Page Menu
Home
Search
Configure Global Search
Log In
Files
F1226
py_eval.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Martin Poirier (theeth)
Nov 13 2013, 12:55 PM
Size
4 KB
Subscribers
None
py_eval.patch
View Options
? blender
? blender-2.37a-linux-glibc2.3.4-i386
? blender-2.37a-linux-glibc2.3.4-i386.tar.gz
? blenderplayer
? commit.txt
? config.opts
? dist
? floorsticky.patch
? log.txt
? obj
? patch_uv_transform.patch
? py_eval.patch
? tools/__init__.pyc
? tools/scons/__init__.pyc
? tools/scons/bs/__init__.pyc
? tools/scons/bs/bs_arc.pyc
? tools/scons/bs/bs_bincopy.pyc
? tools/scons/bs/bs_clean.pyc
? tools/scons/bs/bs_config.pyc
? tools/scons/bs/bs_default.pyc
? tools/scons/bs/bs_dirs.pyc
? tools/scons/bs/bs_globals.pyc
? tools/scons/bs/bs_libs.pyc
? tools/scons/bs/bs_nsis.pyc
Index: source/blender/python/BPY_extern.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/BPY_extern.h,v
retrieving revision 1.23
diff -u -r1.23 BPY_extern.h
--- source/blender/python/BPY_extern.h 8 May 2005 21:20:33 -0000 1.23
+++ source/blender/python/BPY_extern.h 25 Sep 2005 15:07:47 -0000
@@ -76,6 +76,7 @@
int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
unsigned short space_event);
+ int BPY_evalDouble(char *str, double *value);
/* format importer hook */
int BPY_call_importloader( char *name );
Index: source/blender/python/BPY_interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/BPY_interface.c,v
retrieving revision 1.74
diff -u -r1.74 BPY_interface.c
--- source/blender/python/BPY_interface.c 9 Sep 2005 01:31:10 -0000 1.74
+++ source/blender/python/BPY_interface.c 25 Sep 2005 15:07:47 -0000
@@ -33,7 +33,7 @@
#include <Python.h>
-#include "compile.h" /* for the PyCodeObject */
+#include "compile.h" /* for the PyCodeObject */
#include "eval.h" /* for PyEval_EvalCode */
#include "BLI_blenlib.h" /* for BLI_last_slash() */
#include "BIF_interface.h" /* for pupmenu() */
@@ -1652,3 +1652,64 @@
d = PyModule_GetDict( m );
PyDict_SetItemString( d, "__import__", import );
}
+
+
+/* error return function for BPY_evalString */
+static int EvalError() {
+ PyErr_Print();
+ error("Python script error, check console");
+ return -1;
+}
+
+/****************************************************************************/
+/* Description: This function evaluates a string containing python code */
+/* and sets the result in the double value */
+/* Return 1 on success, 0 on failure */
+/****************************************************************************/
+int BPY_evalDouble(char *str, double *value)
+{
+ PyObject *retval, *floatval;
+ PyObject *m, *d, *mod;
+
+ /* default value */
+ *value = 0.0;
+
+ if (str == NULL || value == NULL)
+ return -1;
+
+ m = PyImport_AddModule("__main__");
+
+ if (m == NULL)
+ return EvalError();
+
+ d = PyModule_GetDict(m);
+
+ mod = PyImport_ImportModule("Blender");
+ if (mod) {
+ PyDict_SetItemString(d, "Blender", mod);
+ Py_DECREF(mod);
+ }
+
+ mod = PyImport_ImportModule("math");
+ if (mod) {
+ PyDict_SetItemString(d, "math", mod);
+ Py_DECREF(mod);
+ }
+
+ retval = PyRun_String(str, Py_eval_input, d, d);
+
+ if (retval == NULL)
+ return EvalError();
+
+ floatval = PyNumber_Float(retval);
+ Py_DECREF(retval);
+
+ if (floatval == NULL)
+ return EvalError();
+
+ *value = PyFloat_AsDouble(floatval);
+
+ Py_DECREF(floatval);
+ return 0;
+}
+
Index: source/blender/src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.205
diff -u -r1.205 interface.c
--- source/blender/src/interface.c 24 Sep 2005 16:02:56 -0000 1.205
+++ source/blender/src/interface.c 25 Sep 2005 15:07:47 -0000
@@ -89,6 +89,8 @@
#include "BIF_interface.h"
#include "BIF_butspace.h"
+#include "BPY_extern.h"
+
#include "BSE_view.h"
#include "mydevice.h"
@@ -1620,7 +1622,7 @@
min= but->min;
max= but->max;
but->min= 0.0;
- but->max= 15.0;
+ but->max= UI_MAX_DRAW_STR - 1;
temp= but->type;
but->type= TEX;
textleft= but->flag & UI_TEXT_LEFT;
@@ -1637,8 +1639,13 @@
but->max= max;
if(textleft==0) but->flag &= ~UI_TEXT_LEFT;
- if( but->pointype==FLO ) value= atof(str);
- else value= atoi(str);
+ if( str[0] == '#' ) {
+ if(BPY_evalDouble(str+1, &value)) /* str+1 to skip the # sign */
+ retval = 0; /* invalidate return value if eval failed */
+ }
+ else value = atof(str);
+
+ if( but->pointype!=FLO ) value= (int)value;
if(value<min) value= min;
if(value>max) value= max;
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
86/01/33f527d01ebc5dbfe50967d53784
Event Timeline
Log In to Comment