31 #include <boost/algorithm/string.hpp>
32 #include <boost/algorithm/string/predicate.hpp>
34 #include "WScriptUI.h"
35 #include "core/common/WIOTools.h"
36 #include "core/common/WLogStream.h"
37 #include "core/common/WLogger.h"
38 #include "core/common/WPathHelper.h"
39 #include "core/common/WSegmentationFault.h"
40 #include "core/common/WThreadedRunner.h"
41 #include "core/kernel/WKernel.h"
42 #include "core/kernel/WModuleFactory.h"
46 m_programOptions( options )
57 boost::filesystem::path walnutBin = boost::filesystem::path(
m_argv[ 0 ] ).parent_path();
60 boost::filesystem::path homePath = boost::filesystem::path( getenv(
"HOME" ) );
96 std::shared_ptr< WScriptInterpreter > scriptInterpreter;
97 bool executeScriptFile =
false;
102 boost::filesystem::path scriptFile(
m_programOptions[
"file" ].as< std::vector< std::string > >()[ 0 ] );
104 if( !boost::filesystem::exists( scriptFile ) )
106 wlog::error(
"Walnut" ) << std::string(
"Could not find script file: " ) + scriptFile.string();
111 std::string ext = scriptFile.extension().string();
114 executeScriptFile = ( scriptInterpreter != NULL );
116 if( executeScriptFile )
119 scriptInterpreter->setParameters(
m_programOptions[
"file" ].as< std::vector< std::string > >() );
128 if( !scriptInterpreter )
130 wlog::error(
"Walnut" ) <<
"Could not create a script interpreter.";
131 wlog::error(
"Walnut" ) <<
"Only the following interpreters are supported in this build:";
137 wlog::error(
"Walnut" ) <<
"If the interpreter you want to use is not listed, it is either not implemented yet"
138 <<
" or dependencies are missing.";
146 if( executeScriptFile )
149 scriptInterpreter->executeFile(
m_programOptions[
"file" ].as< std::vector< std::string > >()[ 0 ] );
158 std::getline( std::cin, in );
164 else if( in ==
"help" )
168 else if( in ==
"help" )
175 scriptInterpreter->execute( in );
179 wlog::error(
"Walnut" ) <<
"Error while executing script: " << e.
what();
186 scriptInterpreter.reset();
200 if( boost::filesystem::exists( configPath ) )
202 wlog::info(
"Walnut" ) <<
"Reading config file from: " << configPath;
203 std::ifstream is( configPath.string().c_str() );
205 std::string pattern =
"additionalModulePaths=";
206 while( std::getline( is, line ) )
208 if( boost::starts_with( line, pattern ) )
210 std::istringstream ss( line.substr( pattern.size(), line.size() - pattern.size() ) );
212 while( std::getline( ss, path,
',' ) )
214 boost::algorithm::trim( path );
virtual const char * what() const
Returns the message string set on throw.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
static WKernel * instance(std::shared_ptr< WGraphicsEngine > ge, std::shared_ptr< WUI > ui)
Returns pointer to the running kernel or a new if no kernel was there.
std::shared_ptr< WScriptEngine > getScriptEngine()
Get the script engine of this kernel.
static boost::filesystem::path getHomePath()
The path to the OW dir in the user's home.
static std::shared_ptr< WPathHelper > getPathHelper()
Returns instance of the path helper.
WScriptUI(int argc, char **argv, boost::program_options::variables_map const &options)
Constructor.
virtual ~WScriptUI()
Destructor.
virtual WUIWidgetFactory::SPtr getWidgetFactory() const
Returns the widget factory of the UI.
boost::program_options::variables_map const & m_programOptions
The programm options.
virtual int run()
Runs the UI.
virtual void loadToolboxes(boost::filesystem::path configPath)
If you need to load additional modules from your toolboxes, you might want specify these paths in a c...
void wait(bool requestFinish=false)
Wait for the thread to be finished.
This class prescribes the interface to the UI.
char ** m_argv
Command line arguments given.
WFlag< bool > m_isInitialized
Flag determining whether the UI is properly initialized.
WStreamedLogger info(const std::string &source)
Logging an information message.
WStreamedLogger error(const std::string &source)
Logging an error message.