* Added 3 missing functions, 2 of them called by blender/src/drawtext.c:
Callbacks registered with Draw.Register in Python are called now. That should fix submodule Blender.Draw. * Added a few other missing functions to BPY_interface.c * Finished implementing Get() function for Camera, Lamp, Image and Text: Both the .Get(name) and .Get() cases are handled now. * Added function Blender.ReleaseGlobalDict(): This function should give script writers control over whether the global Python Interpreter Dict should be cleared after the script is run (default is to clear). This is a test.
This commit is contained in:
@@ -25,11 +25,15 @@
|
|||||||
*
|
*
|
||||||
* The Original Code is: source/blender/bpyton/include/BPY_extern.h
|
* The Original Code is: source/blender/bpyton/include/BPY_extern.h
|
||||||
*
|
*
|
||||||
* Contributor(s): Michel Selten
|
* Contributor(s): Michel Selten, Willian P. Germano
|
||||||
*
|
*
|
||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Global to control whether the global dictionary should be preserved or not
|
||||||
|
* each time a script is executed by the Python Interpreter: */
|
||||||
|
extern short EXPP_releaseGlobalDict; /* defaults to TRUE */
|
||||||
|
|
||||||
struct Text; /* defined in DNA_text_types.h */
|
struct Text; /* defined in DNA_text_types.h */
|
||||||
struct ID; /* defined in DNA_ID.h */
|
struct ID; /* defined in DNA_ID.h */
|
||||||
struct ScriptLink; /* defined in DNA_scriptlink_types.h */
|
struct ScriptLink; /* defined in DNA_scriptlink_types.h */
|
||||||
@@ -57,7 +61,9 @@ void BPY_copy_scriptlink(struct ScriptLink *scriptlink);
|
|||||||
/* format importer hook */
|
/* format importer hook */
|
||||||
int BPY_call_importloader(char *name);
|
int BPY_call_importloader(char *name);
|
||||||
|
|
||||||
|
/* XXX The 3 functions below are implemented in Draw.c */
|
||||||
|
/*
|
||||||
int BPY_spacetext_is_pywin(struct SpaceText *st);
|
int BPY_spacetext_is_pywin(struct SpaceText *st);
|
||||||
void BPY_spacetext_do_pywin_draw(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);
|
void BPY_spacetext_do_pywin_event(struct SpaceText *st, unsigned short event, short val);
|
||||||
|
*/
|
||||||
|
@@ -31,7 +31,11 @@
|
|||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
#include "compile.h" /* for the PyCodeObject */
|
||||||
|
#include "eval.h" /* for PyEval_EvalCode */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <MEM_guardedalloc.h>
|
#include <MEM_guardedalloc.h>
|
||||||
@@ -51,9 +55,9 @@
|
|||||||
#include <DNA_world_types.h>
|
#include <DNA_world_types.h>
|
||||||
|
|
||||||
#include "BPY_extern.h"
|
#include "BPY_extern.h"
|
||||||
|
|
||||||
#include "api2_2x/EXPP_interface.h"
|
#include "api2_2x/EXPP_interface.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Structure definitions */
|
/* Structure definitions */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -67,6 +71,7 @@ typedef struct _ScriptError {
|
|||||||
/* Global variables */
|
/* Global variables */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
ScriptError g_script_error;
|
ScriptError g_script_error;
|
||||||
|
short EXPP_releaseGlobalDict = 1;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
@@ -92,7 +97,7 @@ void BPY_start_python(void)
|
|||||||
|
|
||||||
initBlenderApi2_2x ();
|
initBlenderApi2_2x ();
|
||||||
|
|
||||||
return;
|
return; /* We could take away all these return; ... */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -124,49 +129,169 @@ const char *BPY_Err_getFilename(void)
|
|||||||
return g_script_error.filename;
|
return g_script_error.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Description: Return PyString filename from a traceback object */
|
||||||
|
/*****************************************************************************/
|
||||||
|
PyObject *traceback_getFilename(PyObject *tb)
|
||||||
|
{
|
||||||
|
PyObject *v;
|
||||||
|
|
||||||
|
/* co_filename is in f_code, which is in tb_frame, which is in tb */
|
||||||
|
|
||||||
|
v = PyObject_GetAttrString(tb, "tb_frame"); Py_XDECREF(v);
|
||||||
|
v = PyObject_GetAttrString(v, "f_code"); Py_XDECREF(v);
|
||||||
|
v = PyObject_GetAttrString(v, "co_filename");
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Description: Blender Python error handler. This catches the error and */
|
||||||
|
/* stores filename and line number in a global */
|
||||||
|
/*****************************************************************************/
|
||||||
|
void BPY_Err_Handle(Text *text)
|
||||||
|
{
|
||||||
|
PyObject *exception, *err, *tb, *v;
|
||||||
|
|
||||||
|
PyErr_Fetch(&exception, &err, &tb);
|
||||||
|
|
||||||
|
if (!exception && !tb) {
|
||||||
|
printf("FATAL: spurious exception\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(g_script_error.filename, GetName(text));
|
||||||
|
|
||||||
|
if (exception && PyErr_GivenExceptionMatches(exception, PyExc_SyntaxError)) {
|
||||||
|
/* no traceback available when SyntaxError */
|
||||||
|
PyErr_Restore(exception, err, tb); /* takes away reference! */
|
||||||
|
PyErr_Print();
|
||||||
|
v = PyObject_GetAttrString(err, "lineno");
|
||||||
|
g_script_error.lineno = PyInt_AsLong(v);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
PyErr_NormalizeException(&exception, &err, &tb);
|
||||||
|
PyErr_Restore(exception, err, tb); // takes away reference!
|
||||||
|
PyErr_Print();
|
||||||
|
tb = PySys_GetObject("last_traceback");
|
||||||
|
Py_INCREF(tb);
|
||||||
|
|
||||||
|
/* From old bpython BPY_main.c:
|
||||||
|
* 'check traceback objects and look for last traceback in the
|
||||||
|
* same text file. This is used to jump to the line of where the
|
||||||
|
* error occured. "If the error occured in another text file or module,
|
||||||
|
* the last frame in the current file is adressed."' */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
v = PyObject_GetAttrString(tb, "tb_next");
|
||||||
|
|
||||||
|
if (v == Py_None ||
|
||||||
|
strcmp(PyString_AsString(traceback_getFilename(v)), GetName(text)))
|
||||||
|
break;
|
||||||
|
Py_DECREF(tb);
|
||||||
|
tb = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
v = PyObject_GetAttrString(tb, "tb_lineno");
|
||||||
|
g_script_error.lineno = PyInt_AsLong(v);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
v = traceback_getFilename(tb);
|
||||||
|
strncpy(g_script_error.filename, PyString_AsString(v), FILENAME_LENGTH);
|
||||||
|
Py_XDECREF(v);
|
||||||
|
Py_DECREF(tb);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: This function executes the script passed by st. */
|
/* Description: This function executes the script passed by st. */
|
||||||
/* Notes: Currently, the script is compiled each time it is executed, */
|
/* Notes: It is called by blender/src/drawtext.c when a Blender user */
|
||||||
/* This should be optimized to store the compiled bytecode as */
|
/* presses ALT+PKEY in the script's text window. */
|
||||||
/* has been done by the previous implementation. */
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
struct _object *BPY_txt_do_python(struct SpaceText* st)
|
struct _object *BPY_txt_do_python(struct SpaceText* st)
|
||||||
{
|
{
|
||||||
PyObject * dict;
|
PyObject *dict, *ret;
|
||||||
PyObject * ret;
|
|
||||||
printf ("In BPY_txt_do_python\n");
|
printf ("In BPY_txt_do_python\n");
|
||||||
|
|
||||||
if (!st->text)
|
if (!st->text) return NULL;
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
if (EXPP_releaseGlobalDict) {
|
||||||
|
printf("Using a clean Global Dictionary.\n");
|
||||||
|
st->flags |= ST_CLEAR_NAMESPACE;
|
||||||
|
dict = CreateGlobalDictionary();
|
||||||
|
}
|
||||||
|
else
|
||||||
dict = PyModule_GetDict(PyImport_AddModule("__main__"));
|
dict = PyModule_GetDict(PyImport_AddModule("__main__"));
|
||||||
/* dict = newGlobalDictionary(); */
|
|
||||||
ret = RunPython (st->text, dict);
|
|
||||||
|
|
||||||
/* If errors have occurred, set the error filename to the name of the
|
ret = RunPython (st->text, dict); /* Run the script */
|
||||||
script.
|
|
||||||
*/
|
if (!ret) { /* Failed execution of the script */
|
||||||
if (!ret)
|
|
||||||
{
|
if (EXPP_releaseGlobalDict) ReleaseGlobalDictionary(dict);
|
||||||
sprintf(g_script_error.filename, "%s", st->text->id.name+2);
|
|
||||||
|
BPY_Err_Handle(st->text);
|
||||||
|
BPY_end_python();
|
||||||
|
BPY_start_python();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else Py_DECREF (ret);
|
||||||
|
|
||||||
|
/* From the old BPY_main.c:
|
||||||
|
* 'The following lines clear the global name space of the python
|
||||||
|
* interpreter. This is desired to release objects after execution
|
||||||
|
* of a script (remember that each wrapper object increments the refcount
|
||||||
|
* of the Blender Object.
|
||||||
|
* Exception: 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() */
|
||||||
|
|
||||||
|
if (EXPP_releaseGlobalDict) {
|
||||||
|
if (st->flags & ST_CLEAR_NAMESPACE) {
|
||||||
|
ReleaseGlobalDictionary(dict);
|
||||||
|
/*garbage_collect(&G.main); Unfinished in the previous implementation */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void BPY_free_compiled_text(struct Text* text)
|
void BPY_free_compiled_text(struct Text* text)
|
||||||
{
|
{
|
||||||
printf ("In BPY_free_compiled_text\n");
|
printf ("In BPY_free_compiled_text\n");
|
||||||
|
if (!text->compiled) return;
|
||||||
|
Py_DECREF((PyObject*) text->compiled);
|
||||||
|
text->compiled = NULL;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* ScriptLinks */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: Not implemented yet */
|
||||||
@@ -174,6 +299,16 @@ void BPY_free_compiled_text(struct Text* text)
|
|||||||
void BPY_clear_bad_scriptlinks(struct Text *byebye)
|
void BPY_clear_bad_scriptlinks(struct Text *byebye)
|
||||||
{
|
{
|
||||||
printf ("In BPY_clear_bad_scriptlinks\n");
|
printf ("In BPY_clear_bad_scriptlinks\n");
|
||||||
|
/*
|
||||||
|
BPY_clear_bad_scriptlist(getObjectList(), byebye);
|
||||||
|
BPY_clear_bad_scriptlist(getLampList(), byebye);
|
||||||
|
BPY_clear_bad_scriptlist(getCameraList(), byebye);
|
||||||
|
BPY_clear_bad_scriptlist(getMaterialList(), byebye);
|
||||||
|
BPY_clear_bad_scriptlist(getWorldList(), byebye);
|
||||||
|
BPY_clear_bad_scriptlink(&scene_getCurrent()->id, byebye);
|
||||||
|
|
||||||
|
allqueue(REDRAWBUTSSCRIPT, 0);
|
||||||
|
*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +329,7 @@ void BPY_do_all_scripts(short event)
|
|||||||
DoAllScriptsFromList (&(G.main->world), event);
|
DoAllScriptsFromList (&(G.main->world), event);
|
||||||
|
|
||||||
BPY_do_pyscript (&(G.scene->id), event);
|
BPY_do_pyscript (&(G.scene->id), event);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,10 +350,7 @@ void BPY_do_pyscript(struct ID *id, short event)
|
|||||||
|
|
||||||
scriptlink = setScriptLinks (id, event);
|
scriptlink = setScriptLinks (id, event);
|
||||||
|
|
||||||
if (scriptlink == NULL)
|
if (scriptlink == NULL) return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index = 0; index < scriptlink->totscript; index++)
|
for (index = 0; index < scriptlink->totscript; index++)
|
||||||
{
|
{
|
||||||
@@ -237,21 +370,43 @@ void BPY_do_pyscript(struct ID *id, short event)
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void BPY_free_scriptlink(struct ScriptLink *slink)
|
void BPY_free_scriptlink(struct ScriptLink *slink)
|
||||||
{
|
{
|
||||||
printf ("In BPY_free_scriptlink\n");
|
printf ("In BPY_free_scriptlink\n");
|
||||||
|
|
||||||
|
if (slink->totscript) {
|
||||||
|
if(slink->flag) MEM_freeN(slink->flag);
|
||||||
|
if(slink->scripts) MEM_freeN(slink->scripts);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void BPY_copy_scriptlink(struct ScriptLink *scriptlink)
|
void BPY_copy_scriptlink(struct ScriptLink *scriptlink)
|
||||||
{
|
{
|
||||||
|
void *tmp;
|
||||||
|
|
||||||
printf ("In BPY_copy_scriptlink\n");
|
printf ("In BPY_copy_scriptlink\n");
|
||||||
|
|
||||||
|
if (scriptlink->totscript) {
|
||||||
|
|
||||||
|
tmp = scriptlink->scripts;
|
||||||
|
scriptlink->scripts =
|
||||||
|
MEM_mallocN(sizeof(ID*)*scriptlink->totscript, "scriptlistL");
|
||||||
|
memcpy(scriptlink->scripts, tmp, sizeof(ID*)*scriptlink->totscript);
|
||||||
|
|
||||||
|
tmp = scriptlink->flag;
|
||||||
|
scriptlink->flag =
|
||||||
|
MEM_mallocN(sizeof(short)*scriptlink->totscript, "scriptlistF");
|
||||||
|
memcpy(scriptlink->flag, tmp, sizeof(short)*scriptlink->totscript);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,43 +415,45 @@ void BPY_copy_scriptlink(struct ScriptLink *scriptlink)
|
|||||||
/* Notes: Not implemented yet */
|
/* Notes: Not implemented yet */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int BPY_call_importloader(char *name)
|
int BPY_call_importloader(char *name)
|
||||||
{
|
{ /* XXX Should this function go away from Blender? */
|
||||||
printf ("In BPY_call_importloader(name=%s)\n",name);
|
printf ("In BPY_call_importloader(name=%s)\n",name);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/* XXX THE 3 FUNCTIONS BELOW ARE IMPLEMENTED IN DRAW.C */
|
||||||
/* Description: */
|
|
||||||
/* Notes: Not implemented yet */
|
|
||||||
/*****************************************************************************/
|
|
||||||
int BPY_spacetext_is_pywin(struct SpaceText *st)
|
|
||||||
{
|
|
||||||
/* No printf is done here because it is called with every mouse move */
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: Not implemented yet */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void BPY_spacetext_do_pywin_draw(struct SpaceText *st)
|
//int BPY_spacetext_is_pywin(struct SpaceText *st)
|
||||||
{
|
//{
|
||||||
printf ("In BPY_spacetext_do_pywin_draw\n");
|
// /* No printf is done here because it is called with every mouse move */
|
||||||
return;
|
// return (0);
|
||||||
}
|
//}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Description: */
|
/* Description: */
|
||||||
/* Notes: Not implemented yet */
|
/* Notes: Not implemented yet */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
void BPY_spacetext_do_pywin_event(struct SpaceText *st,
|
//void BPY_spacetext_do_pywin_draw(struct SpaceText *st)
|
||||||
unsigned short event,
|
//{
|
||||||
short val)
|
// printf ("In BPY_spacetext_do_pywin_draw\n");
|
||||||
{
|
// return;
|
||||||
printf ("In BPY_spacetext_do_pywin_event(st=?, event=%d, val=%d)\n",
|
//}
|
||||||
event, val);
|
|
||||||
return;
|
/*****************************************************************************/
|
||||||
}
|
/* Description: */
|
||||||
|
/* Notes: Not implemented yet */
|
||||||
|
/*****************************************************************************/
|
||||||
|
//void BPY_spacetext_do_pywin_event(struct SpaceText *st,
|
||||||
|
// unsigned short event,
|
||||||
|
// short val)
|
||||||
|
//{
|
||||||
|
// printf ("In BPY_spacetext_do_pywin_event(st=?, event=%d, val=%d)\n",
|
||||||
|
// event, val);
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Private functions */
|
/* Private functions */
|
||||||
@@ -309,26 +466,30 @@ void BPY_spacetext_do_pywin_event(struct SpaceText *st,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
PyObject * RunPython(Text *text, PyObject *globaldict)
|
PyObject * RunPython(Text *text, PyObject *globaldict)
|
||||||
{
|
{
|
||||||
PyObject * ret;
|
char *buf = NULL;
|
||||||
char * buf;
|
|
||||||
|
|
||||||
printf("Run Python script \"%s\" ...\n", GetName(text));
|
printf("Run Python script \"%s\" ...\n", GetName(text));
|
||||||
buf = txt_to_buf(text);
|
|
||||||
ret = PyRun_String (buf, Py_file_input, globaldict, globaldict);
|
|
||||||
|
|
||||||
if (!ret)
|
/* The script text is compiled to Python bytecode and saved at text->compiled
|
||||||
{
|
* to speed-up execution if the user executes the script multiple times */
|
||||||
/* an exception was raised, handle it here */
|
|
||||||
PyErr_Print(); /* this function also clears the error
|
if (!text->compiled) { /* if it wasn't already compiled, do it now */
|
||||||
indicator */
|
buf = txt_to_buf(text);
|
||||||
}
|
|
||||||
else
|
text->compiled = Py_CompileString(buf, GetName(text), Py_file_input);
|
||||||
{
|
|
||||||
PyErr_Clear(); /* seems necessary, at least now */
|
|
||||||
}
|
|
||||||
|
|
||||||
MEM_freeN(buf);
|
MEM_freeN(buf);
|
||||||
return ret;
|
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
BPY_free_compiled_text(text);
|
||||||
|
PyErr_SetString (PyExc_RuntimeError,
|
||||||
|
"couldn't compile script to Python bytecode");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return PyEval_EvalCode(text->compiled, globaldict, globaldict);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -346,10 +507,11 @@ char * GetName(Text *text)
|
|||||||
PyObject * CreateGlobalDictionary (void)
|
PyObject * CreateGlobalDictionary (void)
|
||||||
{
|
{
|
||||||
PyObject *dict = PyDict_New();
|
PyObject *dict = PyDict_New();
|
||||||
|
|
||||||
PyDict_SetItemString (dict, "__builtins__", PyEval_GetBuiltins());
|
PyDict_SetItemString (dict, "__builtins__", PyEval_GetBuiltins());
|
||||||
PyDict_SetItemString (dict, "__name__", PyString_FromString("__main__"));
|
PyDict_SetItemString (dict, "__name__", PyString_FromString("__main__"));
|
||||||
|
|
||||||
return (dict);
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -359,6 +521,8 @@ void ReleaseGlobalDictionary (PyObject * dict)
|
|||||||
{
|
{
|
||||||
PyDict_Clear (dict);
|
PyDict_Clear (dict);
|
||||||
Py_DECREF (dict); /* Release dictionary. */
|
Py_DECREF (dict); /* Release dictionary. */
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -372,10 +536,11 @@ void DoAllScriptsFromList (ListBase * list, short event)
|
|||||||
|
|
||||||
id = list->first;
|
id = list->first;
|
||||||
|
|
||||||
while (id != NULL)
|
while (id != NULL) {
|
||||||
{
|
|
||||||
BPY_do_pyscript (id, event);
|
BPY_do_pyscript (id, event);
|
||||||
id = id->next;
|
id = id->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -337,7 +337,10 @@ static PyObject *Buffer_repr(PyObject *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* BGL_Wrap defined in BGL.h */
|
/* BGL_Wrap defined in BGL.h */
|
||||||
#ifndef __APPLE__
|
|
||||||
|
/* Let's try to take away this ifndef: */
|
||||||
|
/* #ifndef __APPLE__ */
|
||||||
|
|
||||||
BGL_Wrap(2, Accum, void, (GLenum, GLfloat))
|
BGL_Wrap(2, Accum, void, (GLenum, GLfloat))
|
||||||
BGL_Wrap(2, AlphaFunc, void, (GLenum, GLclampf))
|
BGL_Wrap(2, AlphaFunc, void, (GLenum, GLclampf))
|
||||||
BGL_Wrap(3, AreTexturesResident, GLboolean, (GLsizei, GLuintP, GLbooleanP))
|
BGL_Wrap(3, AreTexturesResident, GLboolean, (GLsizei, GLuintP, GLbooleanP))
|
||||||
@@ -663,7 +666,8 @@ BGL_Wrap(1, Vertex4iv, void, (GLintP))
|
|||||||
BGL_Wrap(4, Vertex4s, void, (GLshort, GLshort, GLshort, GLshort))
|
BGL_Wrap(4, Vertex4s, void, (GLshort, GLshort, GLshort, GLshort))
|
||||||
BGL_Wrap(1, Vertex4sv, void, (GLshortP))
|
BGL_Wrap(1, Vertex4sv, void, (GLshortP))
|
||||||
BGL_Wrap(4, Viewport, void, (GLint, GLint, GLsizei, GLsizei))
|
BGL_Wrap(4, Viewport, void, (GLint, GLint, GLsizei, GLsizei))
|
||||||
#endif
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
#undef MethodDef
|
#undef MethodDef
|
||||||
#define MethodDef(func) {"gl"#func, Method_##func, METH_VARARGS}
|
#define MethodDef(func) {"gl"#func, Method_##func, METH_VARARGS}
|
||||||
@@ -673,7 +677,9 @@ BGL_Wrap(4, Viewport, void, (GLint, GLint, GLsizei, GLsizei))
|
|||||||
|
|
||||||
static struct PyMethodDef BGL_methods[] = {
|
static struct PyMethodDef BGL_methods[] = {
|
||||||
{"Buffer", Method_Buffer, METH_VARARGS, Method_Buffer_doc},
|
{"Buffer", Method_Buffer, METH_VARARGS, Method_Buffer_doc},
|
||||||
#ifndef __APPLE__
|
|
||||||
|
/* #ifndef __APPLE__ */
|
||||||
|
|
||||||
MethodDef( Accum),
|
MethodDef( Accum),
|
||||||
MethodDef( AlphaFunc),
|
MethodDef( AlphaFunc),
|
||||||
MethodDef( AreTexturesResident),
|
MethodDef( AreTexturesResident),
|
||||||
@@ -987,7 +993,8 @@ static struct PyMethodDef BGL_methods[] = {
|
|||||||
MethodDef( Vertex4s),
|
MethodDef( Vertex4s),
|
||||||
MethodDef( Vertex4sv),
|
MethodDef( Vertex4sv),
|
||||||
MethodDef( Viewport),
|
MethodDef( Viewport),
|
||||||
#endif
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
@@ -151,7 +151,8 @@ PyTypeObject Buffer_Type = {
|
|||||||
&Buffer_SeqMethods, /*tp_as_sequence*/
|
&Buffer_SeqMethods, /*tp_as_sequence*/
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef __APPLE__
|
/* #ifndef __APPLE__ */
|
||||||
|
|
||||||
/*@ By golly George! It looks like fancy pants macro time!!! */
|
/*@ By golly George! It looks like fancy pants macro time!!! */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -419,6 +420,6 @@ static PyObject *Method_##funcname (PyObject *self, PyObject *args) {\
|
|||||||
ret_ret_##ret; \
|
ret_ret_##ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
/* #endif */
|
||||||
|
|
||||||
PyObject *M_BGL_Init(void);
|
PyObject *M_BGL_Init(void);
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*
|
*
|
||||||
* This is a new part of Blender.
|
* This is a new part of Blender.
|
||||||
*
|
*
|
||||||
* Contributor(s): Michel Selten
|
* Contributor(s): Michel Selten, Willian P. Germano
|
||||||
*
|
*
|
||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
@@ -173,6 +173,31 @@ PyObject *Blender_Redraw(PyObject *self, PyObject *args)
|
|||||||
return M_Window_Redraw(self, Py_BuildValue("(i)", wintype));
|
return M_Window_Redraw(self, Py_BuildValue("(i)", wintype));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Function: Blender_ReleaseGlobalDict */
|
||||||
|
/* Python equivalent: Blender.ReleaseGlobalDict */
|
||||||
|
/* Description: Receives an int (treated as boolean) to define */
|
||||||
|
/* whether the global Python dictionary should be */
|
||||||
|
/* cleared after the script is run or not. Default */
|
||||||
|
/* is to clear (to release). To change this, call */
|
||||||
|
/* Blender.ReleaseGlobalDict with a non-zero int */
|
||||||
|
/* argument. If called with an empty arg list, it */
|
||||||
|
/* doesn't change anything. */
|
||||||
|
/* Returns the current behavior. */
|
||||||
|
/*****************************************************************************/
|
||||||
|
PyObject *Blender_ReleaseGlobalDict(PyObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
printf ("In Blender_ReleaseGlobalDict()\n");
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple (args, "|i", &EXPP_releaseGlobalDict))
|
||||||
|
{
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected int argument (or nothing)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Py_BuildValue("i", (EXPP_releaseGlobalDict?1:0));
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: initBlender */
|
/* Function: initBlender */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*
|
*
|
||||||
* This is a new part of Blender.
|
* This is a new part of Blender.
|
||||||
*
|
*
|
||||||
* Contributor(s): Michel Selten
|
* Contributor(s): Michel Selten, Willian P. Germano
|
||||||
*
|
*
|
||||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
@@ -50,12 +50,18 @@
|
|||||||
/* From Window.h, used here by Blender_Redraw */
|
/* From Window.h, used here by Blender_Redraw */
|
||||||
PyObject *M_Window_Redraw(PyObject *self, PyObject *args);
|
PyObject *M_Window_Redraw(PyObject *self, PyObject *args);
|
||||||
|
|
||||||
|
/* This global variable controls whether the global Interpreter dictionary
|
||||||
|
* should be cleared after a script is run. Default is to clear it.
|
||||||
|
* See Blender.ReleaseGlobalDict(bool) */
|
||||||
|
extern short EXPP_releaseGlobalDict;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Python API function prototypes for the Blender module. */
|
/* Python API function prototypes for the Blender module. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
PyObject *Blender_Set (PyObject *self, PyObject *args);
|
PyObject *Blender_Set (PyObject *self, PyObject *args);
|
||||||
PyObject *Blender_Get (PyObject *self, PyObject *args);
|
PyObject *Blender_Get (PyObject *self, PyObject *args);
|
||||||
PyObject *Blender_Redraw(PyObject *self, PyObject *args);
|
PyObject *Blender_Redraw(PyObject *self, PyObject *args);
|
||||||
|
PyObject *Blender_ReleaseGlobalDict(PyObject *self, PyObject *args);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* The following string definitions are used for documentation strings. */
|
/* The following string definitions are used for documentation strings. */
|
||||||
@@ -81,6 +87,12 @@ char Blender_Get_doc[] =
|
|||||||
|
|
||||||
char Blender_Redraw_doc[] = "() - Redraw all 3D windows";
|
char Blender_Redraw_doc[] = "() - Redraw all 3D windows";
|
||||||
|
|
||||||
|
char Blender_ReleaseGlobalDict_doc[] =
|
||||||
|
"(int) - Define whether the global Python Interpreter dictionary\n\
|
||||||
|
should be cleared after the script is run. Default is\n\
|
||||||
|
to clear (non-zero int).\n\
|
||||||
|
() - Return the current behavior as a bool value (0 is false, 1 is true)\n";
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Python method structure definition. */
|
/* Python method structure definition. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -88,6 +100,8 @@ struct PyMethodDef Blender_methods[] = {
|
|||||||
{"Set", &Blender_Set, METH_VARARGS, Blender_Set_doc},
|
{"Set", &Blender_Set, METH_VARARGS, Blender_Set_doc},
|
||||||
{"Get", &Blender_Get, METH_VARARGS, Blender_Get_doc},
|
{"Get", &Blender_Get, METH_VARARGS, Blender_Get_doc},
|
||||||
{"Redraw", &Blender_Redraw, METH_VARARGS, Blender_Redraw_doc},
|
{"Redraw", &Blender_Redraw, METH_VARARGS, Blender_Redraw_doc},
|
||||||
|
{"ReleaseGlobalDict", &Blender_ReleaseGlobalDict,
|
||||||
|
METH_VARARGS, Blender_ReleaseGlobalDict_doc},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -87,29 +87,31 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *keywords
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Camera_Get */
|
/* Function: M_Camera_Get */
|
||||||
/* Python equivalent: Blender.Camera.Get */
|
/* Python equivalent: Blender.Camera.Get */
|
||||||
|
/* Description: Receives a string and returns the camera data obj */
|
||||||
|
/* whose name matches the string. If no argument is */
|
||||||
|
/* passed in, a list of all camera data names in the */
|
||||||
|
/* current scene is returned. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
|
static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name = NULL;
|
||||||
Camera *cam_iter;
|
Camera *cam_iter;
|
||||||
C_Camera *wanted_cam;
|
|
||||||
|
|
||||||
printf ("In Camera_Get()\n");
|
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
"expected string argument (or nothing)"));
|
||||||
"expected string argument"));
|
|
||||||
|
|
||||||
/* Use the name to search for the camera requested */
|
|
||||||
wanted_cam = NULL;
|
|
||||||
cam_iter = G.main->camera.first;
|
cam_iter = G.main->camera.first;
|
||||||
|
|
||||||
while ((cam_iter) && (wanted_cam == NULL)) {
|
if (name) { /* (name) - Search camera by name */
|
||||||
|
|
||||||
|
C_Camera *wanted_cam = NULL;
|
||||||
|
|
||||||
|
while ((cam_iter) && (wanted_cam == NULL)) {
|
||||||
if (strcmp (name, cam_iter->id.name+2) == 0) {
|
if (strcmp (name, cam_iter->id.name+2) == 0) {
|
||||||
wanted_cam = (C_Camera *)PyObject_NEW(C_Camera, &Camera_Type);
|
wanted_cam = (C_Camera *)PyObject_NEW(C_Camera, &Camera_Type);
|
||||||
if (wanted_cam) wanted_cam->camera = cam_iter;
|
if (wanted_cam) wanted_cam->camera = cam_iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
cam_iter = cam_iter->id.next;
|
cam_iter = cam_iter->id.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +125,33 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
|
|||||||
return (PyObject *)wanted_cam;
|
return (PyObject *)wanted_cam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else { /* () - return a list of all cameras in the scene */
|
||||||
|
int index = 0;
|
||||||
|
PyObject *camlist, *pystr;
|
||||||
|
|
||||||
|
camlist = PyList_New (BLI_countlist (&(G.main->camera)));
|
||||||
|
|
||||||
|
if (camlist == NULL)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyList"));
|
||||||
|
|
||||||
|
while (cam_iter) {
|
||||||
|
pystr = PyString_FromString (cam_iter->id.name+2);
|
||||||
|
|
||||||
|
if (!pystr)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyString"));
|
||||||
|
|
||||||
|
PyList_SET_ITEM (camlist, index, pystr);
|
||||||
|
|
||||||
|
cam_iter = cam_iter->id.next;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (camlist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Camera_Init */
|
/* Function: M_Camera_Init */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -216,7 +245,7 @@ static PyObject *Camera_rename(C_Camera *self, PyObject *args)
|
|||||||
char buf[21];
|
char buf[21];
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||||
@@ -232,7 +261,7 @@ static PyObject *Camera_setType(C_Camera *self, PyObject *args)
|
|||||||
char *type;
|
char *type;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &type))
|
if (!PyArg_ParseTuple(args, "s", &type))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
if (strcmp (type, "persp") == 0)
|
if (strcmp (type, "persp") == 0)
|
||||||
@@ -257,13 +286,13 @@ static PyObject *Camera_setIntType(C_Camera *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument: 0 or 1"));
|
"expected int argument: 0 or 1"));
|
||||||
|
|
||||||
if (value == 0 || value == 1)
|
if (value == 0 || value == 1)
|
||||||
self->camera->type = value;
|
self->camera->type = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument: 0 or 1"));
|
"expected int argument: 0 or 1"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -312,13 +341,13 @@ static PyObject *Camera_setIntMode(C_Camera *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [0,3]"));
|
"expected int argument in [0,3]"));
|
||||||
|
|
||||||
if (value >= 0 && value <= 3)
|
if (value >= 0 && value <= 3)
|
||||||
self->camera->flag = value;
|
self->camera->flag = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [0,3]"));
|
"expected int argument in [0,3]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -330,7 +359,7 @@ static PyObject *Camera_setLens(C_Camera *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
self->camera->lens = EXPP_ClampFloat (value,
|
self->camera->lens = EXPP_ClampFloat (value,
|
||||||
@@ -345,7 +374,7 @@ static PyObject *Camera_setClipStart(C_Camera *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
self->camera->clipsta = EXPP_ClampFloat (value,
|
self->camera->clipsta = EXPP_ClampFloat (value,
|
||||||
@@ -360,7 +389,7 @@ static PyObject *Camera_setClipEnd(C_Camera *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
self->camera->clipend = EXPP_ClampFloat (value,
|
self->camera->clipend = EXPP_ClampFloat (value,
|
||||||
@@ -375,7 +404,7 @@ static PyObject *Camera_setDrawSize(C_Camera *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected a float number as argument"));
|
||||||
|
|
||||||
self->camera->drawsize = EXPP_ClampFloat (value,
|
self->camera->drawsize = EXPP_ClampFloat (value,
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
#include <BKE_global.h>
|
#include <BKE_global.h>
|
||||||
#include <BKE_object.h>
|
#include <BKE_object.h>
|
||||||
#include <BKE_library.h>
|
#include <BKE_library.h>
|
||||||
|
#include <BLI_blenlib.h>
|
||||||
#include <DNA_camera_types.h>
|
#include <DNA_camera_types.h>
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
|
@@ -114,20 +114,26 @@ static void exit_pydraw(SpaceText *st)
|
|||||||
|
|
||||||
static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args)
|
static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *result= PyEval_CallObject(callback, args);
|
PyObject *result = PyObject_CallObject (callback, args);
|
||||||
|
printf ("In exec_callback\n");
|
||||||
if (result==NULL) {
|
if (result==NULL) {
|
||||||
|
printf("In exec_callback, result == NULL\n");
|
||||||
st->text->compiled= NULL;
|
st->text->compiled= NULL;
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
exit_pydraw(st);
|
exit_pydraw(st);
|
||||||
}
|
}
|
||||||
|
printf ("In exec_callback 2\n");
|
||||||
Py_XDECREF(result);
|
Py_XDECREF(result);
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@ the handler for drawing routines (see Register method) */
|
/* BPY_spacetext_do_pywin_draw, the static spacetext_do_pywin_buttons and
|
||||||
|
* BPY_spacetext_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 */
|
||||||
|
|
||||||
void EXPP_spacetext_do_pywin_draw(SpaceText *st)
|
void BPY_spacetext_do_pywin_draw(SpaceText *st)
|
||||||
{
|
{
|
||||||
uiBlock *block;
|
uiBlock *block;
|
||||||
char butblock[20];
|
char butblock[20];
|
||||||
@@ -150,8 +156,6 @@ void EXPP_spacetext_do_pywin_draw(SpaceText *st)
|
|||||||
curarea->win_swap= WIN_BACK_OK;
|
curarea->win_swap= WIN_BACK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@ the handler for button event routines (see Register method) */
|
|
||||||
|
|
||||||
static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event)
|
static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event)
|
||||||
{
|
{
|
||||||
if (st->py_button) {
|
if (st->py_button) {
|
||||||
@@ -159,9 +163,7 @@ static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@ calls the generic event handling methods registered with Register */
|
void BPY_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val)
|
||||||
|
|
||||||
void EXPP_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val)
|
|
||||||
{
|
{
|
||||||
if (event==QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) {
|
if (event==QKEY && G.qual & (LR_ALTKEY|LR_CTRLKEY|LR_SHIFTKEY)) {
|
||||||
exit_pydraw(st);
|
exit_pydraw(st);
|
||||||
@@ -171,23 +173,22 @@ void EXPP_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short va
|
|||||||
if (val) {
|
if (val) {
|
||||||
if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
|
if (uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
|
||||||
|
|
||||||
if (event==UI_BUT_EVENT) {
|
if (event==UI_BUT_EVENT)
|
||||||
spacetext_do_pywin_buttons(st, val);
|
spacetext_do_pywin_buttons(st, val);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (st->py_event) {
|
if (st->py_event)
|
||||||
exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val));
|
exec_callback(st, st->py_event, Py_BuildValue("(ii)", event, val));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int EXPP_spacetext_is_pywin(SpaceText *st)
|
int BPY_spacetext_is_pywin(SpaceText *st)
|
||||||
{
|
{
|
||||||
return (st->py_draw || st->py_event || st->py_button);
|
return (st->py_draw || st->py_event || st->py_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPP_TRY(x) if((!(x))) \
|
/* the define CLEAR_NAMESPACE is currently ignored. It should be
|
||||||
return EXPP_ReturnPyObjError(PyExc_AttributeError, "in module Blender.Draw")
|
* substituted by a better method, that was also the intention of the
|
||||||
|
* programmer(s) who put it there. */
|
||||||
|
|
||||||
static PyObject *Method_Exit (PyObject *self, PyObject *args)
|
static PyObject *Method_Exit (PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
@@ -195,7 +196,9 @@ static PyObject *Method_Exit (PyObject *self, PyObject *args)
|
|||||||
#ifdef CLEAR_NAMESPACE
|
#ifdef CLEAR_NAMESPACE
|
||||||
PyObject *d;
|
PyObject *d;
|
||||||
#endif
|
#endif
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, ""));
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
|
"expected empty argument list");
|
||||||
|
|
||||||
exit_pydraw(st);
|
exit_pydraw(st);
|
||||||
#ifdef CLEAR_NAMESPACE
|
#ifdef CLEAR_NAMESPACE
|
||||||
@@ -214,8 +217,10 @@ static PyObject *Method_Register (PyObject *self, PyObject *args)
|
|||||||
PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL;
|
PyObject *newdrawc= NULL, *neweventc= NULL, *newbuttonc= NULL;
|
||||||
SpaceText *st= curarea->spacedata.first;
|
SpaceText *st= curarea->spacedata.first;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "O|OO", &newdrawc,
|
if (!PyArg_ParseTuple(args, "O|OO", &newdrawc,
|
||||||
&neweventc, &newbuttonc));
|
&neweventc, &newbuttonc))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected one or three PyObjects");
|
||||||
|
|
||||||
/*@This is a hack again:
|
/*@This is a hack again:
|
||||||
* Every python script should actually do a global variable cleanup at
|
* Every python script should actually do a global variable cleanup at
|
||||||
@@ -261,7 +266,9 @@ static PyObject *Method_Redraw (PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
int after= 0;
|
int after= 0;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "|i", &after));
|
if (!PyArg_ParseTuple(args, "|i", &after))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected int argument (or nothing)");
|
||||||
|
|
||||||
if (after) addafterqueue(curarea->win, REDRAW, 1);
|
if (after) addafterqueue(curarea->win, REDRAW, 1);
|
||||||
else scrarea_queue_winredraw(curarea);
|
else scrarea_queue_winredraw(curarea);
|
||||||
@@ -273,11 +280,14 @@ static PyObject *Method_Draw (PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
/*@ If forced drawing is disable queue a redraw event instead */
|
/*@ If forced drawing is disable queue a redraw event instead */
|
||||||
if (EXPP_disable_force_draw) {
|
if (EXPP_disable_force_draw) {
|
||||||
|
printf ("\nEXPP_disable_force_draw\n");
|
||||||
scrarea_queue_winredraw(curarea);
|
scrarea_queue_winredraw(curarea);
|
||||||
return EXPP_incr_ret (Py_None);
|
return EXPP_incr_ret (Py_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, ""));
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
|
"expected empty argument list");
|
||||||
|
|
||||||
scrarea_do_windraw(curarea);
|
scrarea_do_windraw(curarea);
|
||||||
|
|
||||||
@@ -291,7 +301,9 @@ static PyObject *Method_Create (PyObject *self, PyObject *args)
|
|||||||
Button *but;
|
Button *but;
|
||||||
PyObject *in;
|
PyObject *in;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "O", &in));
|
if (!PyArg_ParseTuple(args, "O", &in))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected PyObject argument");
|
||||||
|
|
||||||
but= newbutton();
|
but= newbutton();
|
||||||
if(PyFloat_Check(in)) {
|
if(PyFloat_Check(in)) {
|
||||||
@@ -329,8 +341,10 @@ static PyObject *Method_Button (PyObject *self, PyObject *args)
|
|||||||
int event;
|
int event;
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiii|s", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiii|s", &name, &event,
|
||||||
&x, &y, &w, &h, &tip));
|
&x, &y, &w, &h, &tip))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected a string, five ints and optionally another string as arguments");
|
||||||
|
|
||||||
block= Get_uiBlock();
|
block= Get_uiBlock();
|
||||||
|
|
||||||
@@ -348,8 +362,10 @@ static PyObject *Method_Menu (PyObject *self, PyObject *args)
|
|||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
Button *but;
|
Button *but;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
|
||||||
&x, &y, &w, &h, &def, &tip));
|
&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= newbutton();
|
||||||
but->type= 1;
|
but->type= 1;
|
||||||
@@ -370,8 +386,10 @@ static PyObject *Method_Toggle (PyObject *self, PyObject *args)
|
|||||||
int x, y, w, h, def;
|
int x, y, w, h, def;
|
||||||
Button *but;
|
Button *but;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiiii|s", &name, &event,
|
||||||
&x, &y, &w, &h, &def, &tip));
|
&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= newbutton();
|
||||||
but->type= 1;
|
but->type= 1;
|
||||||
@@ -425,9 +443,11 @@ static PyObject *Method_Slider (PyObject *self, PyObject *args)
|
|||||||
Button *but;
|
Button *but;
|
||||||
PyObject *mino, *maxo, *inio;
|
PyObject *mino, *maxo, *inio;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiiiOOO|is", &name, &event,
|
||||||
&x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip));
|
&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();
|
but= newbutton();
|
||||||
if (PyFloat_Check(inio)) {
|
if (PyFloat_Check(inio)) {
|
||||||
@@ -479,7 +499,11 @@ static PyObject *Method_Scrollbar (PyObject *self, PyObject *args)
|
|||||||
PyObject *mino, *maxo, *inio;
|
PyObject *mino, *maxo, *inio;
|
||||||
float ini, min, max;
|
float ini, min, max;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "iiiiiOOO|is", &event, &x, &y, &w, &h, &inio, &mino, &maxo, &realtime, &tip));
|
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))
|
if (!PyNumber_Check(inio) || !PyNumber_Check(inio) || !PyNumber_Check(inio))
|
||||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
@@ -526,8 +550,11 @@ static PyObject *Method_Number (PyObject *self, PyObject *args)
|
|||||||
Button *but;
|
Button *but;
|
||||||
PyObject *mino, *maxo, *inio;
|
PyObject *mino, *maxo, *inio;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiiiOOO|s", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiiiOOO|s", &name, &event,
|
||||||
&x, &y, &w, &h, &inio, &mino, &maxo, &tip));
|
&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();
|
but= newbutton();
|
||||||
|
|
||||||
@@ -570,8 +597,11 @@ static PyObject *Method_String (PyObject *self, PyObject *args)
|
|||||||
int x, y, w, h, len;
|
int x, y, w, h, len;
|
||||||
Button *but;
|
Button *but;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "siiiiisi|s", &name, &event,
|
if (!PyArg_ParseTuple(args, "siiiiisi|s", &name, &event,
|
||||||
&x, &y, &w, &h, &newstr, &len, &tip));
|
&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= newbutton();
|
||||||
but->type= 3;
|
but->type= 3;
|
||||||
@@ -592,7 +622,9 @@ static PyObject *Method_Text (PyObject *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
char *text;
|
char *text;
|
||||||
|
|
||||||
EXPP_TRY(PyArg_ParseTuple(args, "s", &text));
|
if (!PyArg_ParseTuple(args, "s", &text))
|
||||||
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
|
"expected string argument");
|
||||||
|
|
||||||
BMF_DrawString(G.font, text);
|
BMF_DrawString(G.font, text);
|
||||||
|
|
||||||
|
@@ -121,10 +121,10 @@ static Button *newbutton (void);
|
|||||||
|
|
||||||
static void exit_pydraw(SpaceText *st);
|
static void exit_pydraw(SpaceText *st);
|
||||||
static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args);
|
static void exec_callback(SpaceText *st, PyObject *callback, PyObject *args);
|
||||||
void EXPP_spacetext_do_pywin_draw(SpaceText *st);
|
void BPY_spacetext_do_pywin_draw(SpaceText *st);
|
||||||
static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event);
|
static void spacetext_do_pywin_buttons(SpaceText *st, unsigned short event);
|
||||||
void EXPP_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val);
|
void BPY_spacetext_do_pywin_event(SpaceText *st, unsigned short event, short val);
|
||||||
int EXPP_spacetext_is_pywin(SpaceText *st);
|
int BPY_spacetext_is_pywin(SpaceText *st);
|
||||||
|
|
||||||
static char Method_Exit_doc[] =
|
static char Method_Exit_doc[] =
|
||||||
"() - Exit the windowing interface";
|
"() - Exit the windowing interface";
|
||||||
@@ -160,10 +160,8 @@ exactly once for everytime this function is called.";
|
|||||||
static PyObject *Method_Draw (PyObject *self, PyObject *args);
|
static PyObject *Method_Draw (PyObject *self, PyObject *args);
|
||||||
|
|
||||||
static char Method_Create_doc[] =
|
static char Method_Create_doc[] =
|
||||||
"(value) - Create a default Button object\n\
|
"(value) - Create a default Button object\n\n\
|
||||||
\n\
|
(value) - The value to store in the button\n\n\
|
||||||
(value) - The value to store in the button\n\
|
|
||||||
\n\
|
|
||||||
Valid values are ints, floats, and strings";
|
Valid values are ints, floats, and strings";
|
||||||
|
|
||||||
static PyObject *Method_Create (PyObject *self, PyObject *args);
|
static PyObject *Method_Create (PyObject *self, PyObject *args);
|
||||||
|
@@ -46,53 +46,85 @@ static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Image_Get */
|
/* Function: M_Image_Get */
|
||||||
/* Python equivalent: Blender.Image.Get */
|
/* Python equivalent: Blender.Image.Get */
|
||||||
|
/* Description: Receives a string and returns the image object */
|
||||||
|
/* whose name matches the string. If no argument is */
|
||||||
|
/* passed in, a list of all image names in the */
|
||||||
|
/* current scene is returned. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static PyObject *M_Image_Get(PyObject *self, PyObject *args)
|
static PyObject *M_Image_Get(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name = NULL;
|
||||||
Image *img_iter;
|
Image *img_iter;
|
||||||
C_Image *wanted_img;
|
|
||||||
|
|
||||||
printf ("In Image_Get()\n");
|
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
"expected string argument (or nothing)"));
|
||||||
"expected string argument"));
|
|
||||||
|
|
||||||
/* Use the name to search for the image requested. */
|
|
||||||
wanted_img = NULL;
|
|
||||||
img_iter = G.main->image.first;
|
img_iter = G.main->image.first;
|
||||||
|
|
||||||
while ((img_iter) && (wanted_img == NULL)) {
|
if (name) { /* (name) - Search image by name */
|
||||||
|
|
||||||
|
C_Image *wanted_image = NULL;
|
||||||
|
|
||||||
|
while ((img_iter) && (wanted_image == NULL)) {
|
||||||
if (strcmp (name, img_iter->id.name+2) == 0) {
|
if (strcmp (name, img_iter->id.name+2) == 0) {
|
||||||
wanted_img = (C_Image *)PyObject_NEW(C_Image, &Image_Type);
|
wanted_image = (C_Image *)PyObject_NEW(C_Image, &Image_Type);
|
||||||
if (wanted_img) wanted_img->image = img_iter;
|
if (wanted_image) wanted_image->image = img_iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
img_iter = img_iter->id.next;
|
img_iter = img_iter->id.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wanted_img == NULL) {
|
if (wanted_image == NULL) { /* Requested image doesn't exist */
|
||||||
/* No image exists with the name specified in the argument name. */
|
|
||||||
char error_msg[64];
|
char error_msg[64];
|
||||||
PyOS_snprintf(error_msg, sizeof(error_msg),
|
PyOS_snprintf(error_msg, sizeof(error_msg),
|
||||||
"Image \"%s\" not found", name);
|
"Image \"%s\" not found", name);
|
||||||
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject*)wanted_img;
|
return (PyObject *)wanted_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else { /* () - return a list of all images in the scene */
|
||||||
|
int index = 0;
|
||||||
|
PyObject *img_list, *pystr;
|
||||||
|
|
||||||
|
img_list = PyList_New (BLI_countlist (&(G.main->image)));
|
||||||
|
|
||||||
|
if (img_list == NULL)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyList"));
|
||||||
|
|
||||||
|
while (img_iter) {
|
||||||
|
pystr = PyString_FromString (img_iter->id.name+2);
|
||||||
|
|
||||||
|
if (!pystr)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyString"));
|
||||||
|
|
||||||
|
PyList_SET_ITEM (img_list, index, pystr);
|
||||||
|
|
||||||
|
img_iter = img_iter->id.next;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (img_list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Function: M_Image_Load */
|
||||||
|
/* Python equivalent: Blender.Image.Load */
|
||||||
|
/* Description: Receives a string and returns the image object */
|
||||||
|
/* whose filename matches the string. */
|
||||||
|
/*****************************************************************************/
|
||||||
static PyObject *M_Image_Load(PyObject *self, PyObject *args)
|
static PyObject *M_Image_Load(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *fname;
|
char *fname;
|
||||||
Image *img_ptr;
|
Image *img_ptr;
|
||||||
C_Image *img;
|
C_Image *img;
|
||||||
|
|
||||||
printf ("In Image_Load()\n");
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &fname))
|
if (!PyArg_ParseTuple(args, "s", &fname))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
img = (C_Image *)PyObject_NEW(C_Image, &Image_Type);
|
img = (C_Image *)PyObject_NEW(C_Image, &Image_Type);
|
||||||
@@ -118,8 +150,6 @@ PyObject *M_Image_Init (void)
|
|||||||
{
|
{
|
||||||
PyObject *submodule;
|
PyObject *submodule;
|
||||||
|
|
||||||
printf ("In M_Image_Init()\n");
|
|
||||||
|
|
||||||
submodule = Py_InitModule3("Blender.Image", M_Image_methods, M_Image_doc);
|
submodule = Py_InitModule3("Blender.Image", M_Image_methods, M_Image_doc);
|
||||||
|
|
||||||
return (submodule);
|
return (submodule);
|
||||||
@@ -154,7 +184,7 @@ static PyObject *Image_rename(C_Image *self, PyObject *args)
|
|||||||
char buf[21];
|
char buf[21];
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||||
@@ -170,13 +200,13 @@ static PyObject *Image_setXRep(C_Image *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
|
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
|
||||||
self->image->xrep = value;
|
self->image->xrep = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -188,13 +218,13 @@ static PyObject *Image_setYRep(C_Image *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
|
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
|
||||||
self->image->yrep = value;
|
self->image->yrep = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
#include <BKE_global.h>
|
#include <BKE_global.h>
|
||||||
#include <BKE_library.h>
|
#include <BKE_library.h>
|
||||||
#include <BKE_image.h>
|
#include <BKE_image.h>
|
||||||
|
#include <BLI_blenlib.h>
|
||||||
#include <DNA_image_types.h>
|
#include <DNA_image_types.h>
|
||||||
|
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
|
@@ -89,35 +89,35 @@ static PyObject *M_Lamp_New(PyObject *self, PyObject *args, PyObject *keywords)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Lamp_Get */
|
/* Function: M_Lamp_Get */
|
||||||
/* Python equivalent: Blender.Lamp.Get */
|
/* Python equivalent: Blender.Lamp.Get */
|
||||||
|
/* Description: Receives a string and returns the lamp data obj */
|
||||||
|
/* whose name matches the string. If no argument is */
|
||||||
|
/* passed in, a list of all lamp data names in the */
|
||||||
|
/* current scene is returned. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
|
static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name = NULL;
|
||||||
Lamp *lamp_iter;
|
Lamp *lamp_iter;
|
||||||
C_Lamp *wanted_lamp;
|
|
||||||
|
|
||||||
printf ("In Lamp_Get()\n");
|
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
{
|
"expected string argument (or nothing)"));
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
|
||||||
"expected string argument"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use the name to search for the lamp requested. */
|
|
||||||
wanted_lamp = NULL;
|
|
||||||
lamp_iter = G.main->lamp.first;
|
lamp_iter = G.main->lamp.first;
|
||||||
|
|
||||||
while ((lamp_iter) && (wanted_lamp == NULL)) {
|
if (name) { /* (name) - Search lamp by name */
|
||||||
|
|
||||||
|
C_Lamp *wanted_lamp = NULL;
|
||||||
|
|
||||||
|
while ((lamp_iter) && (wanted_lamp == NULL)) {
|
||||||
if (strcmp (name, lamp_iter->id.name+2) == 0) {
|
if (strcmp (name, lamp_iter->id.name+2) == 0) {
|
||||||
wanted_lamp = (C_Lamp *)PyObject_NEW(C_Lamp, &Lamp_Type);
|
wanted_lamp = (C_Lamp *)PyObject_NEW(C_Lamp, &Lamp_Type);
|
||||||
if (wanted_lamp) wanted_lamp->lamp = lamp_iter;
|
if (wanted_lamp) wanted_lamp->lamp = lamp_iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
lamp_iter = lamp_iter->id.next;
|
lamp_iter = lamp_iter->id.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wanted_lamp == NULL) {/* Requested Lamp doesn't exist */
|
if (wanted_lamp == NULL) { /* Requested lamp doesn't exist */
|
||||||
char error_msg[64];
|
char error_msg[64];
|
||||||
PyOS_snprintf(error_msg, sizeof(error_msg),
|
PyOS_snprintf(error_msg, sizeof(error_msg),
|
||||||
"Lamp \"%s\" not found", name);
|
"Lamp \"%s\" not found", name);
|
||||||
@@ -127,6 +127,33 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
|
|||||||
return (PyObject *)wanted_lamp;
|
return (PyObject *)wanted_lamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else { /* () - return a list of all lamps in the scene */
|
||||||
|
int index = 0;
|
||||||
|
PyObject *lamplist, *pystr;
|
||||||
|
|
||||||
|
lamplist = PyList_New (BLI_countlist (&(G.main->lamp)));
|
||||||
|
|
||||||
|
if (lamplist == NULL)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyList"));
|
||||||
|
|
||||||
|
while (lamp_iter) {
|
||||||
|
pystr = PyString_FromString (lamp_iter->id.name+2);
|
||||||
|
|
||||||
|
if (!pystr)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyString"));
|
||||||
|
|
||||||
|
PyList_SET_ITEM (lamplist, index, pystr);
|
||||||
|
|
||||||
|
lamp_iter = lamp_iter->id.next;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (lamplist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Lamp_Init */
|
/* Function: M_Lamp_Init */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -320,7 +347,7 @@ static PyObject *Lamp_rename(C_Lamp *self, PyObject *args)
|
|||||||
char buf[21];
|
char buf[21];
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||||
@@ -336,7 +363,7 @@ static PyObject *Lamp_setType(C_Lamp *self, PyObject *args)
|
|||||||
char *type;
|
char *type;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &type))
|
if (!PyArg_ParseTuple(args, "s", &type))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
if (strcmp (type, "Lamp") == 0)
|
if (strcmp (type, "Lamp") == 0)
|
||||||
@@ -365,13 +392,13 @@ static PyObject *Lamp_setIntType(C_Lamp *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [0,3]"));
|
"expected int argument in [0,3]"));
|
||||||
|
|
||||||
if (value >= 0 && value <= 3)
|
if (value >= 0 && value <= 3)
|
||||||
self->lamp->type = value;
|
self->lamp->type = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [0,3]"));
|
"expected int argument in [0,3]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -386,7 +413,7 @@ static PyObject *Lamp_setMode(C_Lamp *self, PyObject *args)
|
|||||||
if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2],
|
if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2],
|
||||||
&m[3], &m[4], &m[5], &m[6], &m[7]))
|
&m[3], &m[4], &m[5], &m[6], &m[7]))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
"expected string argument(s)"));
|
"expected from none to eight string argument(s)"));
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if (m[i] == NULL) break;
|
if (m[i] == NULL) break;
|
||||||
@@ -424,7 +451,7 @@ static PyObject *Lamp_setIntMode(C_Lamp *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument"));
|
"expected int argument"));
|
||||||
|
|
||||||
/* well, with so many flag bits, we just accept any short int, no checking */
|
/* well, with so many flag bits, we just accept any short int, no checking */
|
||||||
@@ -439,14 +466,14 @@ static PyObject *Lamp_setSamples(C_Lamp *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
if (value >= EXPP_LAMP_SAMPLES_MIN &&
|
if (value >= EXPP_LAMP_SAMPLES_MIN &&
|
||||||
value <= EXPP_LAMP_SAMPLES_MAX)
|
value <= EXPP_LAMP_SAMPLES_MAX)
|
||||||
self->lamp->samp = value;
|
self->lamp->samp = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [1,16]"));
|
"expected int argument in [1,16]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -458,21 +485,15 @@ static PyObject *Lamp_setBufferSize(C_Lamp *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument, any of [512, 768, 1024, 1536, 2560]"));
|
"expected int argument in [512, 5120]"));
|
||||||
|
|
||||||
switch (value) {
|
if (value >= EXPP_LAMP_BUFFERSIZE_MIN &&
|
||||||
case 512:
|
value <= EXPP_LAMP_BUFFERSIZE_MAX)
|
||||||
case 768:
|
|
||||||
case 1024:
|
|
||||||
case 1536:
|
|
||||||
case 2560:
|
|
||||||
self->lamp->bufsize = value;
|
self->lamp->bufsize = value;
|
||||||
break;
|
else
|
||||||
default:
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
"expected int argument in [512, 5120]"));
|
||||||
"expected int argument, any of [512, 768, 1024, 1536, 2560]"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
@@ -483,14 +504,14 @@ static PyObject *Lamp_setHaloStep(C_Lamp *self, PyObject *args)
|
|||||||
short value;
|
short value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "h", &value))
|
if (!PyArg_ParseTuple(args, "h", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected int argument in [0,12]"));
|
"expected int argument in [0,12]"));
|
||||||
|
|
||||||
if (value >= EXPP_LAMP_HALOSTEP_MIN &&
|
if (value >= EXPP_LAMP_HALOSTEP_MIN &&
|
||||||
value <= EXPP_LAMP_HALOSTEP_MAX)
|
value <= EXPP_LAMP_HALOSTEP_MAX)
|
||||||
self->lamp->shadhalostep = value;
|
self->lamp->shadhalostep = value;
|
||||||
else
|
else
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_ValueError,
|
||||||
"expected int argument in [0,12]"));
|
"expected int argument in [0,12]"));
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -502,7 +523,7 @@ static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument in [0.0, 1.0]"));
|
"expected float argument in [0.0, 1.0]"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, 0.0, 1.0);
|
value = EXPP_ClampFloat (value, 0.0, 1.0);
|
||||||
@@ -523,7 +544,7 @@ static PyObject *Lamp_setEnergy(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX);
|
value = EXPP_ClampFloat (value, EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX);
|
||||||
@@ -538,7 +559,7 @@ static PyObject *Lamp_setDist(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX);
|
value = EXPP_ClampFloat (value, EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX);
|
||||||
@@ -553,10 +574,11 @@ static PyObject *Lamp_setSpotSize(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX);
|
value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTSIZE_MIN,
|
||||||
|
EXPP_LAMP_SPOTSIZE_MAX);
|
||||||
self->lamp->spotsize = value;
|
self->lamp->spotsize = value;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
@@ -568,7 +590,7 @@ static PyObject *Lamp_setSpotBlend(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected float argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTBLEND_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_SPOTBLEND_MIN,
|
||||||
@@ -584,8 +606,8 @@ static PyObject *Lamp_setClipStart(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPSTART_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPSTART_MIN,
|
||||||
EXPP_LAMP_CLIPSTART_MAX);
|
EXPP_LAMP_CLIPSTART_MAX);
|
||||||
@@ -600,8 +622,8 @@ static PyObject *Lamp_setClipEnd(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPEND_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_CLIPEND_MIN,
|
||||||
EXPP_LAMP_CLIPEND_MAX);
|
EXPP_LAMP_CLIPEND_MAX);
|
||||||
@@ -616,8 +638,8 @@ static PyObject *Lamp_setBias(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX);
|
value = EXPP_ClampFloat (value, EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX);
|
||||||
self->lamp->bias = value;
|
self->lamp->bias = value;
|
||||||
@@ -631,8 +653,8 @@ static PyObject *Lamp_setSoftness(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_SOFTNESS_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_SOFTNESS_MIN,
|
||||||
EXPP_LAMP_SOFTNESS_MAX);
|
EXPP_LAMP_SOFTNESS_MAX);
|
||||||
@@ -647,8 +669,8 @@ static PyObject *Lamp_setHaloInt(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_HALOINT_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_HALOINT_MIN,
|
||||||
EXPP_LAMP_HALOINT_MAX);
|
EXPP_LAMP_HALOINT_MAX);
|
||||||
@@ -663,8 +685,8 @@ static PyObject *Lamp_setQuad1(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD1_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD1_MIN,
|
||||||
EXPP_LAMP_QUAD1_MAX);
|
EXPP_LAMP_QUAD1_MAX);
|
||||||
@@ -679,8 +701,8 @@ static PyObject *Lamp_setQuad2(C_Lamp *self, PyObject *args)
|
|||||||
float value;
|
float value;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "f", &value))
|
if (!PyArg_ParseTuple(args, "f", &value))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a float number as argument"));
|
"expected float argument"));
|
||||||
|
|
||||||
value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD2_MIN,
|
value = EXPP_ClampFloat (value, EXPP_LAMP_QUAD2_MIN,
|
||||||
EXPP_LAMP_QUAD2_MAX);
|
EXPP_LAMP_QUAD2_MAX);
|
||||||
|
@@ -39,6 +39,7 @@
|
|||||||
#include <BKE_global.h>
|
#include <BKE_global.h>
|
||||||
#include <BKE_object.h>
|
#include <BKE_object.h>
|
||||||
#include <BKE_library.h>
|
#include <BKE_library.h>
|
||||||
|
#include <BLI_blenlib.h>
|
||||||
#include <DNA_lamp_types.h>
|
#include <DNA_lamp_types.h>
|
||||||
|
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
@@ -79,6 +80,8 @@
|
|||||||
#define EXPP_LAMP_SAMPLES_MIN 1
|
#define EXPP_LAMP_SAMPLES_MIN 1
|
||||||
#define EXPP_LAMP_SAMPLES_MAX 16
|
#define EXPP_LAMP_SAMPLES_MAX 16
|
||||||
#define EXPP_LAMP_BUFFERSIZE 512
|
#define EXPP_LAMP_BUFFERSIZE 512
|
||||||
|
#define EXPP_LAMP_BUFFERSIZE_MIN 512
|
||||||
|
#define EXPP_LAMP_BUFFERSIZE_MAX 5120
|
||||||
#define EXPP_LAMP_ENERGY 1.0
|
#define EXPP_LAMP_ENERGY 1.0
|
||||||
#define EXPP_LAMP_ENERGY_MIN 0.0
|
#define EXPP_LAMP_ENERGY_MIN 0.0
|
||||||
#define EXPP_LAMP_ENERGY_MAX 10.0
|
#define EXPP_LAMP_ENERGY_MAX 10.0
|
||||||
|
@@ -183,7 +183,7 @@ PyObject *M_Object_New(PyObject *self, PyObject *args)
|
|||||||
PyObject *M_Object_Get(PyObject *self, PyObject *args)
|
PyObject *M_Object_Get(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
struct Object * object;
|
struct Object * object;
|
||||||
char * name;
|
char * name = NULL;
|
||||||
|
|
||||||
printf ("In Object_Get()\n");
|
printf ("In Object_Get()\n");
|
||||||
|
|
||||||
|
@@ -43,10 +43,8 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
|||||||
Text *bl_text; /* blender text object */
|
Text *bl_text; /* blender text object */
|
||||||
C_Text *py_text; /* python wrapper */
|
C_Text *py_text; /* python wrapper */
|
||||||
|
|
||||||
printf ("In Text_New()\n");
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|si", &name, &follow))
|
if (!PyArg_ParseTuple(args, "|si", &name, &follow))
|
||||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
||||||
"expected string and int arguments (or nothing)");
|
"expected string and int arguments (or nothing)");
|
||||||
|
|
||||||
bl_text = add_empty_text();
|
bl_text = add_empty_text();
|
||||||
@@ -75,53 +73,85 @@ static PyObject *M_Text_New(PyObject *self, PyObject *args, PyObject *keywords)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Text_Get */
|
/* Function: M_Text_Get */
|
||||||
/* Python equivalent: Blender.Text.Get */
|
/* Python equivalent: Blender.Text.Get */
|
||||||
|
/* Description: Receives a string and returns the text object */
|
||||||
|
/* whose name matches the string. If no argument is */
|
||||||
|
/* passed in, a list of all text names in the current */
|
||||||
|
/* scene is returned. */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static PyObject *M_Text_Get(PyObject *self, PyObject *args)
|
static PyObject *M_Text_Get(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name = NULL;
|
||||||
Text *txt_iter;
|
Text *txt_iter;
|
||||||
C_Text *wanted_txt;
|
|
||||||
|
|
||||||
printf ("In Text_Get()\n");
|
if (!PyArg_ParseTuple(args, "|s", &name))
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
"expected string argument (or nothing)"));
|
||||||
"expected string argument");
|
|
||||||
|
|
||||||
/* Use the name to search for the text requested. */
|
|
||||||
wanted_txt = NULL;
|
|
||||||
txt_iter = G.main->text.first;
|
txt_iter = G.main->text.first;
|
||||||
|
|
||||||
while ((txt_iter) && (wanted_txt == NULL)) {
|
if (name) { /* (name) - Search text by name */
|
||||||
|
|
||||||
|
C_Text *wanted_txt = NULL;
|
||||||
|
|
||||||
|
while ((txt_iter) && (wanted_txt == NULL)) {
|
||||||
if (strcmp (name, txt_iter->id.name+2) == 0) {
|
if (strcmp (name, txt_iter->id.name+2) == 0) {
|
||||||
wanted_txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
wanted_txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
||||||
if (wanted_txt) wanted_txt->text = txt_iter;
|
if (wanted_txt) wanted_txt->text = txt_iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
txt_iter = txt_iter->id.next;
|
txt_iter = txt_iter->id.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wanted_txt == NULL) {
|
if (wanted_txt == NULL) { /* Requested text doesn't exist */
|
||||||
/* No text exists with the name specified in the argument name. */
|
|
||||||
char error_msg[64];
|
char error_msg[64];
|
||||||
PyOS_snprintf(error_msg, sizeof(error_msg),
|
PyOS_snprintf(error_msg, sizeof(error_msg),
|
||||||
"Text \"%s\" not found", name);
|
"Text \"%s\" not found", name);
|
||||||
return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
|
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)wanted_txt;
|
return (PyObject *)wanted_txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else { /* () - return a list of all texts in the scene */
|
||||||
|
int index = 0;
|
||||||
|
PyObject *txtlist, *pystr;
|
||||||
|
|
||||||
|
txtlist = PyList_New (BLI_countlist (&(G.main->text)));
|
||||||
|
|
||||||
|
if (txtlist == NULL)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyList"));
|
||||||
|
|
||||||
|
while (txt_iter) {
|
||||||
|
pystr = PyString_FromString (txt_iter->id.name+2);
|
||||||
|
|
||||||
|
if (!pystr)
|
||||||
|
return (PythonReturnErrorObject (PyExc_MemoryError,
|
||||||
|
"couldn't create PyString"));
|
||||||
|
|
||||||
|
PyList_SET_ITEM (txtlist, index, pystr);
|
||||||
|
|
||||||
|
txt_iter = txt_iter->id.next;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (txtlist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Function: M_Text_Get */
|
||||||
|
/* Python equivalent: Blender.Text.Load */
|
||||||
|
/* Description: Receives a filename and returns the text object */
|
||||||
|
/* created from the corresponding file. */
|
||||||
|
/*****************************************************************************/
|
||||||
static PyObject *M_Text_Load(PyObject *self, PyObject *args)
|
static PyObject *M_Text_Load(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *fname;
|
char *fname;
|
||||||
Text *txt_ptr;
|
Text *txt_ptr;
|
||||||
C_Text *txt;
|
C_Text *txt;
|
||||||
|
|
||||||
printf ("In Text_Load()\n");
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &fname))
|
if (!PyArg_ParseTuple(args, "s", &fname))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
txt = (C_Text *)PyObject_NEW(C_Text, &Text_Type);
|
||||||
@@ -177,8 +207,6 @@ PyObject *M_Text_Init (void)
|
|||||||
{
|
{
|
||||||
PyObject *submodule;
|
PyObject *submodule;
|
||||||
|
|
||||||
printf ("In M_Text_Init()\n");
|
|
||||||
|
|
||||||
submodule = Py_InitModule3("Blender.Text", M_Text_methods, M_Text_doc);
|
submodule = Py_InitModule3("Blender.Text", M_Text_methods, M_Text_doc);
|
||||||
|
|
||||||
return (submodule);
|
return (submodule);
|
||||||
@@ -236,7 +264,7 @@ static PyObject *Text_rename(C_Text *self, PyObject *args)
|
|||||||
char buf[21];
|
char buf[21];
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &name))
|
if (!PyArg_ParseTuple(args, "s", &name))
|
||||||
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
return (EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected string argument"));
|
"expected string argument"));
|
||||||
|
|
||||||
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
PyOS_snprintf(buf, sizeof(buf), "%s", name);
|
||||||
@@ -296,7 +324,7 @@ static PyObject *Text_write(C_Text *self, PyObject *args)
|
|||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &str))
|
if (!PyArg_ParseTuple(args, "s", &str))
|
||||||
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
||||||
"expected a string argument");
|
"expected string argument");
|
||||||
|
|
||||||
oldstate = txt_get_undostate();
|
oldstate = txt_get_undostate();
|
||||||
txt_insert_buf(self->text, str);
|
txt_insert_buf(self->text, str);
|
||||||
|
@@ -41,6 +41,7 @@
|
|||||||
#include <BKE_sca.h>
|
#include <BKE_sca.h>
|
||||||
#include <BIF_drawtext.h>
|
#include <BIF_drawtext.h>
|
||||||
#include <BKE_text.h>
|
#include <BKE_text.h>
|
||||||
|
#include <BLI_blenlib.h>
|
||||||
#include <DNA_text_types.h>
|
#include <DNA_text_types.h>
|
||||||
|
|
||||||
#include "gen_utils.h"
|
#include "gen_utils.h"
|
||||||
|
Reference in New Issue
Block a user