[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16039] branches/soc-2008-quorn/source/ blender: Python errors originating in the active text are now displayed at the top of the text area .
Ian Thompson
quornian at googlemail.com
Sat Aug 9 20:11:41 CEST 2008
Revision: 16039
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16039
Author: quorn
Date: 2008-08-09 20:11:40 +0200 (Sat, 09 Aug 2008)
Log Message:
-----------
Python errors originating in the active text are now displayed at the top of the text area. Errors in other files/scripts still pop up a message as before and all errors are still printed to the console. This removes the need to switch to the console for local errors.
Modified Paths:
--------------
branches/soc-2008-quorn/source/blender/python/BPY_extern.h
branches/soc-2008-quorn/source/blender/python/BPY_interface.c
branches/soc-2008-quorn/source/blender/src/drawtext.c
Modified: branches/soc-2008-quorn/source/blender/python/BPY_extern.h
===================================================================
--- branches/soc-2008-quorn/source/blender/python/BPY_extern.h 2008-08-09 15:59:21 UTC (rev 16038)
+++ branches/soc-2008-quorn/source/blender/python/BPY_extern.h 2008-08-09 18:11:40 UTC (rev 16039)
@@ -89,6 +89,7 @@
int BPY_Err_getLinenumber( void );
const char *BPY_Err_getFilename( void );
+ const char *BPY_Err_getMessage( void );
int BPY_txt_do_python_Text( struct Text *text );
int BPY_menu_do_python( short menutype, int event );
Modified: branches/soc-2008-quorn/source/blender/python/BPY_interface.c
===================================================================
--- branches/soc-2008-quorn/source/blender/python/BPY_interface.c 2008-08-09 15:59:21 UTC (rev 16038)
+++ branches/soc-2008-quorn/source/blender/python/BPY_interface.c 2008-08-09 18:11:40 UTC (rev 16039)
@@ -145,9 +145,11 @@
* Structure definitions
**************************************************************************/
#define FILENAME_LENGTH 24
+#define MESSAGE_LENGTH 256
typedef struct _ScriptError {
char filename[FILENAME_LENGTH];
+ char message[MESSAGE_LENGTH+1];
int lineno;
} ScriptError;
@@ -508,6 +510,15 @@
}
/*****************************************************************************/
+/* Description: This function will return the short message of the error */
+/* that has occured in the python script. */
+/*****************************************************************************/
+const char *BPY_Err_getMessage( void )
+{
+ return g_script_error.message;
+}
+
+/*****************************************************************************/
/* Description: Return PyString filename from a traceback object */
/*****************************************************************************/
PyObject *traceback_getFilename( PyObject * tb )
@@ -566,6 +577,15 @@
} else {
g_script_error.lineno = -1;
}
+ v = PyObject_GetAttrString( err, "text" );
+ if ( v && PyString_Check(v) ) {
+ strcpy(g_script_error.message, "Invalid syntax: ");
+ strncpy(g_script_error.message+16, PyString_AS_STRING( v ), MESSAGE_LENGTH-16);
+ g_script_error.message[MESSAGE_LENGTH]= '\0';
+ Py_DECREF( v );
+ } else {
+ strcpy(g_script_error.message, "Invalid Syntax");
+ }
/* this avoids an abort in Python 2.3's garbage collecting: */
PyErr_Clear( );
return;
@@ -612,6 +632,14 @@
FILENAME_LENGTH );
Py_DECREF(v);
}
+ v = PyObject_GetAttrString( err, "message" );
+ if ( v && PyString_Check(v) ) {
+ strncpy(g_script_error.message, PyString_AS_STRING( v ), MESSAGE_LENGTH);
+ g_script_error.message[MESSAGE_LENGTH]= '\0';
+ Py_DECREF( v );
+ } else {
+ g_script_error.message[0] = '\0';
+ }
Py_DECREF( tb );
}
Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-08-09 15:59:21 UTC (rev 16038)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c 2008-08-09 18:11:40 UTC (rev 16039)
@@ -2014,6 +2014,18 @@
}
}
+static void txt_print_error(SpaceText *st, char* str)
+{
+ if (curarea->spacetype != SPACE_TEXT) return;
+ drawtextspace(curarea, st);
+ glColor3ub(128, 16, 16);
+ glRecti(22, curarea->winy-2, curarea->winx-2, curarea->winy-st->lheight-3);
+ glColor3ub(255, 32, 32);
+ glRasterPos2i(22, curarea->winy-st->lheight);
+ BMF_DrawString(spacetext_get_font(st), str);
+ curarea->win_swap= WIN_BACK_OK;
+}
+
void run_python_script(SpaceText *st)
{
char *py_filename;
@@ -2029,16 +2041,17 @@
if (!st->text) return;
if (!strcmp(py_filename, st->text->id.name+2)) {
- error_pyscript( );
+ //error_pyscript( );
if (lineno >= 0) {
txt_move_toline(text, lineno-1, 0);
txt_sel_line(text);
pop_space_text(st);
- }
+ }
+ txt_print_error(st, BPY_Err_getMessage());
} else {
error("Error in other (possibly external) file, "\
"check console");
- }
+ }
}
}
@@ -2862,7 +2875,6 @@
case PKEY:
if (G.qual == LR_ALTKEY) {
run_python_script(st);
- do_draw= 1;
}
break; /* BREAK P */
case QKEY:
More information about the Bf-blender-cvs
mailing list