Page Menu
Home
Search
Configure Global Search
Log In
Files
F1227
updated_py_eval.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Willian Padovani Germano (ianwill)
Nov 13 2013, 12:55 PM
Size
6 KB
Subscribers
None
updated_py_eval.patch
View Options
? .updated_py_eval.patch.swp
? updated_py_eval.patch
? user-config.py
? source/blender/python/api2_2x/doc/BPY_API
? tools/Blender.pyc
? tools/__init__.pyc
? tools/bcolors.pyc
? tools/btools.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/blenkernel/BKE_bad_level_calls.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/BKE_bad_level_calls.h,v
retrieving revision 1.23
diff -u -p -r1.23 BKE_bad_level_calls.h
--- source/blender/blenkernel/BKE_bad_level_calls.h 30 Apr 2006 22:10:38 -0000 1.23
+++ source/blender/blenkernel/BKE_bad_level_calls.h 11 Jun 2006 23:26:04 -0000
@@ -71,6 +71,8 @@ void BPY_free_screen_spacehandlers (stru
struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver);
float BPY_pydriver_eval(struct IpoDriver *driver);
void BPY_pydriver_update(void);
+/* button python evaluation */
+int BPY_button_eval(char *expr, double *value);
/* writefile.c */
struct Oops;
Index: source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c,v
retrieving revision 1.48
diff -u -p -r1.48 stubs.c
--- source/blender/blenkernel/bad_level_call_stubs/stubs.c 28 May 2006 17:29:50 -0000 1.48
+++ source/blender/blenkernel/bad_level_call_stubs/stubs.c 11 Jun 2006 23:26:04 -0000
@@ -114,9 +114,12 @@ float BPY_pydriver_eval(struct IpoDriver
{
return 0;
}
-
/* depsgraph.c: */
struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver)
+{
+ return 0;
+}
+int BPY_button_eval(char *expr, double *value)
{
return 0;
}
Index: source/blender/python/BPY_extern.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/BPY_extern.h,v
retrieving revision 1.26
diff -u -p -r1.26 BPY_extern.h
--- source/blender/python/BPY_extern.h 30 Apr 2006 22:10:39 -0000 1.26
+++ source/blender/python/BPY_extern.h 11 Jun 2006 23:26:05 -0000
@@ -85,6 +85,8 @@ extern "C" {
float BPY_pydriver_eval(struct IpoDriver *driver);
struct Object **BPY_pydriver_get_objects(struct IpoDriver *driver);
+ int BPY_button_eval(char *expr, 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.86
diff -u -p -r1.86 BPY_interface.c
--- source/blender/python/BPY_interface.c 7 May 2006 08:23:50 -0000 1.86
+++ source/blender/python/BPY_interface.c 11 Jun 2006 23:26:06 -0000
@@ -1144,6 +1144,74 @@ float BPY_pydriver_eval(IpoDriver *drive
return result;
}
+/* Button Python Evaluation */
+
+/* This is Martin (theeth) Poirier's Python evaluation for gui buttons:
+ * users can write any valid Python expression (that evals to an int or float)
+ * inside Blender's gui number buttons and have them evaluated to their
+ * actual int or float value.
+ *
+ * The global dict used for pydrivers is also used here, so all imported
+ * modules for pydrivers (including the pydrivers.py Blender text) are
+ * available for button py eval, too. */
+
+static int bpy_button_eval_error(char *expr) {
+
+ if (bpy_pydriver_oblist)
+ bpy_pydriver_freeList();
+
+ if (bpy_pydriver_Dict) { /* free the persistent global dict */
+ /* it's the same dict used by pydrivers */
+ PyDict_Clear(bpy_pydriver_Dict);
+ Py_DECREF(bpy_pydriver_Dict);
+ bpy_pydriver_Dict = NULL;
+ }
+
+ fprintf(stderr, "\nError in button evaluation:\nThis is the failed Python expression:\n'%s'\n\n", expr);
+
+ PyErr_Print();
+
+ return -1;
+}
+
+int BPY_button_eval(char *expr, double *value)
+{
+ PyObject *retval, *floatval;
+
+ if (!value || !expr || expr[0]=='\0') return -1;
+
+ *value = 0.0; /* default value */
+
+ if (!bpy_pydriver_Dict) {
+ if (bpy_pydriver_create_dict() != 0) {
+ fprintf(stderr,
+ "Button Python Eval error: couldn't create Python dictionary");
+ return -1;
+ }
+ }
+
+ retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict,
+ bpy_pydriver_Dict);
+
+ if (retval == NULL) {
+ return bpy_button_eval_error(expr);
+ }
+ else {
+ floatval = PyNumber_Float(retval);
+ Py_DECREF(retval);
+ }
+
+ if (floatval == NULL)
+ return bpy_button_eval_error(expr);
+ else {
+ *value = (float)PyFloat_AsDouble(floatval);
+ Py_DECREF(floatval);
+ }
+
+ return 0; /* successful exit */
+}
+
+
/*****************************************************************************/
/* ScriptLinks */
/*****************************************************************************/
Index: source/blender/src/interface.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/interface.c,v
retrieving revision 1.232
diff -u -p -r1.232 interface.c
--- source/blender/src/interface.c 9 Jun 2006 16:01:27 -0000 1.232
+++ source/blender/src/interface.c 11 Jun 2006 23:26:10 -0000
@@ -99,6 +99,8 @@
#include "BSE_view.h"
+#include "BPY_extern.h" /* for BPY_button_eval */
+
#include "mydevice.h"
#include "interface.h"
#include "blendef.h"
@@ -2007,7 +2009,7 @@ static int ui_act_as_text_but(uiBut *but
min= but->min;
max= but->max;
but->min= 0.0;
- but->max= 15.0;
+ but->max= UI_MAX_DRAW_STR - 1; /* for py strings evaluation */
temp= but->type;
but->type= TEX;
textleft= but->flag & UI_TEXT_LEFT;
@@ -2024,8 +2026,14 @@ static int ui_act_as_text_but(uiBut *but
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_button_eval(str+1, &value)) /* str+1 to skip the # sign */
+ error("Invalid Python expression, check console");
+ 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
58/77/d845387d8e6b0a2fdbcf21e8d3bc
Event Timeline
Log In to Comment