2003-05-09 04:34:40 +00:00
|
|
|
/*
|
2004-09-18 18:47:03 +00:00
|
|
|
* $Id$
|
2003-05-09 04:34:40 +00:00
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
|
* about this.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Willian P. Germano
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "Text.h" /*This must come first*/
|
2004-05-22 20:25:22 +00:00
|
|
|
|
2005-07-18 03:50:37 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_sca.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BIF_drawtext.h"
|
|
|
|
|
#include "BKE_text.h"
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
2004-05-22 20:25:22 +00:00
|
|
|
#include "gen_utils.h"
|
|
|
|
|
#include "../BPY_extern.h"
|
|
|
|
|
|
|
|
|
|
#define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python API function prototypes for the Text module. */
|
|
|
|
|
/*****************************************************************************/
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *M_Text_New( PyObject * self, PyObject * args);
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Text_Get( PyObject * self, PyObject * args );
|
|
|
|
|
static PyObject *M_Text_Load( PyObject * self, PyObject * args );
|
|
|
|
|
static PyObject *M_Text_unlink( PyObject * self, PyObject * args );
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* The following string definitions are used for documentation strings. */
|
|
|
|
|
/* In Python these will be written to the console when doing a */
|
|
|
|
|
/* Blender.Text.__doc__ */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Text_doc[] = "The Blender Text module\n\n";
|
2004-05-22 20:25:22 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Text_New_doc[] = "() - return a new Text object";
|
2004-05-22 20:25:22 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static char M_Text_Get_doc[] = "(name) - return the Text with name 'name', \
|
2004-05-22 20:25:22 +00:00
|
|
|
returns None if not found.\n If 'name' is not specified, \
|
|
|
|
|
it returns a list of all Texts in the\ncurrent scene.";
|
|
|
|
|
|
|
|
|
|
static char M_Text_Load_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(filename) - return text from file filename as a Text Object, \
|
2004-05-22 20:25:22 +00:00
|
|
|
returns None if not found.\n";
|
|
|
|
|
|
|
|
|
|
static char M_Text_unlink_doc[] =
|
2004-09-25 20:30:40 +00:00
|
|
|
"(text) - remove Text object 'text' from Blender";
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python method structure definition for Blender.Text module: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
struct PyMethodDef M_Text_methods[] = {
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
{"New", M_Text_New, METH_VARARGS, M_Text_New_doc},
|
2004-09-25 20:30:40 +00:00
|
|
|
{"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
|
|
|
|
|
{"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
|
|
|
|
|
{"Load", M_Text_Load, METH_VARARGS, M_Text_Load_doc},
|
|
|
|
|
{"unlink", M_Text_unlink, METH_VARARGS, M_Text_unlink_doc},
|
|
|
|
|
{NULL, NULL, 0, NULL}
|
2004-05-22 20:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Text structure definition: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
typedef struct {
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_HEAD Text * text;
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
} BPy_Text;
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Text_IsLinked( BPy_Text * self );
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Text methods declarations: */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_getName( BPy_Text * self );
|
|
|
|
|
static PyObject *Text_getFilename( BPy_Text * self );
|
|
|
|
|
static PyObject *Text_getNLines( BPy_Text * self );
|
|
|
|
|
static PyObject *Text_setName( BPy_Text * self, PyObject * args );
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *Text_clear( BPy_Text * self );
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_write( BPy_Text * self, PyObject * args );
|
|
|
|
|
static PyObject *Text_set( BPy_Text * self, PyObject * args );
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *Text_asLines( BPy_Text * self );
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Text methods table: */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static PyMethodDef BPy_Text_methods[] = {
|
2004-09-25 20:30:40 +00:00
|
|
|
/* name, method, flags, doc */
|
|
|
|
|
{"getName", ( PyCFunction ) Text_getName, METH_NOARGS,
|
|
|
|
|
"() - Return Text Object name"},
|
|
|
|
|
{"getFilename", ( PyCFunction ) Text_getFilename, METH_VARARGS,
|
|
|
|
|
"() - Return Text Object filename"},
|
|
|
|
|
{"getNLines", ( PyCFunction ) Text_getNLines, METH_VARARGS,
|
|
|
|
|
"() - Return number of lines in text buffer"},
|
|
|
|
|
{"setName", ( PyCFunction ) Text_setName, METH_VARARGS,
|
|
|
|
|
"(str) - Change Text Object name"},
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
{"clear", ( PyCFunction ) Text_clear, METH_NOARGS,
|
2004-09-25 20:30:40 +00:00
|
|
|
"() - Clear Text buffer"},
|
|
|
|
|
{"write", ( PyCFunction ) Text_write, METH_VARARGS,
|
|
|
|
|
"(line) - Append string 'str' to Text buffer"},
|
|
|
|
|
{"set", ( PyCFunction ) Text_set, METH_VARARGS,
|
|
|
|
|
"(name, val) - Set attribute 'name' to value 'val'"},
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
{"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
|
2004-09-25 20:30:40 +00:00
|
|
|
"() - Return text buffer as a list of lines"},
|
|
|
|
|
{NULL, NULL, 0, NULL}
|
2004-05-22 20:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python Text_Type callback function prototypes: */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Text_dealloc( BPy_Text * self );
|
|
|
|
|
static int Text_setAttr( BPy_Text * self, char *name, PyObject * v );
|
|
|
|
|
static PyObject *Text_getAttr( BPy_Text * self, char *name );
|
|
|
|
|
static int Text_compare( BPy_Text * a, BPy_Text * b );
|
|
|
|
|
static PyObject *Text_repr( BPy_Text * self );
|
2004-05-22 20:25:22 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python Text_Type structure definition: */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyTypeObject Text_Type = {
|
|
|
|
|
PyObject_HEAD_INIT( NULL )
|
|
|
|
|
0, /* ob_size */
|
|
|
|
|
"Blender Text", /* tp_name */
|
|
|
|
|
sizeof( BPy_Text ), /* tp_basicsize */
|
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
|
/* methods */
|
|
|
|
|
( destructor ) Text_dealloc, /* tp_dealloc */
|
|
|
|
|
0, /* tp_print */
|
|
|
|
|
( getattrfunc ) Text_getAttr, /* tp_getattr */
|
|
|
|
|
( setattrfunc ) Text_setAttr, /* tp_setattr */
|
|
|
|
|
( cmpfunc ) Text_compare, /* tp_compare */
|
|
|
|
|
( reprfunc ) Text_repr, /* tp_repr */
|
|
|
|
|
0, /* tp_as_number */
|
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
|
0, /* tp_as_hash */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
0, /* tp_doc */
|
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
|
BPy_Text_methods, /* tp_methods */
|
|
|
|
|
0, /* tp_members */
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
2004-05-22 20:25:22 +00:00
|
|
|
};
|
2003-05-09 04:34:40 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: M_Text_New */
|
|
|
|
|
/* Python equivalent: Blender.Text.New */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *M_Text_New( PyObject * self, PyObject * args)
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
|
|
|
|
char buf[21];
|
|
|
|
|
int follow = 0;
|
|
|
|
|
Text *bl_text; /* blender text object */
|
|
|
|
|
PyObject *py_text; /* python wrapper */
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "|si", &name, &follow ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_AttributeError,
|
|
|
|
|
"expected string and int arguments (or nothing)" );
|
|
|
|
|
|
|
|
|
|
bl_text = add_empty_text( );
|
|
|
|
|
|
|
|
|
|
if( bl_text ) {
|
|
|
|
|
/* do not set user count because Text is already linked */
|
|
|
|
|
|
|
|
|
|
/* create python wrapper obj */
|
|
|
|
|
py_text = Text_CreatePyObject( bl_text );
|
|
|
|
|
} else
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't create Text Object in Blender" );
|
|
|
|
|
if( !py_text )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create Text Object wrapper" );
|
|
|
|
|
|
|
|
|
|
if( follow )
|
|
|
|
|
bl_text->flags |= EXPP_TEXT_MODE_FOLLOW;
|
|
|
|
|
|
|
|
|
|
if( name ) {
|
|
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
|
|
|
|
rename_id( &bl_text->id, buf );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return py_text;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-05-13 01:54:28 +00:00
|
|
|
/* Function: M_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. */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Text_Get( PyObject * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name = NULL;
|
|
|
|
|
Text *txt_iter;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "|s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument (or nothing)" ) );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
txt_iter = G.main->text.first;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( name ) { /* (name) - Search text by name */
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *wanted_txt = NULL;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( ( txt_iter ) && ( wanted_txt == NULL ) ) {
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, txt_iter->id.name + 2 ) == 0 ) {
|
|
|
|
|
wanted_txt = Text_CreatePyObject( txt_iter );
|
|
|
|
|
}
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
txt_iter = txt_iter->id.next;
|
|
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( wanted_txt == NULL ) { /* Requested text doesn't exist */
|
|
|
|
|
char error_msg[64];
|
|
|
|
|
PyOS_snprintf( error_msg, sizeof( error_msg ),
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
"Text \"%s\" not found", name );
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( EXPP_ReturnPyObjError
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
( PyExc_NameError, error_msg ) );
|
2004-09-25 20:30:40 +00:00
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return wanted_txt;
|
|
|
|
|
}
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
else { /* () - return a list of all texts in the scene */
|
|
|
|
|
int index = 0;
|
|
|
|
|
PyObject *txtlist, *pyobj;
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
txtlist = PyList_New( BLI_countlist( &( G.main->text ) ) );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( txtlist == NULL )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyList" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( txt_iter ) {
|
|
|
|
|
pyobj = Text_CreatePyObject( txt_iter );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pyobj )
|
|
|
|
|
return ( EXPP_ReturnPyObjError
|
|
|
|
|
( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyString" ) );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
PyList_SET_ITEM( txtlist, index, pyobj );
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
txt_iter = txt_iter->id.next;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2003-05-13 01:54:28 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( txtlist );
|
|
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: M_Text_Load */
|
2003-05-13 01:54:28 +00:00
|
|
|
/* Python equivalent: Blender.Text.Load */
|
|
|
|
|
/* Description: Receives a filename and returns the text object */
|
|
|
|
|
/* created from the corresponding file. */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Text_Load( PyObject * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
char *fname = NULL;
|
|
|
|
|
char fpath[FILE_MAXDIR + FILE_MAXFILE];
|
|
|
|
|
Text *txt_ptr = NULL;
|
|
|
|
|
unsigned int maxlen = FILE_MAXDIR + FILE_MAXFILE;
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "s", &fname ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
if (strlen(fname) > (maxlen - 1))
|
|
|
|
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
|
|
|
|
"text filename too long");
|
|
|
|
|
else if (!BLI_exists(fname))
|
|
|
|
|
return EXPP_ReturnPyObjError (PyExc_AttributeError,
|
|
|
|
|
"text file not found");
|
2003-05-09 04:34:40 +00:00
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
BLI_strncpy(fpath, fname, maxlen);
|
2003-05-09 04:34:40 +00:00
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
txt_ptr = add_text( fpath );
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !txt_ptr )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_IOError,
|
|
|
|
|
"couldn't load text" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
return Text_CreatePyObject(txt_ptr);
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-26 02:03:51 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: M_Text_unlink */
|
|
|
|
|
/* Python equivalent: Blender.Text.unlink */
|
|
|
|
|
/* Description: Removes the given Text object from Blender */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *M_Text_unlink( PyObject * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
BPy_Text *textobj;
|
|
|
|
|
Text *text;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "O!", &Text_Type, &textobj ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected a Text object as argument" );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
text = ( ( BPy_Text * ) textobj )->text;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !text )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"this text was already unlinked!" );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
BPY_clear_bad_scriptlinks( text );
|
|
|
|
|
free_text_controllers( text );
|
|
|
|
|
unlink_text( text );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
free_libblock( &G.main->text, text );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
( ( BPy_Text * ) textobj )->text = NULL;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-24 07:21:17 +00:00
|
|
|
/* Function: Text_Init */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Text_Init( void )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *submodule;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Text_Type.ob_type = &PyType_Type;
|
2003-06-02 20:15:50 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
submodule =
|
|
|
|
|
Py_InitModule3( "Blender.Text", M_Text_methods, M_Text_doc );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( submodule );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_CreatePyObject */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *Text_CreatePyObject( Text * txt )
|
2003-06-26 02:03:51 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
BPy_Text *pytxt;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
pytxt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !pytxt )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create BPy_Text PyObject" );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
pytxt->text = txt;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return ( PyObject * ) pytxt;
|
2003-06-26 02:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python BPy_Text methods: */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_getName( BPy_Text * self )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = PyString_FromString( self->text->id.name + 2 );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Text.name attribute" );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_getFilename( BPy_Text * self )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr;
|
2003-08-02 20:49:31 +00:00
|
|
|
char *name = self->text->name;
|
2004-09-25 20:30:40 +00:00
|
|
|
|
|
|
|
|
if( name )
|
|
|
|
|
attr = PyString_FromString( self->text->name );
|
2003-08-02 20:49:31 +00:00
|
|
|
else
|
|
|
|
|
attr = Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Text.filename attribute" );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_getNLines( BPy_Text * self )
|
|
|
|
|
{ /* text->nlines isn't updated in Blender (?) */
|
|
|
|
|
int nlines = 0;
|
|
|
|
|
TextLine *line;
|
|
|
|
|
PyObject *attr;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
line = self->text->lines.first;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( line ) { /* so we have to count them ourselves */
|
|
|
|
|
line = line->next;
|
|
|
|
|
nlines++;
|
|
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
self->text->nlines = nlines; /* and update Blender, too (should we?) */
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
attr = PyInt_FromLong( nlines );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( attr )
|
|
|
|
|
return attr;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"couldn't get Text.nlines attribute" );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_setName( BPy_Text * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *name;
|
|
|
|
|
char buf[21];
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "s", &name ) )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" ) );
|
|
|
|
|
|
|
|
|
|
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
|
|
|
|
|
|
|
|
|
|
rename_id( &self->text->id, buf );
|
|
|
|
|
|
|
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *Text_clear( BPy_Text * self)
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
int oldstate;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !self->text )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"This object isn't linked to a Blender Text Object" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
oldstate = txt_get_undostate( );
|
|
|
|
|
txt_set_undostate( 1 );
|
|
|
|
|
txt_sel_all( self->text );
|
|
|
|
|
txt_cut_sel( self->text );
|
|
|
|
|
txt_set_undostate( oldstate );
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_set( BPy_Text * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
int ival;
|
|
|
|
|
char *attr;
|
|
|
|
|
|
|
|
|
|
if( !PyArg_ParseTuple( args, "si", &attr, &ival ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected a string and an int as arguments" );
|
|
|
|
|
|
|
|
|
|
if( strcmp( "follow_cursor", attr ) == 0 ) {
|
|
|
|
|
if( ival )
|
|
|
|
|
self->text->flags |= EXPP_TEXT_MODE_FOLLOW;
|
|
|
|
|
else
|
|
|
|
|
self->text->flags &= EXPP_TEXT_MODE_FOLLOW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_write( BPy_Text * self, PyObject * args )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
char *str;
|
|
|
|
|
int oldstate;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !self->text )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"This object isn't linked to a Blender Text Object" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !PyArg_ParseTuple( args, "s", &str ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
|
|
|
|
"expected string argument" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
oldstate = txt_get_undostate( );
|
|
|
|
|
txt_insert_buf( self->text, str );
|
|
|
|
|
txt_move_eof( self->text, 0 );
|
|
|
|
|
txt_set_undostate( oldstate );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_INCREF( Py_None );
|
|
|
|
|
return Py_None;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
BPython:
- Scripts:
fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus.
cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu).
small updates to help_browser.py script.
The above changes are related to this:
- Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there.
- Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ).
- Modules:
Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode.
NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work).
- Bugs fixed:
#2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9
Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does.
#1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9
Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script").
Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython.
- Removed a few warnings here and there and also updated docs.
2005-03-19 06:24:55 +00:00
|
|
|
static PyObject *Text_asLines( BPy_Text * self )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
TextLine *line;
|
|
|
|
|
PyObject *list, *ob;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !self->text )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"This object isn't linked to a Blender Text Object" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
line = self->text->lines.first;
|
|
|
|
|
list = PyList_New( 0 );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !list )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyList" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( line ) {
|
|
|
|
|
ob = Py_BuildValue( "s", line->line );
|
|
|
|
|
PyList_Append( list, ob );
|
|
|
|
|
line = line->next;
|
|
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
return list;
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_dealloc */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Text type. It is */
|
2003-05-09 04:34:40 +00:00
|
|
|
/* the destructor function. */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static void Text_dealloc( BPy_Text * self )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject_DEL( self );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_getAttr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Text type. It is */
|
|
|
|
|
/* the function that accesses BPy_Text member variables and */
|
2003-05-09 04:34:40 +00:00
|
|
|
/* methods. */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_getAttr( BPy_Text * self, char *name )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *attr = Py_None;
|
|
|
|
|
|
|
|
|
|
if( !self->text || !Text_IsLinked( self ) )
|
|
|
|
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
|
|
|
|
"Text was already deleted!" );
|
|
|
|
|
|
|
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
attr = PyString_FromString( self->text->id.name + 2 );
|
|
|
|
|
else if( strcmp( name, "filename" ) == 0 )
|
|
|
|
|
return Text_getFilename( self ); /* special: can be null */
|
|
|
|
|
else if( strcmp( name, "mode" ) == 0 )
|
|
|
|
|
attr = PyInt_FromLong( self->text->flags );
|
|
|
|
|
else if( strcmp( name, "nlines" ) == 0 )
|
|
|
|
|
attr = Text_getNLines( self );
|
|
|
|
|
|
|
|
|
|
else if( strcmp( name, "__members__" ) == 0 )
|
|
|
|
|
attr = Py_BuildValue( "[s,s,s,s]",
|
|
|
|
|
"name", "filename", "mode", "nlines" );
|
|
|
|
|
|
|
|
|
|
if( !attr )
|
|
|
|
|
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
|
|
|
|
|
"couldn't create PyObject" ) );
|
|
|
|
|
|
|
|
|
|
if( attr != Py_None )
|
|
|
|
|
return attr; /* attribute found, return its value */
|
|
|
|
|
|
|
|
|
|
/* not an attribute, search the methods table */
|
|
|
|
|
return Py_FindMethod( BPy_Text_methods, ( PyObject * ) self, name );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_setAttr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Text type. It is the */
|
|
|
|
|
/* function that changes Text Data members values. If this */
|
|
|
|
|
/* data is linked to a Blender Text, it also gets updated. */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Text_setAttr( BPy_Text * self, char *name, PyObject * value )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
PyObject *valtuple;
|
|
|
|
|
PyObject *error = NULL;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !self->text || !Text_IsLinked( self ) )
|
|
|
|
|
return EXPP_ReturnIntError( PyExc_RuntimeError,
|
|
|
|
|
"Text was already deleted!" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
|
|
|
|
/* We're playing a trick on the Python API users here. Even if they use
|
|
|
|
|
* Text.member = val instead of Text.setMember(value), we end up using the
|
|
|
|
|
* function anyway, since it already has error checking, clamps to the right
|
|
|
|
|
* interval and updates the Blender Text structure when necessary. */
|
|
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
valtuple = Py_BuildValue( "(O)", value ); /* the set* functions expect a tuple */
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( !valtuple )
|
|
|
|
|
return EXPP_ReturnIntError( PyExc_MemoryError,
|
|
|
|
|
"TextSetAttr: couldn't create PyTuple" );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( strcmp( name, "name" ) == 0 )
|
|
|
|
|
error = Text_setName( self, valtuple );
|
|
|
|
|
else { /* Error: no such member in the Text Data structure */
|
|
|
|
|
Py_DECREF( value );
|
|
|
|
|
Py_DECREF( valtuple );
|
|
|
|
|
return ( EXPP_ReturnIntError( PyExc_KeyError,
|
|
|
|
|
"attribute not found or immutable" ) );
|
|
|
|
|
}
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( valtuple );
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
if( error != Py_None )
|
|
|
|
|
return -1;
|
2003-05-09 04:34:40 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
Py_DECREF( Py_None ); /* incref'ed by the called set* function */
|
|
|
|
|
return 0; /* normal exit */
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-21 19:58:31 +00:00
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_compare */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Text type. It */
|
2003-05-21 19:58:31 +00:00
|
|
|
/* compares two Text_Type objects. Only the "==" and "!=" */
|
|
|
|
|
/* comparisons are meaninful. Returns 0 for equality and -1 if */
|
|
|
|
|
/* they don't point to the same Blender Text struct. */
|
|
|
|
|
/* In Python it becomes 1 if they are equal, 0 otherwise. */
|
|
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static int Text_compare( BPy_Text * a, BPy_Text * b )
|
2003-05-21 19:58:31 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
Text *pa = a->text, *pb = b->text;
|
|
|
|
|
return ( pa == pb ) ? 0 : -1;
|
2003-05-21 19:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2003-06-26 02:03:51 +00:00
|
|
|
/* Function: Text_repr */
|
|
|
|
|
/* Description: This is a callback function for the BPy_Text type. It */
|
|
|
|
|
/* builds a meaninful string to represent text objects. */
|
2003-05-09 04:34:40 +00:00
|
|
|
/*****************************************************************************/
|
2004-09-25 20:30:40 +00:00
|
|
|
static PyObject *Text_repr( BPy_Text * self )
|
2003-05-09 04:34:40 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
if( self->text && Text_IsLinked( self ) )
|
|
|
|
|
return PyString_FromFormat( "[Text \"%s\"]",
|
|
|
|
|
self->text->id.name + 2 );
|
|
|
|
|
else
|
|
|
|
|
return PyString_FromString( "[Text <deleted>]" );
|
2003-05-09 04:34:40 +00:00
|
|
|
}
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
/* Internal function to confirm if a Text wasn't unlinked.
|
|
|
|
|
* This is necessary because without it, if a script writer
|
2004-09-25 20:30:40 +00:00
|
|
|
* referenced an already unlinked Text obj, Blender would crash. */
|
|
|
|
|
static int Text_IsLinked( BPy_Text * self )
|
2003-06-26 02:03:51 +00:00
|
|
|
{
|
2004-09-25 20:30:40 +00:00
|
|
|
Text *txt_iter = G.main->text.first;
|
2003-06-26 02:03:51 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
while( txt_iter ) {
|
|
|
|
|
if( self->text == txt_iter )
|
|
|
|
|
return 1; /* ok, still linked */
|
2003-06-28 07:38:21 +00:00
|
|
|
|
2004-09-25 20:30:40 +00:00
|
|
|
txt_iter = txt_iter->id.next;
|
|
|
|
|
}
|
2003-06-28 07:38:21 +00:00
|
|
|
/* uh-oh, it was already deleted */
|
2004-09-25 20:30:40 +00:00
|
|
|
self->text = NULL; /* so we invalidate the pointer */
|
|
|
|
|
return 0;
|
2003-06-26 02:03:51 +00:00
|
|
|
}
|