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-02-28 16:27:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-02-28 16:27:45 +0300
commitbab4cd69913eee9aa30d61db7dc46e21655e4bde (patch)
treeebf28a1372c0db195928a1724b05f56d5c62d35e /source/blender/python/intern/bpy_util.c
parent0f8969640ccb5e7f615c85576e569ba23dd62c6f (diff)
Python experimental UI API
Can draw panels in the scripts space containing RNA and operator buttons. * Added bpyui.register() so scripts can draw buttons and panels into the scripts space type. * wrapped drawBlock, drawPanels and matchPanelsView2d * Operator buttons take a python dictionary used to set the button defaults. * BPY_getFileAndNum utility function to get the filename and line number python is currently running.
Diffstat (limited to 'source/blender/python/intern/bpy_util.c')
-rw-r--r--source/blender/python/intern/bpy_util.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c
index 63112295d18..31d15d8a69e 100644
--- a/source/blender/python/intern/bpy_util.c
+++ b/source/blender/python/intern/bpy_util.c
@@ -161,3 +161,43 @@ void PyObSpit(char *name, PyObject *var) {
}
fprintf(stderr, "\n");
}
+
+void BPY_getFileAndNum(char **filename, int *lineno)
+{
+ PyObject *getframe, *frame;
+ PyObject *f_lineno, *f_code, *co_filename;
+
+ if (filename) *filename= NULL;
+ if (lineno) *lineno = -1;
+
+ getframe = PySys_GetObject("_getframe"); // borrowed
+ if (getframe) {
+ frame = PyObject_CallObject(getframe, NULL);
+ if (frame) {
+ f_lineno= PyObject_GetAttrString(frame, "f_lineno");
+ f_code= PyObject_GetAttrString(frame, "f_code");
+ if (f_lineno && f_code) {
+ co_filename= PyObject_GetAttrString(f_code, "co_filename");
+ if (co_filename) {
+
+ if (filename) *filename = _PyUnicode_AsString(co_filename);
+ if (lineno) *lineno = (int)PyLong_AsSsize_t(f_lineno);
+
+ Py_DECREF(f_lineno);
+ Py_DECREF(f_code);
+ Py_DECREF(co_filename);
+ Py_DECREF(frame);
+
+ return;
+ }
+ }
+ }
+ }
+
+ Py_XDECREF(co_filename);
+ Py_XDECREF(f_lineno);
+ Py_XDECREF(f_code);
+ Py_XDECREF(frame);
+
+ PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_code.co_filename");
+}