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:
authorWillian Padovani Germano <wpgermano@gmail.com>2003-12-14 04:18:09 +0300
committerWillian Padovani Germano <wpgermano@gmail.com>2003-12-14 04:18:09 +0300
commit49021f7ec4bfc1313c6cdfeae1f9c32e98cc9cdc (patch)
tree44e7c4c38bc8c26b5efe0b52b846402589a4ca9a /source/blender/python/api2_2x
parent6653af79142aa929eb3d131f8fced363b2c4b828 (diff)
BPython - first step for better integration of Python in Blender:
- add a new space: Space Script - add a new dna struct: Script - add these two properly everywhere they are meant to It's not a tiny commit, but most of it is ground work for what is still to be done. Right now the benefits should be: freeing the Text Editor to be used in a window even while a script w/ gui in "on" and letting more than one currently running script w/ gui be accessible from each window Some files are added, so some build systems (not autotools) will need updates
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r--source/blender/python/api2_2x/Draw.c1298
-rw-r--r--source/blender/python/api2_2x/Draw.h18
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.c45
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.h3
-rw-r--r--source/blender/python/api2_2x/Sys.c24
-rw-r--r--source/blender/python/api2_2x/Window.c310
-rw-r--r--source/blender/python/api2_2x/gen_utils.c27
-rw-r--r--source/blender/python/api2_2x/gen_utils.h4
8 files changed, 934 insertions, 795 deletions
diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c
index 3a824aa9f6b..5a743a43b7e 100644
--- a/source/blender/python/api2_2x/Draw.c
+++ b/source/blender/python/api2_2x/Draw.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
@@ -31,7 +31,7 @@
/* This file is the Blender.Draw part of opy_draw.c, from the old
* bpython/intern dir, with minor changes to adapt it to the new Python
- * implementation. Non-trivial original comments are marked with an
+ * implementation. Non-trivial original comments are marked with an
* @ symbol at their beginning. */
#include "Draw.h"
@@ -42,792 +42,834 @@ extern short EXPP_releaseGlobalDict;
static void Button_dealloc(PyObject *self)
{
- Button *but = (Button*)self;
+ Button *but = (Button*)self;
- if(but->type == 3) MEM_freeN (but->val.asstr);
-
- PyObject_DEL (self);
+ if(but->type == 3) MEM_freeN (but->val.asstr);
+
+ PyObject_DEL (self);
}
static PyObject *Button_getattr(PyObject *self, char *name)
{
- Button *but = (Button*)self;
-
- if(strcmp(name, "val") == 0) {
- if (but->type==1)
- return Py_BuildValue("i", but->val.asint);
- else if (but->type==2)
- return Py_BuildValue("f", but->val.asfloat);
- else if (but->type==3)
- return Py_BuildValue("s", but->val.asstr);
- }
-
- PyErr_SetString(PyExc_AttributeError, name);
- return NULL;
+ Button *but = (Button*)self;
+
+ if(strcmp(name, "val") == 0) {
+ if (but->type==1)
+ return Py_BuildValue("i", but->val.asint);
+ else if (but->type==2)
+ return Py_BuildValue("f", but->val.asfloat);
+ else if (but->type==3)
+ return Py_BuildValue("s", but->val.asstr);
+ }
+
+ PyErr_SetString(PyExc_AttributeError, name);
+ return NULL;
}
static int Button_setattr(PyObject *self, char *name, PyObject *v)
{
- Button *but= (Button*) self;
-
- if(strcmp(name, "val") == 0) {
- if (but->type==1)
- PyArg_Parse(v, "i", &but->val.asint);
- else if (but->type==2)
- PyArg_Parse(v, "f", &but->val.asfloat);
- else if (but->type==3) {
- char *newstr;
-
- PyArg_Parse(v, "s", &newstr);
- strncpy(but->val.asstr, newstr, but->slen);
- }
- } else {
- PyErr_SetString(PyExc_AttributeError, name);
- return -1;
- }
-
- return 0;
+ Button *but= (Button*) self;
+
+ if(strcmp(name, "val") == 0) {
+ if (but->type==1)
+ PyArg_Parse(v, "i", &but->val.asint);
+ else if (but->type==2)
+ PyArg_Parse(v, "f", &but->val.asfloat);
+ else if (but->type==3) {
+ char *newstr;
+
+ PyArg_Parse(v, "s", &newstr);
+ strncpy(but->val.asstr, newstr, but->slen);
+ }
+ } else {
+ PyErr_SetString(PyExc_AttributeError, name);
+ return -1;
+ }
+
+ return 0;
}
static PyObject *Button_repr(PyObject *self)
{
- return PyObject_Repr(Button_getattr(self, "val"));
+ return PyObject_Repr(Button_getattr(self, "val"));
}
static Button *newbutton (void)
{
- Button *but= (Button *) PyObject_NEW(Button, &Button_Type);
-
- return but;
+ Button *but= (Button *) PyObject_NEW(Button, &Button_Type);
+
+ return but;
}
/* GUI interface routines */
-static void exit_pydraw(SpaceText *st)
+static void exit_pydraw(SpaceScript *sc, short error)
{
- scrarea_queue_redraw(st->area);
-
- if (st) {
- Py_XDECREF((PyObject *) st->py_draw);
- Py_XDECREF((PyObject *) st->py_event);
- Py_XDECREF((PyObject *) st->py_button);
-
- st->py_draw= st->py_event= st->py_button= NULL;
- }
-}
+ Script *script = NULL;
-static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args)
-{
- PyObject *result = PyObject_CallObject (callback, args);
+ if (!sc || !sc->script) return;
+
+ script = sc->script;
+
+ if (error) {
+ PyErr_Print();
+ scrarea_queue_redraw(sc->area);
+ }
- if (result == NULL) {
- st->text->compiled = NULL;
- PyErr_Print ();
- exit_pydraw (st);
- }
+ Py_XDECREF((PyObject *) script->py_draw);
+ Py_XDECREF((PyObject *) script->py_event);
+ Py_XDECREF((PyObject *) script->py_button);
- Py_XDECREF (result);
- Py_DECREF (args);
+ script->py_draw = script->py_event = script->py_button = NULL;
+}
+
+static void exec_callback(SpaceScript *sc, PyObject *callback, PyObject *args)
+{
+ PyObject *result = PyObject_CallObject (callback, args);
+
+ if (result == NULL && sc->script) { /* errors in the script */
+ if (sc->script->filename == NULL) { /* if it's a Blender Text script */
+ Text *text = G.main->text.first;
+ while (text) { /* find it and free its compiled code */
+ if (!strcmp(text->id.name+2, sc->script->id.name+2))
+ BPY_free_compiled_text(text);
+ }
+ text = text->id.next;
+ }
+ exit_pydraw(sc, 1);
+ }
+
+ Py_XDECREF (result);
+ Py_DECREF (args);
}
-/* BPY_spacetext_do_pywin_draw, the static spacetext_do_pywin_buttons and
- * BPY_spacetext_do_pywin_event are the three functions responsible for
+/* BPY_spacescript_do_pywin_draw, the static spacescript_do_pywin_buttons and
+ * BPY_spacescript_do_pywin_event are the three functions responsible for
* calling the draw, buttons and event callbacks registered with Draw.Register
* (see Method_Register below). They are called (only the two BPY_ ones)
- * from blender/src/drawtext.c */
+ * from blender/src/drawscript.c */
-void BPY_spacetext_do_pywin_draw(SpaceText *st)
+void BPY_spacescript_do_pywin_draw(SpaceScript *sc)
{
- uiBlock *block;
- char butblock[20];
-
- sprintf(butblock, "win %d", curarea->win);
- block= uiNewBlock(&curarea->uiblocks, butblock, UI_EMBOSSX,
- UI_HELV, curarea->win);
-
- if (st->py_draw) {
- glPushAttrib(GL_ALL_ATTRIB_BITS);
- exec_callback(st, st->py_draw, Py_BuildValue("()"));
- glPopAttrib();
- } else {
- glClearColor(0.4375, 0.4375, 0.4375, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- }
-
- uiDrawBlock(block);
-
- curarea->win_swap= WIN_BACK_OK;
+ uiBlock *block;
+ char butblock[20];
+ Script *script = sc->script;
+
+ sprintf(butblock, "win %d", curarea->win);
+ block = uiNewBlock(&curarea->uiblocks, butblock, UI_EMBOSSX,
+ UI_HELV, curarea->win);
+
+ if (script->py_draw) {
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
+ exec_callback(sc, script->py_draw, Py_BuildValue("()"));
+ glPopAttrib();
+ } else {
+ glClearColor(0.4375, 0.4375, 0.4375, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+
+ uiDrawBlock(block);
+
+ curarea->win_swap = WIN_BACK_OK;
}
-static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event)
+static void spacescript_do_pywin_buttons(SpaceScript *sc, unsigned short event)
{
- if (st->py_button) {
- exec_callback(st, st->py_button, Py_BuildValue("(i)", event));
- }
+ if (sc->script->py_button) {
+ exec_callback(sc, sc->script->py_button, Py_BuildValue("(i)", event));
+ }
}
-void BPY_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val)
+void BPY_spacescript_do_pywin_event(SpaceScript *sc, unsigned short event, short val)
{
- if (event == QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) {
- exit_pydraw(st);
- return;
- }
-
- if (val) {
- if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
-
- if (event==UI_BUT_EVENT)
- spacetext_do_pywin_buttons(st, val);
- }
-
- if (st->py_event)
- exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val));
-}
+ if (event == QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY)) {
+ /* finish script: user pressed ALT+Q or CONTROL+Q */
+ Script *script = sc->script;
-int BPY_spacetext_is_pywin(SpaceText *st)
-{
- return (st->py_draw || st->py_event || st->py_button);
-}
+ exit_pydraw(sc, 0);
+
+ script->flags &=~SCRIPT_GUI; /* we're done with this script */
-/* the define CLEAR_NAMESPACE is currently ignored. It should be
- * substituted by a better method, that was also the intention of the
- * programmer(s) who put it there. */
+ return;
+ }
+
+ if (val) {
+ if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event = 0;
+
+ if (event == UI_BUT_EVENT)
+ spacescript_do_pywin_buttons(sc, val);
+ }
+
+ if (sc->script->py_event)
+ exec_callback(sc, sc->script->py_event, Py_BuildValue("(ii)", event, val));
+}
static PyObject *Method_Exit (PyObject *self, PyObject *args)
{
- SpaceText *st= curarea->spacedata.first;
+ SpaceScript *sc;
+ Script *script;
+
+/* if users call Draw.Exit when we are already out of the SPACE_SCRIPT, we
+ * simply return, for compatibility */
+ if (curarea->spacetype == SPACE_SCRIPT) sc = curarea->spacedata.first;
+ else return EXPP_incr_ret (Py_None);
- if (!PyArg_ParseTuple(args, ""))
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected empty argument list");
+ if (!PyArg_ParseTuple(args, ""))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "expected empty argument list");
- exit_pydraw(st);
+ exit_pydraw(sc, 0);
- if (EXPP_releaseGlobalDict) {
- PyObject *d = st->py_globaldict;
- /* d is the current window's global namespace dictionary */
- if (d) {
- PyDict_Clear(d);
- Py_DECREF(d); /* release dictionary */
- }
- }
+ script = sc->script;
- return EXPP_incr_ret (Py_None);
+/* remove our lock to the current namespace */
+ script->flags &=~SCRIPT_GUI;
+
+ return EXPP_incr_ret (Py_None);
}
+/* Method_Register (Draw.Register) registers callbacks for drawing, events
+ * and gui button events, so a script can continue executing after the
+ * interpreter reached its end and returned control to Blender. Everytime
+ * the SPACE_SCRIPT window with this script is redrawn, the registered
+ * callbacks are executed and deleted (a new call to Register re-inserts them
+ * or new ones).*/
static PyObject *Method_Register (PyObject *self, PyObject *args)
{
- PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL;
- SpaceText *st= curarea->spacedata.first;
-
- if (!PyArg_ParseTuple(args, "O|OO", &newdrawc,
- &neweventc, &newbuttonc))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected one or three PyObjects");
+ PyObject *newdrawc = NULL, *neweventc = NULL, *newbuttonc = NULL;
+ SpaceScript *sc;
+ Script *script;
+ int startspace = 0;
+
+ if (!PyArg_ParseTuple(args, "O|OO", &newdrawc, &neweventc, &newbuttonc))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected one or three PyObjects");
+
+ if (!PyCallable_Check(newdrawc)) newdrawc = NULL;
+ if (!PyCallable_Check(neweventc)) neweventc = NULL;
+ if (!PyCallable_Check(newbuttonc)) newbuttonc = NULL;
+
+ if (!(newdrawc || neweventc || newbuttonc))
+ return EXPP_incr_ret(Py_None);
+
+ startspace = curarea->spacetype;
- /*@This is a hack again:
- * Every python script should actually do a global variable cleanup at
- * the end of execution.
- * For scripts registering GUI callbacks, this does not work, because
- * the global namespace of the interpreter still needs to be accessed
- * from the callback.
- * Workaround: a text object has a flag which allows the global name
- * space to be cleared at the end of the script. This flag should be
- * normally set when executed with Alt-P. For a script registering with
- * the GUI though, clear the flag and set it when the GUI mode is left
- * (Method_Exit).
- */
+/* first make sure the current area is of type SPACE_SCRIPT */
+ if (startspace != SPACE_SCRIPT) newspace (curarea, SPACE_SCRIPT);
-/* EXPP_debug(("--- disable clear namespace")); */
+ sc = curarea->spacedata.first;
- st->flags &= ~ST_CLEAR_NAMESPACE;
+/* this is a little confusing: we need to know which script is being executed
+ * now, so we can preserve its namespace from being deleted.
+ * There are two possibilities:
+ * a) One new script was created and the interpreter still hasn't returned
+ * from executing it.
+ * b) Any number of scripts were executed but left registered callbacks and
+ * so were not deleted yet. */
+/* To find out if we're dealing with a) or b), we start with the last
+ * created one: */
+ script = G.main->script.last;
- if (!PyCallable_Check(newdrawc)) newdrawc = NULL;
- if (!PyCallable_Check(neweventc)) neweventc = NULL;
- if (!PyCallable_Check(newbuttonc)) newbuttonc = NULL;
+ if (!script) {
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "Draw.Register: couldn't get pointer to script struct");
+ }
- if (!(newdrawc || neweventc || newbuttonc))
- return EXPP_incr_ret(Py_None);
+/* if the flag SCRIPT_RUNNING is set, this script is case a): */
+ if (!(script->flags & SCRIPT_RUNNING)) {
+ script = sc->script;
+ }
+/* otherwise it's case b) and the script we want is here: */
+ else sc->script = script;
- exit_pydraw(st);
+/* Now we have the right script and can set a lock so its namespace can't be
+ * deleted for as long as we need it */
+ script->flags |= SCRIPT_GUI;
- Py_XINCREF(newdrawc);
- Py_XINCREF(neweventc);
- Py_XINCREF(newbuttonc);
+/* save the last space so we can go back to it upon finishing */
+ if (!script->lastspace) script->lastspace = startspace;
- st->py_draw= newdrawc;
- st->py_event= neweventc;
- st->py_button= newbuttonc;
+/* clean the old callbacks */
+ exit_pydraw(sc, 0);
- scrarea_queue_redraw(st->area);
+/* prepare the new ones and insert them */
+ Py_XINCREF(newdrawc);
+ Py_XINCREF(neweventc);
+ Py_XINCREF(newbuttonc);
- return EXPP_incr_ret (Py_None);
+ script->py_draw = newdrawc;
+ script->py_event = neweventc;
+ script->py_button = newbuttonc;
+
+ scrarea_queue_redraw(sc->area);
+
+ return EXPP_incr_ret (Py_None);
}
static PyObject *Method_Redraw (PyObject *self, PyObject *args)
{
- int after= 0;
-
- if (!PyArg_ParseTuple(args, "|i", &after))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected int argument (or nothing)");
-
- if (after) addafterqueue(curarea->win, REDRAW, 1);
- else scrarea_queue_winredraw(curarea);
-
- return EXPP_incr_ret(Py_None);
+ int after= 0;
+
+ if (!PyArg_ParseTuple(args, "|i", &after))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected int argument (or nothing)");
+
+ /* XXX shouldn't we redraw all spacescript wins with this script on ?*/
+ if (after) addafterqueue(curarea->win, REDRAW, 1);
+ else scrarea_queue_winredraw(curarea);
+
+ return EXPP_incr_ret(Py_None);
}
static PyObject *Method_Draw (PyObject *self, PyObject *args)
{
- /*@ If forced drawing is disable queue a redraw event instead */
- if (EXPP_disable_force_draw) {
- scrarea_queue_winredraw(curarea);
- return EXPP_incr_ret (Py_None);
- }
+ /*@ If forced drawing is disable queue a redraw event instead */
+ if (EXPP_disable_force_draw) {
+ scrarea_queue_winredraw(curarea);
+ return EXPP_incr_ret (Py_None);
+ }
- if (!PyArg_ParseTuple(args, ""))
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected empty argument list");
+ if (!PyArg_ParseTuple(args, ""))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "expected empty argument list");
- scrarea_do_windraw(curarea);
+ scrarea_do_windraw(curarea);
- screen_swapbuffers();
+ screen_swapbuffers();
- return EXPP_incr_ret (Py_None);
+ return EXPP_incr_ret (Py_None);
}
static PyObject *Method_Create (PyObject *self, PyObject *args)
{
- Button *but;
- PyObject *in;
-
- if (!PyArg_ParseTuple(args, "O", &in))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected PyObject argument");
-
- but= newbutton();
- if(PyFloat_Check(in)) {
- but->type= 2;
- but->val.asfloat= PyFloat_AsDouble(in);
- } else if (PyInt_Check(in)) {
- but->type= 1;
- but->val.asint= PyInt_AsLong(in);
- } else if (PyString_Check(in)) {
- char *newstr= PyString_AsString(in);
-
- but->type= 3;
- but->slen= strlen(newstr);
- but->val.asstr= MEM_mallocN(but->slen+1, "button string");
-
- strcpy(but->val.asstr, newstr);
- }
-
- return (PyObject *) but;
+ Button *but;
+ PyObject *in;
+
+ if (!PyArg_ParseTuple(args, "O", &in))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected PyObject argument");
+
+ but= newbutton();
+ if(PyFloat_Check(in)) {
+ but->type= 2;
+ but->val.asfloat= PyFloat_AsDouble(in);
+ } else if (PyInt_Check(in)) {
+ but->type= 1;
+ but->val.asint= PyInt_AsLong(in);
+ } else if (PyString_Check(in)) {
+ char *newstr= PyString_AsString(in);
+
+ but->type= 3;
+ but->slen= strlen(newstr);
+ but->val.asstr= MEM_mallocN(but->slen+1, "button string");
+
+ strcpy(but->val.asstr, newstr);
+ }
+
+ return (PyObject *) but;
}
static uiBlock *Get_uiBlock(void)
{
- char butblock[32];
-
- sprintf(butblock, "win %d", curarea->win);
+ char butblock[32];
+
+ sprintf(butblock, "win %d", curarea->win);
- return uiGetBlock(butblock, curarea);
+ return uiGetBlock(butblock, curarea);
}
static PyObject *Method_Button (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL;
- int event;
- int x, y, w, h;
-
- if (!PyArg_ParseTuple(args, "siiiii|s", &name, &event,
- &x, &y, &w, &h, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, five ints and optionally another string as arguments");
-
- block= Get_uiBlock();
-
- if(block) uiDefBut(block, BUT, event, name, x, y, w, h,
- 0, 0, 0, 0, 0, tip);
-
- return EXPP_incr_ret(Py_None);
+ uiBlock *block;
+ char *name, *tip= NULL;
+ int event;
+ int x, y, w, h;
+
+ if (!PyArg_ParseTuple(args, "siiiii|s", &name, &event,
+ &x, &y, &w, &h, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, five ints and optionally another string as arguments");
+
+ block= Get_uiBlock();
+
+ if(block) uiDefBut(block, BUT, event, name, x, y, w, h,
+ 0, 0, 0, 0, 0, tip);
+
+ return EXPP_incr_ret(Py_None);
}
static PyObject *Method_Menu (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL;
- int event, def;
- int x, y, w, h;
- Button *but;
-
- if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
- &x, &y, &w, &h, &def, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, six ints and optionally another string as arguments");
-
- but= newbutton();
- but->type= 1;
- but->val.asint= def;
-
- block= Get_uiBlock();
- if(block) uiDefButI(block, MENU, event, name, x, y, w, h,
- &but->val.asint, 0, 0, 0, 0, tip);
-
- return (PyObject *) but;
+ uiBlock *block;
+ char *name, *tip= NULL;
+ int event, def;
+ int x, y, w, h;
+ Button *but;
+
+ if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
+ &x, &y, &w, &h, &def, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, six ints and optionally another string as arguments");
+
+ but= newbutton();
+ but->type= 1;
+ but->val.asint= def;
+
+ block= Get_uiBlock();
+ if(block) uiDefButI(block, MENU, event, name, x, y, w, h,
+ &but->val.asint, 0, 0, 0, 0, tip);
+
+ return (PyObject *) but;
}
static PyObject *Method_Toggle (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL;
- int event;
- int x, y, w, h, def;
- Button *but;
-
- if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
- &x, &y, &w, &h, &def, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, six ints and optionally another string as arguments");
-
- but= newbutton();
- but->type= 1;
- but->val.asint= def;
-
- block= Get_uiBlock();
- if(block) uiDefButI(block, TOG, event, name, x, y, w, h,
- &but->val.asint, 0, 0, 0, 0, tip);
-
- return (PyObject *) but;
+ uiBlock *block;
+ char *name, *tip= NULL;
+ int event;
+ int x, y, w, h, def;
+ Button *but;
+
+ if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
+ &x, &y, &w, &h, &def, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, six ints and optionally another string as arguments");
+
+ but= newbutton();
+ but->type= 1;
+ but->val.asint= def;
+
+ block= Get_uiBlock();
+ if(block) uiDefButI(block, TOG, event, name, x, y, w, h,
+ &but->val.asint, 0, 0, 0, 0, tip);
+
+ return (PyObject *) but;
}
/*@DO NOT TOUCH THIS FUNCTION !
- Redrawing a slider inside its own callback routine is actually forbidden
- with the current toolkit architecture (button routines are not reentrant).
- But it works anyway.
- XXX This is condemned to be dinosource in future - it's a hack.
- */
+ Redrawing a slider inside its own callback routine is actually forbidden
+ with the current toolkit architecture (button routines are not reentrant).
+ But it works anyway.
+ XXX This is condemned to be dinosource in future - it's a hack.
+ */
static void py_slider_update(void *butv, void *data2_unused)
{
- uiBut *but= butv;
+ uiBut *but= butv;
- EXPP_disable_force_draw= 1;
- /*@
- Disable forced drawing, otherwise the button object which
- is still being used might be deleted
- */
+ EXPP_disable_force_draw= 1;
+ /*@
+ Disable forced drawing, otherwise the button object which
+ is still being used might be deleted
+ */
/*@
- spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */
-
- g_window_redrawn = 0;
- curarea->win_swap= WIN_BACK_OK;
- /* removed global uiFrontBuf (contact ton when this goes wrong here) */
- spacetext_do_pywin_buttons(curarea->spacedata.first, uiButGetRetVal(but));
+ spacetext_do_pywin_buttons(curarea->spacedata.first, but->retval); */
+ g_window_redrawn = 0;
+ curarea->win_swap= WIN_BACK_OK;
+ /* removed global uiFrontBuf (contact ton when this goes wrong here) */
+ spacescript_do_pywin_buttons(curarea->spacedata.first, uiButGetRetVal(but));
- if (!g_window_redrawn) /*@ if Redraw already called */
- M_Window_Redraw(0, Py_BuildValue("(i)", SPACE_VIEW3D));
+ if (!g_window_redrawn) /*@ if Redraw already called */
+ M_Window_Redraw(0, Py_BuildValue("(i)", SPACE_VIEW3D));
- EXPP_disable_force_draw= 0;
+ EXPP_disable_force_draw= 0;
}
static PyObject *Method_Slider (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL;
- int event;
- int x, y, w, h, realtime=1;
- Button *but;
- PyObject *mino, *maxo, *inio;
-
- if (!PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event,
- &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, five ints, three PyObjects\n\
- and optionally another int and string as arguments");
-
- but= newbutton();
- if (PyFloat_Check(inio)) {
- float ini, min, max;
-
- ini= PyFloat_AsDouble(inio);
- min= PyFloat_AsDouble(mino);
- max= PyFloat_AsDouble(maxo);
-
- but->type= 2;
- but->val.asfloat= ini;
-
- block= Get_uiBlock();
- if(block) {
- uiBut *ubut;
- ubut= uiDefButF(block, NUMSLI, event, name, x, y, w, h,
- &but->val.asfloat, min, max, 0, 0, tip);
- if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
- }
- }
- else {
- int ini, min, max;
-
- ini= PyInt_AsLong(inio);
- min= PyInt_AsLong(mino);
- max= PyInt_AsLong(maxo);
-
- but->type= 1;
- but->val.asint= ini;
-
- block= Get_uiBlock();
- if(block) {
- uiBut *ubut;
- ubut= uiDefButI(block, NUMSLI, event, name, x, y, w, h,
- &but->val.asint, min, max, 0, 0, tip);
- if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
- }
- }
- return (PyObject *) but;
+ uiBlock *block;
+ char *name, *tip= NULL;
+ int event;
+ int x, y, w, h, realtime=1;
+ Button *but;
+ PyObject *mino, *maxo, *inio;
+
+ if (!PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event,
+ &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, five ints, three PyObjects\n\
+ and optionally another int and string as arguments");
+
+ but= newbutton();
+ if (PyFloat_Check(inio)) {
+ float ini, min, max;
+
+ ini= PyFloat_AsDouble(inio);
+ min= PyFloat_AsDouble(mino);
+ max= PyFloat_AsDouble(maxo);
+
+ but->type= 2;
+ but->val.asfloat= ini;
+
+ block= Get_uiBlock();
+ if(block) {
+ uiBut *ubut;
+ ubut= uiDefButF(block, NUMSLI, event, name, x, y, w, h,
+ &but->val.asfloat, min, max, 0, 0, tip);
+ if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
+ }
+ }
+ else {
+ int ini, min, max;
+
+ ini= PyInt_AsLong(inio);
+ min= PyInt_AsLong(mino);
+ max= PyInt_AsLong(maxo);
+
+ but->type= 1;
+ but->val.asint= ini;
+
+ block= Get_uiBlock();
+ if(block) {
+ uiBut *ubut;
+ ubut= uiDefButI(block, NUMSLI, event, name, x, y, w, h,
+ &but->val.asint, min, max, 0, 0, tip);
+ if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
+ }
+ }
+ return (PyObject *) but;
}
-static PyObject *Method_Scrollbar (PyObject *self, PyObject *args)
+static PyObject *Method_Scrollbar (PyObject *self, PyObject *args)
{
- char *tip= NULL;
- uiBlock *block;
- int event;
- int x, y, w, h, realtime=1;
- Button *but;
- PyObject *mino, *maxo, *inio;
- float ini, min, max;
-
- if (!PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h,
- &inio, &mino, &maxo, &realtime, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected five ints, three PyObjects and optionally\n\
- another int and string as arguments");
-
- if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio))
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected numbers for initial, min, and max");
-
- but= newbutton();
-
- if (PyFloat_Check(inio)) but->type= 2;
- else but->type= 1;
-
- ini= PyFloat_AsDouble(inio);
- min= PyFloat_AsDouble(mino);
- max= PyFloat_AsDouble(maxo);
-
- if (but->type==2) {
- but->val.asfloat= ini;
- block= Get_uiBlock();
- if(block) {
- uiBut *ubut;
- ubut= uiDefButF(block, SCROLL, event, "", x, y, w, h,
- &but->val.asfloat, min, max, 0, 0, tip);
- if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
- }
- } else {
- but->val.asint= ini;
- block= Get_uiBlock();
- if(block) {
- uiBut *ubut;
- ubut= uiDefButI(block, SCROLL, event, "", x, y, w, h,
- &but->val.asint, min, max, 0, 0, tip);
- if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
- }
- }
-
- return (PyObject *) but;
+ char *tip= NULL;
+ uiBlock *block;
+ int event;
+ int x, y, w, h, realtime=1;
+ Button *but;
+ PyObject *mino, *maxo, *inio;
+ float ini, min, max;
+
+ if (!PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h,
+ &inio, &mino, &maxo, &realtime, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected five ints, three PyObjects and optionally\n\
+ another int and string as arguments");
+
+ if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "expected numbers for initial, min, and max");
+
+ but= newbutton();
+
+ if (PyFloat_Check(inio)) but->type= 2;
+ else but->type= 1;
+
+ ini= PyFloat_AsDouble(inio);
+ min= PyFloat_AsDouble(mino);
+ max= PyFloat_AsDouble(maxo);
+
+ if (but->type==2) {
+ but->val.asfloat= ini;
+ block= Get_uiBlock();
+ if(block) {
+ uiBut *ubut;
+ ubut= uiDefButF(block, SCROLL, event, "", x, y, w, h,
+ &but->val.asfloat, min, max, 0, 0, tip);
+ if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
+ }
+ } else {
+ but->val.asint= ini;
+ block= Get_uiBlock();
+ if(block) {
+ uiBut *ubut;
+ ubut= uiDefButI(block, SCROLL, event, "", x, y, w, h,
+ &but->val.asint, min, max, 0, 0, tip);
+ if (realtime) uiButSetFunc(ubut, py_slider_update, ubut, NULL);
+ }
+ }
+
+ return (PyObject *) but;
}
static PyObject *Method_Number (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL;
- int event;
- int x, y, w, h;
- Button *but;
- PyObject *mino, *maxo, *inio;
-
- if (!PyArg_ParseTuple(args, "siiiiiOOO|s", &name, &event,
- &x, &y, &w, &h, &inio, &mino, &maxo, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, five ints, three PyObjects and\n\
- optionally another string as arguments");
-
- but= newbutton();
-
- if (PyFloat_Check(inio)) {
- float ini, min, max;
-
- ini= PyFloat_AsDouble(inio);
- min= PyFloat_AsDouble(mino);
- max= PyFloat_AsDouble(maxo);
-
- but->type= 2;
- but->val.asfloat= ini;
-
- block= Get_uiBlock();
- if(block) uiDefButF(block, NUM, event, name, x, y, w, h,
- &but->val.asfloat, min, max, 0, 0, tip);
- } else {
- int ini, min, max;
-
- ini= PyInt_AsLong(inio);
- min= PyInt_AsLong(mino);
- max= PyInt_AsLong(maxo);
-
- but->type= 1;
- but->val.asint= ini;
-
- block= Get_uiBlock();
- if(block) uiDefButI(block, NUM, event, name, x, y, w, h,
- &but->val.asint, min, max, 0, 0, tip);
- }
-
- return (PyObject *) but;
+ uiBlock *block;
+ char *name, *tip= NULL;
+ int event;
+ int x, y, w, h;
+ Button *but;
+ PyObject *mino, *maxo, *inio;
+
+ if (!PyArg_ParseTuple(args, "siiiiiOOO|s", &name, &event,
+ &x, &y, &w, &h, &inio, &mino, &maxo, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, five ints, three PyObjects and\n\
+ optionally another string as arguments");
+
+ but= newbutton();
+
+ if (PyFloat_Check(inio)) {
+ float ini, min, max;
+
+ ini= PyFloat_AsDouble(inio);
+ min= PyFloat_AsDouble(mino);
+ max= PyFloat_AsDouble(maxo);
+
+ but->type= 2;
+ but->val.asfloat= ini;
+
+ block= Get_uiBlock();
+ if(block) uiDefButF(block, NUM, event, name, x, y, w, h,
+ &but->val.asfloat, min, max, 0, 0, tip);
+ } else {
+ int ini, min, max;
+
+ ini= PyInt_AsLong(inio);
+ min= PyInt_AsLong(mino);
+ max= PyInt_AsLong(maxo);
+
+ but->type= 1;
+ but->val.asint= ini;
+
+ block= Get_uiBlock();
+ if(block) uiDefButI(block, NUM, event, name, x, y, w, h,
+ &but->val.asint, min, max, 0, 0, tip);
+ }
+
+ return (PyObject *) but;
}
static PyObject *Method_String (PyObject *self, PyObject *args)
{
- uiBlock *block;
- char *name, *tip= NULL, *newstr;
- int event;
- int x, y, w, h, len;
- Button *but;
-
- if (!PyArg_ParseTuple(args, "siiiiisi|s", &name, &event,
- &x, &y, &w, &h, &newstr, &len, &tip))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string, five ints, a string, an int and\n\
- optionally another string as arguments");
-
- but= newbutton();
- but->type= 3;
- but->slen= len;
- but->val.asstr= MEM_mallocN(len+1, "button string");
-
- strncpy(but->val.asstr, newstr, len);
- but->val.asstr[len]= 0;
-
- block= Get_uiBlock();
- if(block) uiDefBut(block, TEX, event, name, x, y, w, h,
- but->val.asstr, 0, len, 0, 0, tip);
-
- return (PyObject *) but;
+ uiBlock *block;
+ char *name, *tip= NULL, *newstr;
+ int event;
+ int x, y, w, h, len;
+ Button *but;
+
+ if (!PyArg_ParseTuple(args, "siiiiisi|s", &name, &event,
+ &x, &y, &w, &h, &newstr, &len, &tip))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string, five ints, a string, an int and\n\
+ optionally another string as arguments");
+
+ but= newbutton();
+ but->type= 3;
+ but->slen= len;
+ but->val.asstr= MEM_mallocN(len+1, "button string");
+
+ strncpy(but->val.asstr, newstr, len);
+ but->val.asstr[len]= 0;
+
+ block= Get_uiBlock();
+ if(block) uiDefBut(block, TEX, event, name, x, y, w, h,
+ but->val.asstr, 0, len, 0, 0, tip);
+
+ return (PyObject *) but;
}
static PyObject *Method_GetStringWidth (PyObject *self, PyObject *args)
{
- char *text;
- char *font_str = "normal";
- struct BMF_Font *font;
- PyObject *width;
+ char *text;
+ char *font_str = "normal";
+ struct BMF_Font *font;
+ PyObject *width;
- if (!PyArg_ParseTuple(args, "s|s", &text, &font_str))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected one or two string arguments");
+ if (!PyArg_ParseTuple(args, "s|s", &text, &font_str))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected one or two string arguments");
- if (!strcmp (font_str, "normal")) font = (&G)->font;
- else if (!strcmp (font_str, "small" )) font = (&G)->fonts;
- else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
- else
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
+ if (!strcmp (font_str, "normal")) font = (&G)->font;
+ else if (!strcmp (font_str, "small" )) font = (&G)->fonts;
+ else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
+ else
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
- width = PyInt_FromLong(BMF_GetStringWidth (font, text));
+ width = PyInt_FromLong(BMF_GetStringWidth (font, text));
- if (!width)
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create PyInt");
+ if (!width)
+ return EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "couldn't create PyInt");
- return width;
+ return width;
}
static PyObject *Method_Text (PyObject *self, PyObject *args)
{
- char *text;
- char *font_str = NULL;
- struct BMF_Font *font;
+ char *text;
+ char *font_str = NULL;
+ struct BMF_Font *font;
- if (!PyArg_ParseTuple(args, "s|s", &text, &font_str))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected one or two string arguments");
+ if (!PyArg_ParseTuple(args, "s|s", &text, &font_str))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected one or two string arguments");
- if (!font_str) font = (&G)->font;
- else if (!strcmp (font_str, "normal")) font = (&G)->font;
- else if (!strcmp (font_str, "small" )) font = (&G)->fonts;
- else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
- else
- return EXPP_ReturnPyObjError (PyExc_AttributeError,
- "\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
+ if (!font_str) font = (&G)->font;
+ else if (!strcmp (font_str, "normal")) font = (&G)->font;
+ else if (!strcmp (font_str, "small" )) font = (&G)->fonts;
+ else if (!strcmp (font_str, "tiny" )) font = (&G)->fontss;
+ else
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "\"font\" must be: 'normal' (default), 'small' or 'tiny'.");
- BMF_DrawString(font, text);
+ BMF_DrawString(font, text);
- return PyInt_FromLong (BMF_GetStringWidth (font, text));
+ return PyInt_FromLong (BMF_GetStringWidth (font, text));
}
static PyObject *Method_PupMenu (PyObject *self, PyObject *args)
{
- char *text;
- int maxrow = -1;
- PyObject *ret;
+ char *text;
+ int maxrow = -1;
+ PyObject *ret;
- if (!PyArg_ParseTuple(args, "s|i", &text, &maxrow))
- return EXPP_ReturnPyObjError (PyExc_TypeError,
- "expected a string and optionally an int as arguments");
+ if (!PyArg_ParseTuple(args, "s|i", &text, &maxrow))
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected a string and optionally an int as arguments");
- if (maxrow >= 0)
- ret = PyInt_FromLong (pupmenu_col (text, maxrow));
- else
- ret = PyInt_FromLong (pupmenu (text));
+ if (maxrow >= 0)
+ ret = PyInt_FromLong (pupmenu_col (text, maxrow));
+ else
+ ret = PyInt_FromLong (pupmenu (text));
- if (ret) return ret;
+ if (ret) return ret;
- return EXPP_ReturnPyObjError (PyExc_MemoryError,
- "couldn't create a PyInt");
+ return EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "couldn't create a PyInt");
}
PyObject *Draw_Init (void)
{
- PyObject *submodule, *dict;
+ PyObject *submodule, *dict;
- Button_Type.ob_type = &PyType_Type;
+ Button_Type.ob_type = &PyType_Type;
- submodule = Py_InitModule3("Blender.Draw", Draw_methods, Draw_doc);
+ submodule = Py_InitModule3("Blender.Draw", Draw_methods, Draw_doc);
- dict= PyModule_GetDict(submodule);
+ dict= PyModule_GetDict(submodule);
#define EXPP_ADDCONST(x) \
- PyDict_SetItemString(dict, #x, PyInt_FromLong(x))
+ PyDict_SetItemString(dict, #x, PyInt_FromLong(x))
/* So, for example:
* EXPP_ADDCONST(LEFTMOUSE) becomes
* PyDict_SetItemString(dict, "LEFTMOUSE", PyInt_FromLong(LEFTMOUSE)) */
- EXPP_ADDCONST(LEFTMOUSE);
- EXPP_ADDCONST(MIDDLEMOUSE);
- EXPP_ADDCONST(RIGHTMOUSE);
- EXPP_ADDCONST(MOUSEX);
- EXPP_ADDCONST(MOUSEY);
- EXPP_ADDCONST(TIMER0);
- EXPP_ADDCONST(TIMER1);
- EXPP_ADDCONST(TIMER2);
- EXPP_ADDCONST(TIMER3);
- EXPP_ADDCONST(KEYBD);
- EXPP_ADDCONST(RAWKEYBD);
- EXPP_ADDCONST(REDRAW);
- EXPP_ADDCONST(INPUTCHANGE);
- EXPP_ADDCONST(QFULL);
- EXPP_ADDCONST(WINFREEZE);
- EXPP_ADDCONST(WINTHAW);
- EXPP_ADDCONST(WINCLOSE);
- EXPP_ADDCONST(WINQUIT);
+ EXPP_ADDCONST(LEFTMOUSE);
+ EXPP_ADDCONST(MIDDLEMOUSE);
+ EXPP_ADDCONST(RIGHTMOUSE);
+ EXPP_ADDCONST(MOUSEX);
+ EXPP_ADDCONST(MOUSEY);
+ EXPP_ADDCONST(TIMER0);
+ EXPP_ADDCONST(TIMER1);
+ EXPP_ADDCONST(TIMER2);
+ EXPP_ADDCONST(TIMER3);
+ EXPP_ADDCONST(KEYBD);
+ EXPP_ADDCONST(RAWKEYBD);
+ EXPP_ADDCONST(REDRAW);
+ EXPP_ADDCONST(INPUTCHANGE);
+ EXPP_ADDCONST(QFULL);
+ EXPP_ADDCONST(WINFREEZE);
+ EXPP_ADDCONST(WINTHAW);
+ EXPP_ADDCONST(WINCLOSE);
+ EXPP_ADDCONST(WINQUIT);
#ifndef IRISGL
- EXPP_ADDCONST(Q_FIRSTTIME);
+ EXPP_ADDCONST(Q_FIRSTTIME);
#endif
- EXPP_ADDCONST(AKEY);
- EXPP_ADDCONST(BKEY);
- EXPP_ADDCONST(CKEY);
- EXPP_ADDCONST(DKEY);
- EXPP_ADDCONST(EKEY);
- EXPP_ADDCONST(FKEY);
- EXPP_ADDCONST(GKEY);
- EXPP_ADDCONST(HKEY);
- EXPP_ADDCONST(IKEY);
- EXPP_ADDCONST(JKEY);
- EXPP_ADDCONST(KKEY);
- EXPP_ADDCONST(LKEY);
- EXPP_ADDCONST(MKEY);
- EXPP_ADDCONST(NKEY);
- EXPP_ADDCONST(OKEY);
- EXPP_ADDCONST(PKEY);
- EXPP_ADDCONST(QKEY);
- EXPP_ADDCONST(RKEY);
- EXPP_ADDCONST(SKEY);
- EXPP_ADDCONST(TKEY);
- EXPP_ADDCONST(UKEY);
- EXPP_ADDCONST(VKEY);
- EXPP_ADDCONST(WKEY);
- EXPP_ADDCONST(XKEY);
- EXPP_ADDCONST(YKEY);
- EXPP_ADDCONST(ZKEY);
- EXPP_ADDCONST(ZEROKEY);
- EXPP_ADDCONST(ONEKEY);
- EXPP_ADDCONST(TWOKEY);
- EXPP_ADDCONST(THREEKEY);
- EXPP_ADDCONST(FOURKEY);
- EXPP_ADDCONST(FIVEKEY);
- EXPP_ADDCONST(SIXKEY);
- EXPP_ADDCONST(SEVENKEY);
- EXPP_ADDCONST(EIGHTKEY);
- EXPP_ADDCONST(NINEKEY);
- EXPP_ADDCONST(CAPSLOCKKEY);
- EXPP_ADDCONST(LEFTCTRLKEY);
- EXPP_ADDCONST(LEFTALTKEY);
- EXPP_ADDCONST(RIGHTALTKEY);
- EXPP_ADDCONST(RIGHTCTRLKEY);
- EXPP_ADDCONST(RIGHTSHIFTKEY);
- EXPP_ADDCONST(LEFTSHIFTKEY);
- EXPP_ADDCONST(ESCKEY);
- EXPP_ADDCONST(TABKEY);
- EXPP_ADDCONST(RETKEY);
- EXPP_ADDCONST(SPACEKEY);
- EXPP_ADDCONST(LINEFEEDKEY);
- EXPP_ADDCONST(BACKSPACEKEY);
- EXPP_ADDCONST(DELKEY);
- EXPP_ADDCONST(SEMICOLONKEY);
- EXPP_ADDCONST(PERIODKEY);
- EXPP_ADDCONST(COMMAKEY);
- EXPP_ADDCONST(QUOTEKEY);
- EXPP_ADDCONST(ACCENTGRAVEKEY);
- EXPP_ADDCONST(MINUSKEY);
- EXPP_ADDCONST(SLASHKEY);
- EXPP_ADDCONST(BACKSLASHKEY);
- EXPP_ADDCONST(EQUALKEY);
- EXPP_ADDCONST(LEFTBRACKETKEY);
- EXPP_ADDCONST(RIGHTBRACKETKEY);
- EXPP_ADDCONST(LEFTARROWKEY);
- EXPP_ADDCONST(DOWNARROWKEY);
- EXPP_ADDCONST(RIGHTARROWKEY);
- EXPP_ADDCONST(UPARROWKEY);
- EXPP_ADDCONST(PAD2);
- EXPP_ADDCONST(PAD4);
- EXPP_ADDCONST(PAD6);
- EXPP_ADDCONST(PAD8);
- EXPP_ADDCONST(PAD1);
- EXPP_ADDCONST(PAD3);
- EXPP_ADDCONST(PAD5);
- EXPP_ADDCONST(PAD7);
- EXPP_ADDCONST(PAD9);
- EXPP_ADDCONST(PADPERIOD);
- EXPP_ADDCONST(PADSLASHKEY);
- EXPP_ADDCONST(PADASTERKEY);
- EXPP_ADDCONST(PAD0);
- EXPP_ADDCONST(PADMINUS);
- EXPP_ADDCONST(PADENTER);
- EXPP_ADDCONST(PADPLUSKEY);
- EXPP_ADDCONST(F1KEY);
- EXPP_ADDCONST(F2KEY);
- EXPP_ADDCONST(F3KEY);
- EXPP_ADDCONST(F4KEY);
- EXPP_ADDCONST(F5KEY);
- EXPP_ADDCONST(F6KEY);
- EXPP_ADDCONST(F7KEY);
- EXPP_ADDCONST(F8KEY);
- EXPP_ADDCONST(F9KEY);
- EXPP_ADDCONST(F10KEY);
- EXPP_ADDCONST(F11KEY);
- EXPP_ADDCONST(F12KEY);
- EXPP_ADDCONST(PAUSEKEY);
- EXPP_ADDCONST(INSERTKEY);
- EXPP_ADDCONST(HOMEKEY);
- EXPP_ADDCONST(PAGEUPKEY);
- EXPP_ADDCONST(PAGEDOWNKEY);
- EXPP_ADDCONST(ENDKEY);
-
- return submodule;
+ EXPP_ADDCONST(AKEY);
+ EXPP_ADDCONST(BKEY);
+ EXPP_ADDCONST(CKEY);
+ EXPP_ADDCONST(DKEY);
+ EXPP_ADDCONST(EKEY);
+ EXPP_ADDCONST(FKEY);
+ EXPP_ADDCONST(GKEY);
+ EXPP_ADDCONST(HKEY);
+ EXPP_ADDCONST(IKEY);
+ EXPP_ADDCONST(JKEY);
+ EXPP_ADDCONST(KKEY);
+ EXPP_ADDCONST(LKEY);
+ EXPP_ADDCONST(MKEY);
+ EXPP_ADDCONST(NKEY);
+ EXPP_ADDCONST(OKEY);
+ EXPP_ADDCONST(PKEY);
+ EXPP_ADDCONST(QKEY);
+ EXPP_ADDCONST(RKEY);
+ EXPP_ADDCONST(SKEY);
+ EXPP_ADDCONST(TKEY);
+ EXPP_ADDCONST(UKEY);
+ EXPP_ADDCONST(VKEY);
+ EXPP_ADDCONST(WKEY);
+ EXPP_ADDCONST(XKEY);
+ EXPP_ADDCONST(YKEY);
+ EXPP_ADDCONST(ZKEY);
+ EXPP_ADDCONST(ZEROKEY);
+ EXPP_ADDCONST(ONEKEY);
+ EXPP_ADDCONST(TWOKEY);
+ EXPP_ADDCONST(THREEKEY);
+ EXPP_ADDCONST(FOURKEY);
+ EXPP_ADDCONST(FIVEKEY);
+ EXPP_ADDCONST(SIXKEY);
+ EXPP_ADDCONST(SEVENKEY);
+ EXPP_ADDCONST(EIGHTKEY);
+ EXPP_ADDCONST(NINEKEY);
+ EXPP_ADDCONST(CAPSLOCKKEY);
+ EXPP_ADDCONST(LEFTCTRLKEY);
+ EXPP_ADDCONST(LEFTALTKEY);
+ EXPP_ADDCONST(RIGHTALTKEY);
+ EXPP_ADDCONST(RIGHTCTRLKEY);
+ EXPP_ADDCONST(RIGHTSHIFTKEY);
+ EXPP_ADDCONST(LEFTSHIFTKEY);
+ EXPP_ADDCONST(ESCKEY);
+ EXPP_ADDCONST(TABKEY);
+ EXPP_ADDCONST(RETKEY);
+ EXPP_ADDCONST(SPACEKEY);
+ EXPP_ADDCONST(LINEFEEDKEY);
+ EXPP_ADDCONST(BACKSPACEKEY);
+ EXPP_ADDCONST(DELKEY);
+ EXPP_ADDCONST(SEMICOLONKEY);
+ EXPP_ADDCONST(PERIODKEY);
+ EXPP_ADDCONST(COMMAKEY);
+ EXPP_ADDCONST(QUOTEKEY);
+ EXPP_ADDCONST(ACCENTGRAVEKEY);
+ EXPP_ADDCONST(MINUSKEY);
+ EXPP_ADDCONST(SLASHKEY);
+ EXPP_ADDCONST(BACKSLASHKEY);
+ EXPP_ADDCONST(EQUALKEY);
+ EXPP_ADDCONST(LEFTBRACKETKEY);
+ EXPP_ADDCONST(RIGHTBRACKETKEY);
+ EXPP_ADDCONST(LEFTARROWKEY);
+ EXPP_ADDCONST(DOWNARROWKEY);
+ EXPP_ADDCONST(RIGHTARROWKEY);
+ EXPP_ADDCONST(UPARROWKEY);
+ EXPP_ADDCONST(PAD2);
+ EXPP_ADDCONST(PAD4);
+ EXPP_ADDCONST(PAD6);
+ EXPP_ADDCONST(PAD8);
+ EXPP_ADDCONST(PAD1);
+ EXPP_ADDCONST(PAD3);
+ EXPP_ADDCONST(PAD5);
+ EXPP_ADDCONST(PAD7);
+ EXPP_ADDCONST(PAD9);
+ EXPP_ADDCONST(PADPERIOD);
+ EXPP_ADDCONST(PADSLASHKEY);
+ EXPP_ADDCONST(PADASTERKEY);
+ EXPP_ADDCONST(PAD0);
+ EXPP_ADDCONST(PADMINUS);
+ EXPP_ADDCONST(PADENTER);
+ EXPP_ADDCONST(PADPLUSKEY);
+ EXPP_ADDCONST(F1KEY);
+ EXPP_ADDCONST(F2KEY);
+ EXPP_ADDCONST(F3KEY);
+ EXPP_ADDCONST(F4KEY);
+ EXPP_ADDCONST(F5KEY);
+ EXPP_ADDCONST(F6KEY);
+ EXPP_ADDCONST(F7KEY);
+ EXPP_ADDCONST(F8KEY);
+ EXPP_ADDCONST(F9KEY);
+ EXPP_ADDCONST(F10KEY);
+ EXPP_ADDCONST(F11KEY);
+ EXPP_ADDCONST(F12KEY);
+ EXPP_ADDCONST(PAUSEKEY);
+ EXPP_ADDCONST(INSERTKEY);
+ EXPP_ADDCONST(HOMEKEY);
+ EXPP_ADDCONST(PAGEUPKEY);
+ EXPP_ADDCONST(PAGEDOWNKEY);
+ EXPP_ADDCONST(ENDKEY);
+
+ return submodule;
}
diff --git a/source/blender/python/api2_2x/Draw.h b/source/blender/python/api2_2x/Draw.h
index 3fbac1de12e..3681e4a5fe9 100644
--- a/source/blender/python/api2_2x/Draw.h
+++ b/source/blender/python/api2_2x/Draw.h
@@ -46,10 +46,12 @@
#include "BMF_Api.h"
#include "DNA_screen_types.h"
+#include "DNA_script_types.h"
#include "DNA_space_types.h"
#include "DNA_text_types.h"
#include "BKE_global.h"
+#include "BKE_library.h"
#include "BIF_gl.h"
#include "BIF_screen.h"
@@ -77,7 +79,6 @@ int g_window_redrawn;
static char Draw_doc[] =
"The Blender.Draw submodule";
-static void exit_pydraw (SpaceText *st);
static uiBlock *Get_uiBlock (void);
void initDraw (void);
@@ -119,13 +120,14 @@ static Button *newbutton (void);
/* GUI interface routines */
-static void exit_pydraw(SpaceText *st);
-static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args);
-void BPY_spacetext_do_pywin_draw(SpaceText *st);
-static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event);
-void BPY_spacetext_do_pywin_event(SpaceText *st,
- unsigned short event, short val);
-int BPY_spacetext_is_pywin(SpaceText *sc);
+static void exit_pydraw(SpaceScript *sc, short error);
+static void exec_callback(SpaceScript *sc, PyObject *callback, PyObject *args);
+
+/* these are declared in ../BPY_extern.h */
+void BPY_spacescript_do_pywin_draw(SpaceScript *sc);
+static void spacescript_do_pywin_buttons(SpaceScript *sc, unsigned short event);
+void BPY_spacescript_do_pywin_event(SpaceScript *sc, unsigned short event, short val);
+void BPY_free_compiled_text(Text *text);
static char Method_Exit_doc[] =
"() - Exit the windowing interface";
diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c
index b93b2f7f2e2..54076e0fce5 100644
--- a/source/blender/python/api2_2x/EXPP_interface.c
+++ b/source/blender/python/api2_2x/EXPP_interface.c
@@ -33,7 +33,10 @@
#include <Python.h>
+#include <BIF_space.h>
+#include <BIF_screen.h>
#include <BKE_global.h>
+#include <BKE_library.h>
#include <BKE_main.h>
#include <DNA_ID.h>
#include <DNA_camera_types.h>
@@ -41,7 +44,10 @@
#include <DNA_material_types.h>
#include <DNA_object_types.h>
#include <DNA_scene_types.h>
+#include <DNA_screen_types.h>
+#include <DNA_script_types.h>
#include <DNA_scriptlink_types.h>
+#include <DNA_space_types.h>
#include <DNA_world_types.h>
#include "EXPP_interface.h"
@@ -177,3 +183,42 @@ TODO: Check this */
return (scriptlink);
}
+
+void BPY_clear_script (Script *script)
+{
+ if (!script) return;
+
+ Py_XDECREF((PyObject *)script->py_globaldict);
+ Py_XDECREF((PyObject *)script->py_button);
+ Py_XDECREF((PyObject *)script->py_event);
+ Py_XDECREF((PyObject *)script->py_draw);
+}
+
+void EXPP_move_to_spacescript (Script *script)
+{ /* used by BPY_txt_do_python when a text is already being executed */
+ SpaceScript *sc;
+ newspace(curarea, SPACE_SCRIPT);
+ sc = curarea->spacedata.first;
+ sc->script = script;
+ return;
+}
+
+/*****************************************************************************/
+/* Description: This function frees a finished (flags == 0) script. */
+/*****************************************************************************/
+void BPY_free_finished_script(Script *script)
+{
+ PyObject *d = script->py_globaldict;
+
+ if (d) {
+ PyDict_Clear (d);
+ Py_DECREF (d); /* Release dictionary. */
+ script->py_globaldict = NULL;
+ }
+
+ if (script->lastspace != SPACE_SCRIPT)
+ newspace (curarea, script->lastspace);
+
+ free_libblock(&G.main->script, script);
+ return;
+}
diff --git a/source/blender/python/api2_2x/EXPP_interface.h b/source/blender/python/api2_2x/EXPP_interface.h
index c9e77b96704..10c1a7c17f3 100644
--- a/source/blender/python/api2_2x/EXPP_interface.h
+++ b/source/blender/python/api2_2x/EXPP_interface.h
@@ -31,7 +31,10 @@
#include <DNA_ID.h>
+struct Script;
+
void initBlenderApi2_2x (void);
void clearScriptLinks (void);
ScriptLink * setScriptLinks(ID *id, short event);
void discardFromBDict (char *key);
+void EXPP_move_to_spacescript (struct Script *script);
diff --git a/source/blender/python/api2_2x/Sys.c b/source/blender/python/api2_2x/Sys.c
index 4528d41933a..29c54785595 100644
--- a/source/blender/python/api2_2x/Sys.c
+++ b/source/blender/python/api2_2x/Sys.c
@@ -62,7 +62,7 @@ static PyObject *M_sys_dirname (PyObject *self, PyObject *args)
{
PyObject *c;
- char *name, dirname[256];
+ char *name, *p, dirname[256];
char sep;
int n;
@@ -74,14 +74,20 @@ static PyObject *M_sys_dirname (PyObject *self, PyObject *args)
sep = PyString_AsString(c)[0];
Py_DECREF(c);
- n = strrchr(name, sep) - name;
- if (n > 255) {
- PyErr_SetString(PyExc_RuntimeError, "path too long");
- return 0;
- }
+ p = strrchr(name, sep);
+
+ if (p) {
+ n = p - name;
+
+ if (n > 255) {
+ PyErr_SetString(PyExc_RuntimeError, "path too long");
+ return 0;
+ }
- strncpy(dirname, name, n);
- dirname[n] = 0;
+ strncpy(dirname, name, n);
+ dirname[n] = 0;
+ return Py_BuildValue("s", dirname);
+ }
- return Py_BuildValue("s", dirname);
+ return Py_BuildValue("s", "."); /* XXX need to fix this? (is crossplatform?)*/
}
diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c
index ad92b7d02ff..a7897f56dcd 100644
--- a/source/blender/python/api2_2x/Window.c
+++ b/source/blender/python/api2_2x/Window.c
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
@@ -31,90 +31,90 @@
#include "Window.h"
#include "vector.h"
+#include <BKE_library.h>
/* Many parts of the code here come from the older bpython implementation
* (file opy_window.c) */
/*****************************************************************************/
-/* Function: M_Window_Redraw */
-/* Python equivalent: Blender.Window.Redraw */
+/* Function: M_Window_Redraw */
+/* Python equivalent: Blender.Window.Redraw */
/*****************************************************************************/
PyObject *M_Window_Redraw(PyObject *self, PyObject *args)
{ /* not static so py_slider_update in Draw.[ch] can use it */
- ScrArea *tempsa, *sa;
- SpaceText *st;
- int wintype = SPACE_VIEW3D;
- short redraw_all = 0;
+ ScrArea *tempsa, *sa;
+ SpaceText *st;
+ int wintype = SPACE_VIEW3D;
+ short redraw_all = 0;
- if (!PyArg_ParseTuple(args, "|i", &wintype))
- return (EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected int argument (or nothing)"));
+ if (!PyArg_ParseTuple(args, "|i", &wintype))
+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "expected int argument (or nothing)"));
- if (wintype < 0)
- redraw_all = 1;
+ if (wintype < 0)
+ redraw_all = 1;
- if (!during_script()) { /* XXX check this */
- tempsa= curarea;
- sa = G.curscreen->areabase.first;
+ if (!during_script()) { /* XXX check this */
+ tempsa= curarea;
+ sa = G.curscreen->areabase.first;
- while (sa) {
+ while (sa) {
- if (sa->spacetype == wintype || redraw_all) {
- /* don't force-redraw Text window (Python GUI) when
- redraw is called out of a slider update */
- if (sa->spacetype == SPACE_TEXT) {
- st = sa->spacedata.first;
- if (st->text->flags & TXT_FOLLOW) /* follow cursor display */
- pop_space_text(st);
- if (EXPP_disable_force_draw) { /* defined in Draw.[ch] ... */
- scrarea_queue_redraw(sa);
- }
+ if (sa->spacetype == wintype || redraw_all) {
+ /* don't force-redraw Text window (Python GUI) when
+ redraw is called out of a slider update */
+ if (sa->spacetype == SPACE_TEXT) {
+ st = sa->spacedata.first;
+ if (st->text->flags & TXT_FOLLOW) /* follow cursor display */
+ pop_space_text(st);
+ if (EXPP_disable_force_draw) { /* defined in Draw.[ch] ... */
+ scrarea_queue_redraw(sa);
+ }
+ } else {
+ scrarea_do_windraw(sa);
+ if (sa->headwin) scrarea_do_headdraw(sa);
+ }
+ }
- } else {
- scrarea_do_windraw(sa);
- if (sa->headwin) scrarea_do_headdraw(sa);
- }
- }
+ sa= sa->next;
+ }
- sa= sa->next;
- }
+ if (curarea != tempsa) areawinset (tempsa->win);
- if (curarea != tempsa) areawinset (tempsa->win);
+ if (curarea->headwin) scrarea_do_headdraw (curarea);
- if (curarea->headwin) scrarea_do_headdraw (curarea);
-
- screen_swapbuffers();
- }
+ screen_swapbuffers();
+ }
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
/*****************************************************************************/
-/* Function: M_Window_RedrawAll */
-/* Python equivalent: Blender.Window.RedrawAll */
+/* Function: M_Window_RedrawAll */
+/* Python equivalent: Blender.Window.RedrawAll */
/*****************************************************************************/
static PyObject *M_Window_RedrawAll(PyObject *self, PyObject *args)
{
- return M_Window_Redraw(self, Py_BuildValue("(i)", -1));
+ return M_Window_Redraw(self, Py_BuildValue("(i)", -1));
}
/*****************************************************************************/
-/* Function: M_Window_QRedrawAll */
-/* Python equivalent: Blender.Window.QRedrawAll */
+/* Function: M_Window_QRedrawAll */
+/* Python equivalent: Blender.Window.QRedrawAll */
/*****************************************************************************/
static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args)
{
- allqueue(REDRAWALL, 0);
+ allqueue(REDRAWALL, 0);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
/*****************************************************************************/
-/* Function: M_Window_FileSelector */
-/* Python equivalent: Blender.Window.FileSelector */
+/* Function: M_Window_FileSelector */
+/* Python equivalent: Blender.Window.FileSelector */
/*****************************************************************************/
/* This is the callback to "activate_fileselect" below. It receives the
@@ -123,101 +123,147 @@ static PyObject *M_Window_QRedrawAll(PyObject *self, PyObject *args)
static void getSelectedFile(char *name)
{
- if (EXPP_FS_PyCallback) {
- SpaceText *st= curarea->spacedata.first;
+ if (!EXPP_FS_PyCallback) return;
- PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);
+ PyObject_CallFunction((PyObject *)EXPP_FS_PyCallback, "s", name);
- EXPP_FS_PyCallback = NULL;
- st->flags &= ST_CLEAR_NAMESPACE; /* global dict can be cleared */
- }
+ EXPP_FS_PyCallback = NULL;
+
+ return;
}
static PyObject *M_Window_FileSelector(PyObject *self, PyObject *args)
{
- char *title = "SELECT FILE";
- SpaceText *st = curarea->spacedata.first;
-
- if (!PyArg_ParseTuple(args, "O!|s",
- &PyFunction_Type, &EXPP_FS_PyCallback, &title))
- return (EXPP_ReturnPyObjError (PyExc_AttributeError,
- "\nexpected a callback function (and optionally a string) as argument(s)"));
+ char *title = "SELECT FILE";
+ SpaceScript *sc;
+ Script *script = G.main->script.last;
+ int startspace = 0;
+
+ if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback,
+ &title))
+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "\nexpected a callback function (and optionally a string) as argument(s)"));
+
+/* trick: we move to a spacescript because then the fileselector will properly
+ * unset our SCRIPT_FILESEL flag when the user chooses a file or cancels the
+ * selection. This is necessary because when a user cancels, the
+ * getSelectedFile function above doesn't get called and so couldn't unset the
+ * flag. */
+ startspace = curarea->spacetype;
+ if (startspace != SPACE_SCRIPT) newspace (curarea, SPACE_SCRIPT);
+
+ sc = curarea->spacedata.first;
+
+ /* did we get the right script? */
+ if (!(script->flags & SCRIPT_RUNNING)) {
+ /* if not running, then we were already on a SpaceScript space, executing
+ * a registered callback -- aka: this script has a gui */
+ script = sc->script; /* this is the right script */
+ }
+ else { /* still running, use the trick */
+ script->lastspace = startspace;
+ sc->script = script;
+ }
- st->flags &= ~ST_CLEAR_NAMESPACE; /* so global dict won't be cleared */
+ script->flags |= SCRIPT_FILESEL;
- activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
+ activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
static PyObject *M_Window_ImageSelector(PyObject *self, PyObject *args)
{
- char *title = "SELECT IMAGE";
- SpaceText *st = curarea->spacedata.first;
-
- if (!PyArg_ParseTuple(args, "O!|s",
- &PyFunction_Type, &EXPP_FS_PyCallback, &title))
- return (EXPP_ReturnPyObjError (PyExc_AttributeError,
- "\nexpected a callback function (and optionally a string) as argument(s)"));
+ char *title = "SELECT IMAGE";
+ SpaceScript *sc;
+ Script *script = G.main->script.last;
+ int startspace = 0;
+
+ if (!PyArg_ParseTuple(args, "O!|s", &PyFunction_Type, &EXPP_FS_PyCallback,
+ &title))
+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "\nexpected a callback function (and optionally a string) as argument(s)"));
+
+/* trick: we move to a spacescript because then the fileselector will properly
+ * unset our SCRIPT_FILESEL flag when the user chooses a file or cancels the
+ * selection. This is necessary because when a user cancels, the
+ * getSelectedFile function above doesn't get called and so couldn't unset the
+ * flag. */
+ startspace = curarea->spacetype;
+ if (startspace != SPACE_SCRIPT) newspace (curarea, SPACE_SCRIPT);
+
+ sc = curarea->spacedata.first;
+
+ /* did we get the right script? */
+ if (!(script->flags & SCRIPT_RUNNING)) {
+ /* if not running, then we're on a SpaceScript space, executing a
+ * registered callback -- aka: this script has a gui */
+ SpaceScript *sc = curarea->spacedata.first;
+ script = sc->script; /* this is the right script */
+ }
+ else { /* still running, use the trick */
+ script->lastspace = startspace;
+ sc->script = script;
+ }
- st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */
+ script->flags |= SCRIPT_FILESEL; /* same flag as filesel */
- activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
+ activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
- Py_INCREF(Py_None);
- return Py_None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
/*****************************************************************************/
-/* Function: M_Window_DrawProgressBar */
-/* Python equivalent: Blender.Window.DrawProgressBar */
+/* Function: M_Window_DrawProgressBar */
+/* Python equivalent: Blender.Window.DrawProgressBar */
/*****************************************************************************/
static PyObject *M_Window_DrawProgressBar(PyObject *self, PyObject *args)
{
- float done;
- char *info = NULL;
- int retval;
+ float done;
+ char *info = NULL;
+ int retval;
- if(!PyArg_ParseTuple(args, "fs", &done, &info))
- return (EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected a float and a string as arguments"));
+ if(!PyArg_ParseTuple(args, "fs", &done, &info))
+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "expected a float and a string as arguments"));
- retval = progress_bar(done, info);
+ retval = progress_bar(done, info);
- return Py_BuildValue("i", retval);
+ return Py_BuildValue("i", retval);
}
/*****************************************************************************/
-/* Function: M_Window_GetCursorPos */
-/* Python equivalent: Blender.Window.GetCursorPos */
+/* Function: M_Window_GetCursorPos */
+/* Python equivalent: Blender.Window.GetCursorPos */
/*****************************************************************************/
static PyObject *M_Window_GetCursorPos(PyObject *self)
{
- float *cursor = NULL;
- PyObject *pylist;
+ float *cursor = NULL;
+ PyObject *pylist;
- if (G.vd && G.vd->localview)
- cursor = G.vd->cursor;
- else cursor = G.scene->cursor;
+ if (G.vd && G.vd->localview)
+ cursor = G.vd->cursor;
+ else cursor = G.scene->cursor;
- pylist = Py_BuildValue("[fff]", cursor[0], cursor[1], cursor[2]);
+ pylist = Py_BuildValue("[fff]", cursor[0], cursor[1], cursor[2]);
- if (!pylist)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "GetCursorPos: couldn't create pylist"));
+ if (!pylist)
+ return (EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "GetCursorPos: couldn't create pylist"));
- return pylist;
+ return pylist;
}
/*****************************************************************************/
-/* Function: M_Window_SetCursorPos */
-/* Python equivalent: Blender.Window.SetCursorPos */
+/* Function: M_Window_SetCursorPos */
+/* Python equivalent: Blender.Window.SetCursorPos */
/*****************************************************************************/
static PyObject *M_Window_SetCursorPos(PyObject *self, PyObject *args)
{
int ok = 0;
- float val[3];
+ float val[3];
if (PyObject_Length (args) == 3)
ok = PyArg_ParseTuple (args, "fff", &val[0], &val[1], &val[2]);
@@ -228,12 +274,12 @@ static PyObject *M_Window_SetCursorPos(PyObject *self, PyObject *args)
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected [f,f,f] or f,f,f as arguments");
- if (G.vd && G.vd->localview) {
+ if (G.vd && G.vd->localview) {
G.vd->cursor[0] = val[0];
G.vd->cursor[1] = val[1];
G.vd->cursor[2] = val[2];
}
- else {
+ else {
G.scene->cursor[0] = val[0];
G.scene->cursor[1] = val[1];
G.scene->cursor[2] = val[2];
@@ -244,70 +290,70 @@ static PyObject *M_Window_SetCursorPos(PyObject *self, PyObject *args)
}
/*****************************************************************************/
-/* Function: M_Window_GetViewVector */
-/* Python equivalent: Blender.Window.GetViewVector */
+/* Function: M_Window_GetViewVector */
+/* Python equivalent: Blender.Window.GetViewVector */
/*****************************************************************************/
static PyObject *M_Window_GetViewVector(PyObject *self)
{
float *vec = NULL;
- PyObject *pylist;
+ PyObject *pylist;
- if (!G.vd) {
+ if (!G.vd) {
Py_INCREF (Py_None);
return Py_None;
}
vec = G.vd->viewinv[2];
- pylist = Py_BuildValue("[fff]", vec[0], vec[1], vec[2]);
+ pylist = Py_BuildValue("[fff]", vec[0], vec[1], vec[2]);
- if (!pylist)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "GetViewVector: couldn't create pylist"));
+ if (!pylist)
+ return (EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "GetViewVector: couldn't create pylist"));
- return pylist;
+ return pylist;
}
/*****************************************************************************/
-/* Function: M_Window_GetViewMatrix */
-/* Python equivalent: Blender.Window.GetViewMatrix */
+/* Function: M_Window_GetViewMatrix */
+/* Python equivalent: Blender.Window.GetViewMatrix */
/*****************************************************************************/
static PyObject *M_Window_GetViewMatrix(PyObject *self)
{
PyObject *viewmat;
- if (!G.vd) {
+ if (!G.vd) {
Py_INCREF (Py_None);
return Py_None;
}
viewmat = newMatrixObject (G.vd->viewmat);
- if (!viewmat)
- return (EXPP_ReturnPyObjError (PyExc_MemoryError,
- "GetViewMatrix: couldn't create matrix pyobject"));
+ if (!viewmat)
+ return (EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "GetViewMatrix: couldn't create matrix pyobject"));
- return viewmat;
+ return viewmat;
}
/*****************************************************************************/
-/* Function: Window_Init */
+/* Function: Window_Init */
/*****************************************************************************/
PyObject *Window_Init (void)
{
- PyObject *submodule, *Types;
+ PyObject *submodule, *Types;
- submodule = Py_InitModule3("Blender.Window", M_Window_methods, M_Window_doc);
+ submodule = Py_InitModule3("Blender.Window", M_Window_methods, M_Window_doc);
- Types = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
- "VIEW3D", SPACE_VIEW3D, "IPO", SPACE_IPO, "OOPS", SPACE_OOPS,
- "BUTS", SPACE_BUTS, "FILE", SPACE_FILE, "IMAGE", SPACE_IMAGE,
- "INFO", SPACE_INFO, "SEQ", SPACE_SEQ, "IMASEL", SPACE_IMASEL,
- "SOUND", SPACE_SOUND, "ACTION", SPACE_ACTION,
- "TEXT", SPACE_TEXT, "NLA", SPACE_NLA);
+ Types = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
+ "VIEW3D", SPACE_VIEW3D, "IPO", SPACE_IPO, "OOPS", SPACE_OOPS,
+ "BUTS", SPACE_BUTS, "FILE", SPACE_FILE, "IMAGE", SPACE_IMAGE,
+ "INFO", SPACE_INFO, "SEQ", SPACE_SEQ, "IMASEL", SPACE_IMASEL,
+ "SOUND", SPACE_SOUND, "ACTION", SPACE_ACTION,
+ "TEXT", SPACE_TEXT, "NLA", SPACE_NLA, "SCRIPT", SPACE_SCRIPT);
- if (Types) PyModule_AddObject(submodule, "Types", Types);
+ if (Types) PyModule_AddObject(submodule, "Types", Types);
- return submodule;
+ return submodule;
}
diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c
index fdf624935ab..4e7d4de36d6 100644
--- a/source/blender/python/api2_2x/gen_utils.c
+++ b/source/blender/python/api2_2x/gen_utils.c
@@ -30,6 +30,7 @@
*/
#include "gen_utils.h"
+#include "constant.h"
/*****************************************************************************/
/* Description: This function clamps an int to the given interval */
@@ -184,13 +185,9 @@ PyObject *EXPP_tuple_repr(PyObject *self, int size)
Py_DECREF(item);
}
-
return repr;
-
}
-
-
/****************************************************************************/
/* Description: searches through a map for a pair with a given name. If the */
/* pair is present, its ival is stored in *ival and nonzero is */
@@ -238,20 +235,16 @@ int EXPP_map_getShortVal (const EXPP_map_pair *map,
/* and nonzero is returned. If the pair is absent, zero is */
/* returned. */
/****************************************************************************/
-int EXPP_map_getStrVal (const EXPP_map_pair *map,
- int ival, const char **sval)
+int EXPP_map_getStrVal (const EXPP_map_pair *map, int ival, const char **sval)
{
- while (map->sval)
+ while (map->sval)
+ {
+ if (ival == map->ival)
{
- if (ival == map->ival)
- {
- *sval = map->sval;
- return 1;
- }
- ++map;
+ *sval = map->sval;
+ return 1;
}
- return 0;
+ ++map;
+ }
+ return 0;
}
-
-
-
diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h
index 6c487c07489..161eea4de9c 100644
--- a/source/blender/python/api2_2x/gen_utils.h
+++ b/source/blender/python/api2_2x/gen_utils.h
@@ -33,6 +33,8 @@
#define EXPP_gen_utils_h
#include <Python.h>
+#include "compile.h"
+#include "eval.h" /* for PyEval_GetLocals */
#include <stdio.h>
#include <string.h>
@@ -41,6 +43,7 @@
#include <DNA_ID.h>
#include <DNA_object_types.h>
#include <DNA_material_types.h>
+#include <DNA_script_types.h>
#include <DNA_scriptlink_types.h>
#include <DNA_listBase.h>
@@ -63,7 +66,6 @@ int EXPP_ReturnIntError (PyObject *type, char *error_msg);
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
PyObject *EXPP_tuple_repr(PyObject *self, int size);
-
/* mapping utilities - see Texture.c for an example of how to use these */
typedef struct {
const char *sval;