[Hdrflow-svn] SF.net SVN: hdrflow: [212] trunk/app/HDRFlow
Status: Pre-Alpha
Brought to you by:
glslang
|
From: <gl...@us...> - 2007-07-28 15:57:42
|
Revision: 212
http://hdrflow.svn.sourceforge.net/hdrflow/?rev=212&view=rev
Author: glslang
Date: 2007-07-28 08:57:40 -0700 (Sat, 28 Jul 2007)
Log Message:
-----------
+ Script editor execution and display improvements
Modified Paths:
--------------
trunk/app/HDRFlow/ScriptEditorController.mm
trunk/app/HDRFlow/ScriptEngine.cpp
Modified: trunk/app/HDRFlow/ScriptEditorController.mm
===================================================================
--- trunk/app/HDRFlow/ScriptEditorController.mm 2007-07-28 14:32:36 UTC (rev 211)
+++ trunk/app/HDRFlow/ScriptEditorController.mm 2007-07-28 15:57:40 UTC (rev 212)
@@ -38,25 +38,16 @@
- ( void ) executeScript
{
NSString* script = [ scriptEdit_ string ];
- NSString* output = [ [ [ NSString alloc ] initWithString: @"" ] autorelease ];
if( engine_->eval( [ script UTF8String ] ) )
- {
- output = [ output stringByAppendingString: script ];
- output = [ output stringByAppendingString: @"\n" ];
[ scriptStatus_ setStringValue: @"Script successful." ];
- }
else
- {
- output = [ output stringByAppendingString: @"Error in script:\n\t" ];
[ scriptStatus_ setStringValue: @"Script failed." ];
- }
NSString* out = [ [ [ NSString alloc ] initWithUTF8String: engine_->result( ).c_str( ) ] autorelease ];
- output = [ output stringByAppendingString: out ];
- output = [ output stringByAppendingString: @"\n" ];
-
- [ scriptOutput_ setString: output ];
+ [ scriptOutput_ setEditable: YES ];
+ [ scriptOutput_ insertText: out ];
+ [ scriptOutput_ setEditable: NO ];
[ scriptOutput_ setNeedsDisplay: YES ];
[ self clearScript ];
Modified: trunk/app/HDRFlow/ScriptEngine.cpp
===================================================================
--- trunk/app/HDRFlow/ScriptEngine.cpp 2007-07-28 14:32:36 UTC (rev 211)
+++ trunk/app/HDRFlow/ScriptEngine.cpp 2007-07-28 15:57:40 UTC (rev 212)
@@ -46,22 +46,33 @@
py::object main_namespace = main_module.attr( "__dict__" );
result_.clear( );
+
+ std::string trim_str( str.c_str( ) );
+ boost::trim( trim_str );
+ typedef std::vector<std::string> split_vector_type;
+ split_vector_type split_vec;
+ boost::split( split_vec, trim_str, boost::is_any_of( "\n" ) );
+
+ typedef split_vector_type::const_iterator const_iterator;
+ for( const_iterator I = split_vec.begin( ); I != split_vec.end( ); ++I )
+ result_ += "# " + *I + "\n";
+
+ int start = split_vec.size( ) == 1 &&
+ split_vec[ 0 ].find( "import" ) == std::string::npos && split_vec[ 0 ].find( "def" ) == std::string::npos ? Py_eval_input : Py_file_input;
+
try
{
- py::handle<> handle( py::allow_null( PyRun_String( str.c_str( ), Py_eval_input, main_namespace.ptr( ), main_namespace.ptr( ) ) ) );
- if( !handle )
- {
- // clear all errors so the call below has a chance to succeed.
- PyErr_Clear( );
- handle = py::handle<>( PyRun_String( str.c_str( ), Py_file_input, main_namespace.ptr( ), main_namespace.ptr( ) ) );
- }
+ pl::string eval_result;
+ py::handle<> handle( PyRun_String( str.c_str( ), start, main_namespace.ptr( ), main_namespace.ptr( ) ) );
+
py::object strobj( py::handle<>( PyObject_Str( py::object( handle ).ptr( ) ) ) );
if( strobj )
{
- result_ = PyString_AsString( strobj.ptr( ) );
- if( result_ == "None" ) result_.clear( );
+ eval_result = PyString_AsString( strobj.ptr( ) );
+ if( eval_result != "None" )
+ result_ += eval_result + "\n";
}
}
catch( py::error_already_set )
@@ -71,6 +82,7 @@
PyObject* error_traceback;
PyErr_Fetch( &error_type, &error_data, &error_traceback );
+ PyErr_NormalizeException( &error_type, &error_data, &error_traceback );
result_ += error_to_result( error_type );
result_ += error_to_result( error_data );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|