[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19227] branches/bmesh/blender/source/ blender/python: ok anoter compile fix
Joseph Eagar
joeedh at gmail.com
Sun Mar 8 17:55:08 CET 2009
Revision: 19227
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19227
Author: joeedh
Date: 2009-03-08 17:55:06 +0100 (Sun, 08 Mar 2009)
Log Message:
-----------
ok anoter compile fix
Modified Paths:
--------------
branches/bmesh/blender/source/blender/python/BPY_extern.h
branches/bmesh/blender/source/blender/python/epy_doc_gen.py
branches/bmesh/blender/source/blender/python/intern/bpy_compat.h
branches/bmesh/blender/source/blender/python/intern/bpy_interface.c
branches/bmesh/blender/source/blender/python/intern/bpy_operator.c
branches/bmesh/blender/source/blender/python/intern/bpy_operator.h
branches/bmesh/blender/source/blender/python/intern/bpy_rna.c
branches/bmesh/blender/source/blender/python/intern/bpy_ui.c
branches/bmesh/blender/source/blender/python/intern/bpy_util.c
branches/bmesh/blender/source/blender/python/intern/bpy_util.h
branches/bmesh/blender/source/blender/python/intern/stubs.c
Modified: branches/bmesh/blender/source/blender/python/BPY_extern.h
===================================================================
--- branches/bmesh/blender/source/blender/python/BPY_extern.h 2009-03-08 16:50:11 UTC (rev 19226)
+++ branches/bmesh/blender/source/blender/python/BPY_extern.h 2009-03-08 16:55:06 UTC (rev 19227)
@@ -95,7 +95,14 @@
int BPY_menu_do_python( short menutype, int event );
int BPY_menu_do_shortcut( short menutype, unsigned short key, unsigned short modifiers );
int BPY_menu_invoke( struct BPyMenu *pym, short menutype );
- void BPY_run_python_script( struct bContext *C, const char *filename );
+
+ /* 2.5 UI Scripts */
+ int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text ); // 2.5 working
+ int BPY_run_script_space_draw(struct bContext *C, struct SpaceScript * sc); // 2.5 working
+// int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working
+
+
+
int BPY_run_script(struct Script *script);
void BPY_free_compiled_text( struct Text *text );
Modified: branches/bmesh/blender/source/blender/python/epy_doc_gen.py
===================================================================
--- branches/bmesh/blender/source/blender/python/epy_doc_gen.py 2009-03-08 16:50:11 UTC (rev 19226)
+++ branches/bmesh/blender/source/blender/python/epy_doc_gen.py 2009-03-08 16:55:06 UTC (rev 19227)
@@ -121,7 +121,14 @@
try: return rna_struct.base.identifier
except: return '' # invalid id
- structs = [(base_id(rna_struct), rna_struct.identifier, rna_struct) for rna_struct in bpydoc.structs.values()]
+ #structs = [(base_id(rna_struct), rna_struct.identifier, rna_struct) for rna_struct in bpydoc.structs.values()]
+
+ structs = []
+ for rna_struct in bpydoc.structs.values():
+ structs.append( (base_id(rna_struct), rna_struct.identifier, rna_struct) )
+
+
+
structs.sort() # not needed but speeds up sort below, setting items without an inheritance first
# Arrange so classes are always defined in the correct order
@@ -173,12 +180,13 @@
operators = dir(bpyoperator)
operators.remove('add')
operators.remove('remove')
- operators.remove('__dir__')
operators.sort()
for op in operators:
+ if op.startswith('__'):
+ continue
# Keyword attributes
kw_args = [] # "foo = 1", "bar=0.5", "spam='ENUM'"
Modified: branches/bmesh/blender/source/blender/python/intern/bpy_compat.h
===================================================================
--- branches/bmesh/blender/source/blender/python/intern/bpy_compat.h 2009-03-08 16:50:11 UTC (rev 19226)
+++ branches/bmesh/blender/source/blender/python/intern/bpy_compat.h 2009-03-08 16:55:06 UTC (rev 19227)
@@ -80,5 +80,8 @@
PyObject *Py_CmpToRich(int op, int cmp);
#endif
+#ifndef Py_CmpToRich
+PyObject *Py_CmpToRich(int op, int cmp); /* bpy_util.c */
+#endif
#endif /* BPY_COMPAT_H__ */
Modified: branches/bmesh/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- branches/bmesh/blender/source/blender/python/intern/bpy_interface.c 2009-03-08 16:50:11 UTC (rev 19226)
+++ branches/bmesh/blender/source/blender/python/intern/bpy_interface.c 2009-03-08 16:55:06 UTC (rev 19227)
@@ -12,8 +12,22 @@
#include "bpy_rna.h"
#include "bpy_operator.h"
+#include "bpy_ui.h"
+#include "DNA_space_types.h"
+#include "BKE_text.h"
+#include "DNA_text_types.h"
+#include "MEM_guardedalloc.h"
+
+void BPY_free_compiled_text( struct Text *text )
+{
+ if( text->compiled ) {
+ Py_DECREF( ( PyObject * ) text->compiled );
+ text->compiled = NULL;
+ }
+}
+
/*****************************************************************************
* Description: This function creates a new Python dictionary object.
*****************************************************************************/
@@ -81,29 +95,182 @@
return;
}
-void BPY_run_python_script( bContext *C, const char *fn )
+/* Can run a file or text block */
+int BPY_run_python_script( bContext *C, const char *fn, struct Text *text )
{
PyObject *py_dict, *py_result;
- char pystring[512];
PyGILState_STATE gilstate;
-
- /* TODO - look into a better way to run a file */
- sprintf(pystring, "exec(open(r'%s').read())", fn);
+ if (fn==NULL && text==NULL) {
+ return 0;
+ }
+
//BPY_start_python();
gilstate = PyGILState_Ensure();
+
+ py_dict = CreateGlobalDictionary(C);
+
+ if (text) {
+
+ if( !text->compiled ) { /* if it wasn't already compiled, do it now */
+ char *buf = txt_to_buf( text );
+
+ text->compiled =
+ Py_CompileString( buf, text->id.name+2, Py_file_input );
+
+ MEM_freeN( buf );
+
+ if( PyErr_Occurred( ) ) {
+ BPY_free_compiled_text( text );
+ return NULL;
+ }
+ }
+ py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
+
+ } else {
+ char pystring[512];
+ /* TODO - look into a better way to run a file */
+ sprintf(pystring, "exec(open(r'%s').read())", fn);
+ py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
+ }
+ if (!py_result) {
+ PyErr_Print();
+ } else {
+ Py_DECREF( py_result );
+ }
+ PyGILState_Release(gilstate);
+
+ //BPY_end_python();
+ return py_result ? 1:0;
+}
+
+
+/* TODO - move into bpy_space.c ? */
+/* GUI interface routines */
+
+/* Copied from Draw.c */
+static void exit_pydraw( SpaceScript * sc, short err )
+{
+ Script *script = NULL;
+
+ if( !sc || !sc->script )
+ return;
+
+ script = sc->script;
+
+ if( err ) {
+ PyErr_Print( );
+ script->flags = 0; /* mark script struct for deletion */
+ SCRIPT_SET_NULL(script);
+ script->scriptname[0] = '\0';
+ script->scriptarg[0] = '\0';
+// XXX 2.5 error_pyscript();
+// XXX 2.5 scrarea_queue_redraw( sc->area );
+ }
+
+#if 0 // XXX 2.5
+ BPy_Set_DrawButtonsList(sc->but_refs);
+ BPy_Free_DrawButtonsList(); /*clear all temp button references*/
+#endif
+
+ sc->but_refs = NULL;
+
+ Py_XDECREF( ( PyObject * ) script->py_draw );
+ Py_XDECREF( ( PyObject * ) script->py_event );
+ Py_XDECREF( ( PyObject * ) script->py_button );
+
+ script->py_draw = script->py_event = script->py_button = NULL;
+}
+
+static int bpy_run_script_init(bContext *C, SpaceScript * sc)
+{
+ if (sc->script==NULL)
+ return 0;
+
+ if (sc->script->py_draw==NULL && sc->script->scriptname[0] != '\0')
+ BPY_run_python_script(C, sc->script->scriptname, NULL);
+
+ if (sc->script->py_draw==NULL)
+ return 0;
+
+ return 1;
+}
+
+int BPY_run_script_space_draw(bContext *C, SpaceScript * sc)
+{
+ if (bpy_run_script_init(C, sc)) {
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ PyObject *result = PyObject_CallObject( sc->script->py_draw, NULL );
+
+ if (result==NULL)
+ exit_pydraw(sc, 1);
+
+ PyGILState_Release(gilstate);
+ }
+ return 1;
+}
+
+// XXX - not used yet, listeners dont get a context
+int BPY_run_script_space_listener(bContext *C, SpaceScript * sc)
+{
+ if (bpy_run_script_init(C, sc)) {
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ PyObject *result = PyObject_CallObject( sc->script->py_draw, NULL );
+
+ if (result==NULL)
+ exit_pydraw(sc, 1);
+
+ PyGILState_Release(gilstate);
+ }
+ return 1;
+}
+
+#if 0
+/* called from the the scripts window, assume context is ok */
+int BPY_run_python_script_space(const char *modulename, const char *func)
+{
+ PyObject *py_dict, *py_result= NULL;
+ char pystring[512];
+ PyGILState_STATE gilstate;
+
+ /* for calling the module function */
+ PyObject *py_func,
+
+ gilstate = PyGILState_Ensure();
+
py_dict = CreateGlobalDictionary(C);
- py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
+ PyObject *module = PyImport_ImportModule(scpt->script.filename);
+ if (module==NULL) {
+ PyErr_SetFormat(PyExc_SystemError, "could not import '%s'", scpt->script.filename);
+ }
+ else {
+ py_func = PyObject_GetAttrString(modulename, func);
+ if (py_func==NULL) {
+ PyErr_SetFormat(PyExc_SystemError, "module has no function '%s.%s'\n", scpt->script.filename, func);
+ }
+ else {
+ if (!PyCallable_Check(py_func)) {
+ PyErr_SetFormat(PyExc_SystemError, "module item is not callable '%s.%s'\n", scpt->script.filename, func);
+ }
+ else {
+ py_result= PyObject_CallObject(py_func, NULL); // XXX will need args eventually
+ }
+ }
+ }
if (!py_result)
PyErr_Print();
else
Py_DECREF( py_result );
+ Py_XDECREF(module);
+
+
PyGILState_Release(gilstate);
-
- //BPY_end_python();
+ return 1;
}
+#endif
Modified: branches/bmesh/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- branches/bmesh/blender/source/blender/python/intern/bpy_operator.c 2009-03-08 16:50:11 UTC (rev 19226)
+++ branches/bmesh/blender/source/blender/python/intern/bpy_operator.c 2009-03-08 16:55:06 UTC (rev 19227)
@@ -115,6 +115,18 @@
return (strcmp(a->name, b->name)==0) ? 0 : -1;
}
+/* For some reason python3 needs these :/ */
+static PyObject *pyop_func_richcmp(BPy_OperatorFunc * a, BPy_OperatorFunc * b, int op)
+{
+ int cmp_result= -1; /* assume false */
+ if (BPy_OperatorFunc_Check(a) && BPy_OperatorFunc_Check(b)) {
+ cmp_result= pyop_func_compare(a, b);
+ }
+
+ return Py_CmpToRich(op, cmp_result);
+}
+
+
/*----------------------repr--------------------------------------------*/
static PyObject *pyop_base_repr( BPy_OperatorBase * self )
{
@@ -126,6 +138,11 @@
return PyUnicode_FromFormat( "[BPy_OperatorFunc \"%s\"]", self->name);
}
+static struct PyMethodDef pyop_base_methods[] = {
+ {"add", (PyCFunction)PYOP_wrap_add, METH_VARARGS, ""},
+ {"remove", (PyCFunction)PYOP_wrap_remove, METH_VARARGS, ""},
+ {NULL, NULL, 0, NULL}
+};
//---------------getattr--------------------------------------------
static PyObject *pyop_base_getattro( BPy_OperatorBase * self, PyObject *pyname )
@@ -133,10 +150,22 @@
char *name = _PyUnicode_AsString(pyname);
PyObject *ret;
wmOperatorType *ot;
-
+ PyMethodDef *meth;
+
if ((ot = WM_operatortype_find(name))) {
ret= pyop_func_CreatePyObject(self->C, name);
}
+ else if (strcmp(name, "__dict__")==0) {
+ ret = PyDict_New();
+
+ for(ot= WM_operatortype_first(); ot; ot= ot->next) {
+ PyDict_SetItemString(ret, ot->idname, Py_None);
+ }
+
+ for(meth=pyop_base_methods; meth->ml_name; meth++) {
+ PyDict_SetItemString(ret, meth->ml_name, Py_None);
+ }
+ }
else if ((ret = PyObject_GenericGetAttr((PyObject *)self, pyname))) {
/* do nothing, this accounts for methoddef's add and remove */
}
@@ -144,7 +173,7 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list