Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-08-10 15:58:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-08-10 15:58:53 +0400
commit6c951fbb98a5ddb29240c3efc9af4304ab942396 (patch)
tree7eb917c4f8cb9196f1430cf034335d2d7ebaeb1e /source/blender/python
parent7084be920a0acb95e2db84bb7029a65bc7a76d9a (diff)
adding back button evaluation so you can do 1/60, 90*0.1 etc as well as dimension conversion 1km-10cm+4ft
Note... - Python3.1 you don't need to add the .0 for divisions anymore (was esp annoying for button eval) - Simple dimension input, imperial mi/yd/ft/in, metric km/m/cm/mm, Later could display these values and have a pref for scene scale, atm it assumes 1BU == 1m.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/BPY_extern.h2
-rw-r--r--source/blender/python/intern/bpy_interface.c62
2 files changed, 63 insertions, 1 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index db0404c33a8..acb45790ed2 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -122,7 +122,7 @@ extern "C" {
void BPY_pydriver_update(void);
float BPY_pydriver_eval(struct ChannelDriver *driver);
- int BPY_button_eval(char *expr, double *value);
+ int BPY_button_eval(struct bContext *C, char *expr, double *value);
/* format importer hook */
int BPY_call_importloader( char *name );
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index e37e75ab80d..8cd4cdd5dfc 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -804,3 +804,65 @@ float BPY_pydriver_eval (ChannelDriver *driver)
return result;
}
+
+int BPY_button_eval(bContext *C, char *expr, double *value)
+{
+ PyGILState_STATE gilstate;
+ PyObject *dict, *retval, *expr_conv;
+ int error_ret = 0;
+
+ if (!value || !expr || expr[0]=='\0') return -1;
+
+ bpy_context_set(C, &gilstate);
+
+ // experemental, fun. "button_convert.convert" is currently defined in bpy_ops.py
+ {
+ PyObject *mod= PyDict_GetItemString(PySys_GetObject("modules"), "button_convert");
+ if(mod && PyModule_Check(mod)) {
+ PyObject *mod_dict= PyModule_GetDict(mod);
+ PyObject *func= PyDict_GetItemString(mod_dict, "convert");
+ if(func) {
+ PyObject *expr_conv = PyObject_CallFunction(func, "s", expr);
+ if(expr_conv==NULL) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+ else {
+ expr= _PyUnicode_AsString(expr_conv); /* TODO, check */
+ }
+ }
+ }
+ }
+
+ dict= CreateGlobalDictionary(C);
+ retval = PyRun_String(expr, Py_eval_input, dict, dict);
+
+ if(expr_conv) {
+ Py_DECREF(expr_conv); /* invalidates expr */
+ }
+
+ if (retval == NULL) {
+ error_ret= -1;
+ }
+ else {
+ double val = PyFloat_AsDouble(retval);
+ Py_DECREF(retval);
+
+ if(val==-1 && PyErr_Occurred()) {
+ error_ret= -1;
+ }
+ else {
+ *value= val;
+ }
+ }
+
+ if(error_ret) {
+ BPy_errors_to_report(CTX_wm_reports(C));
+ }
+
+ Py_DECREF(dict);
+ bpy_context_clear(C, &gilstate);
+
+ return error_ret;
+}
+