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
This commit is contained in:
2003-12-14 01:18:09 +00:00
parent 6653af7914
commit 49021f7ec4
36 changed files with 1656 additions and 883 deletions

View File

@@ -41,6 +41,8 @@ struct ID; /* defined in DNA_ID.h */
struct ScriptLink; /* defined in DNA_scriptlink_types.h */
struct ListBase; /* defined in DNA_listBase.h */
struct SpaceText; /* defined in DNA_space_types.h */
struct SpaceScript;/* defined in DNA_space_types.h */
struct Script; /* defined in DNA_script_types.h */
/*
struct _object; // forward declaration for PyObject !
*/
@@ -51,7 +53,7 @@ void BPY_syspath_append_pythondir(void);
int BPY_Err_getLinenumber(void);
const char *BPY_Err_getFilename(void);
/* void BPY_Err_Handle(struct Text *text); */
struct _object *BPY_txt_do_python(struct SpaceText* st);
int BPY_txt_do_python(struct SpaceText* st);
void BPY_free_compiled_text(struct Text* text);
/*void BPY_clear_bad_scriptlink(struct ID *id, struct Text *byebye); */
void BPY_clear_bad_scriptlinks(struct Text *byebye);
@@ -64,8 +66,10 @@ void BPY_copy_scriptlink(struct ScriptLink *scriptlink);
/* format importer hook */
int BPY_call_importloader(char *name);
int BPY_spacetext_is_pywin(struct SpaceText *st);
void BPY_spacetext_do_pywin_draw(struct SpaceText *st);
void BPY_spacetext_do_pywin_event(struct SpaceText *st, unsigned short event, short val);
//int BPY_spacetext_is_pywin(struct SpaceText *st);
void BPY_spacescript_do_pywin_draw(struct SpaceScript *sc);
void BPY_spacescript_do_pywin_event(struct SpaceScript *sc, unsigned short event, short val);
void BPY_clear_script(struct Script *script);
void BPY_free_finished_script(struct Script *script);
void init_syspath(void);

View File

@@ -39,10 +39,10 @@
#include <stdio.h>
#include <MEM_guardedalloc.h>
#include <BLI_blenlib.h> /* for BLI_last_slash() */
#include <BKE_global.h>
#include <BKE_library.h>
#include <BKE_main.h>
#include <BKE_text.h>
#include <DNA_camera_types.h>
@@ -51,15 +51,17 @@
#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_text_types.h>
#include <DNA_world_types.h>
#include <DNA_userdef_types.h> /* for U.pythondir */
#include "BPY_extern.h"
#include "api2_2x/EXPP_interface.h"
#include "api2_2x/constant.h"
/* bpy_registryDict is declared in api2_2x/Registry.h and defined
* here. This Python dictionary will be used to store data that scripts
@@ -371,81 +373,77 @@ void BPY_Err_Handle(Text *text)
/* Notes: It is called by blender/src/drawtext.c when a Blender user */
/* presses ALT+PKEY in the script's text window. */
/*****************************************************************************/
struct _object *BPY_txt_do_python(struct SpaceText* st)
int BPY_txt_do_python(struct SpaceText* st)
{
PyObject *dict, *ret;
PyObject *main_dict = PyModule_GetDict(PyImport_AddModule("__main__"));
PyObject *py_dict, *py_result;
BPy_constant *tracer;
Script *script = G.main->script.first;
if (!st->text) return NULL;
if (!st->text) return 0;
/* The EXPP_releaseGlobalDict global variable controls whether we should run
* the script with a clean global dictionary or should keep the current one,
* possibly already "polluted" by other calls to the Python Interpreter.
* The default is to use a clean one. To change this the script writer must
* call Blender.ReleaseGlobalDict(bool), with bool == 0, in the script. */
/* check if this text is already running */
while (script) {
if (!strcmp(script->id.name+2, st->text->id.name+2)) {
/* if this text is already a running script, just move to it: */
EXPP_move_to_spacescript (script);
return 1;
}
script = script->id.next;
}
if (EXPP_releaseGlobalDict) {
printf("Using a clean Global Dictionary.\n");
st->flags |= ST_CLEAR_NAMESPACE;
dict = CreateGlobalDictionary();
}
else
dict = main_dict; /* must be careful not to free the main_dict */
/* Create a new script structure and initialize it: */
script = alloc_libblock(&G.main->script, ID_SCRIPT, GetName(st->text));
if (!script) {
printf("couldn't allocate memory for Script struct!");
return 0;
}
script->id.us = 1;
script->filename = NULL; /* it's a Blender Text script */
script->flags = SCRIPT_RUNNING;
script->py_draw = NULL;
script->py_event = NULL;
script->py_button = NULL;
py_dict = CreateGlobalDictionary();
script->py_globaldict = py_dict;
/* We will insert a constant dict at this script's namespace, with the name
* of the script. Later more info can be added, if necessary. */
tracer = (BPy_constant *)M_constant_New(); /*create a constant object*/
if (tracer) {
constant_insert(tracer, "name", PyString_FromString(script->id.name+2));
}
PyDict_SetItemString(py_dict, "__script__", (PyObject *)tracer);
clearScriptLinks ();
ret = RunPython (st->text, dict); /* Run the script */
py_result = RunPython (st->text, py_dict); /* Run the script */
if (!ret) { /* Failed execution of the script */
if (EXPP_releaseGlobalDict && (dict != main_dict))
ReleaseGlobalDictionary(dict);
if (!py_result) { /* Failed execution of the script */
BPY_Err_Handle(st->text);
ReleaseGlobalDictionary(py_dict);
free_libblock(&G.main->script, script);
BPY_end_python();
BPY_start_python();
return NULL;
}
return 0;
}
else {
Py_DECREF (py_result);
script->flags &=~SCRIPT_RUNNING;
if (!script->flags) {
ReleaseGlobalDictionary(py_dict);
script->py_globaldict = NULL;
free_libblock(&G.main->script, script);
}
}
else Py_DECREF (ret);
/* Scripts that use the GUI rely on the persistent global namespace, so
* they need a workaround: The namespace is released when the GUI is exit.'
* See api2_2x/Draw.c: Method_Register() */
/* Block below: The global dict should only be released if:
* - a script didn't defined it to be persistent and
* - Draw.Register() is not in use (no GUI) and
* - it is not the real __main__ dict (if it is, restart to clean it) */
if (EXPP_releaseGlobalDict) {
if (st->flags & ST_CLEAR_NAMESPACE) { /* False if the GUI is in use */
if (dict != main_dict) ReleaseGlobalDictionary(dict);
else {
BPY_end_python(); /* restart to get a fresh __main__ dict */
BPY_start_python();
}
}
}
else if (dict != main_dict) PyDict_Update (main_dict, dict);
/* Line above: if it should be kept and it's not already the __main__ dict,
* merge it into the __main__ one. This happens when to release is the
* current behavior and the script changes that with
* Blender.ReleaseGlobalDict(0). */
/* Edited from old BPY_main.c:
* 'The return value is the global namespace dictionary of the script
* context. This may be stored in the SpaceText instance to give control
* over namespace persistence. Remember that the same script may be
* executed in several windows ... Namespace persistence is desired for
* scripts that use the GUI and store callbacks to the current script.' */
return dict;
return 1; /* normal return */
}
/*****************************************************************************/
@@ -460,7 +458,6 @@ void BPY_free_compiled_text(struct Text* text)
return;
}
/*****************************************************************************/
/* ScriptLinks */
/*****************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@@ -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";

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);
strncpy(dirname, name, n);
dirname[n] = 0;
if (p) {
n = p - name;
return Py_BuildValue("s", dirname);
if (n > 255) {
PyErr_SetString(PyExc_RuntimeError, "path too long");
return 0;
}
strncpy(dirname, name, n);
dirname[n] = 0;
return Py_BuildValue("s", dirname);
}
return Py_BuildValue("s", "."); /* XXX need to fix this? (is crossplatform?)*/
}

View File

@@ -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;
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)"));
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)"));
st->flags &= ~ST_CLEAR_NAMESPACE; /* so global dict won't be cleared */
/* 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);
activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
sc = curarea->spacedata.first;
Py_INCREF(Py_None);
return Py_None;
/* 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;
}
script->flags |= SCRIPT_FILESEL;
activate_fileselect(FILE_BLENDER, title, G.sce, getSelectedFile);
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;
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)"));
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)"));
st->flags &= ~ST_CLEAR_NAMESPACE; /* hold global dictionary */
/* 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);
activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
sc = curarea->spacedata.first;
Py_INCREF(Py_None);
return Py_None;
/* 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;
}
script->flags |= SCRIPT_FILESEL; /* same flag as filesel */
activate_imageselect(FILE_BLENDER, title, G.sce, getSelectedFile);
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;
}

View File

@@ -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;
}

View File

@@ -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;