71 emit
scriptInfo( _pluginName , _functionName );
95 if ( OpenFlipper::Options::gui()) {
98 QFile uiFile(_uiFilename);
100 if ( !uiFile.exists() ) {
101 emit
log(
LOGERR,tr(
"File does not exist : ") + _uiFilename );
105 uiFile.open(QIODevice::ReadOnly);
110 emit
log(
LOGERR,tr(
"Unable to create QWidget from ui file for ") + _objectName );
114 QScriptValue scriptUi =
scriptEngine_.newQObject(ui, QScriptEngine::ScriptOwnership);
116 if ( !scriptUi.isValid() ) {
117 emit
log(
LOGERR,tr(
"Unable to generate script interface for ") + _objectName );
121 scriptEngine_.globalObject().setProperty(_objectName, scriptUi);
124 if(_show) ui->show();
126 emit
log(
LOGERR,tr(
"Error! Script tried to create Widget in ui less batc mode! Creation Aborted!"));
142 if ( OpenFlipper::Options::gui() )
149 return OpenFlipper::Options::currentViewMode();
156 if ( OpenFlipper::Options::gui() ){
158 QFile file(_iconName);
159 QFileInfo fileInfo(file);
161 if ( ! file.exists() ){
162 emit
log(
LOGERR, tr(
"Icon not found (%1)").arg(_iconName) );
166 file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() +
"viewMode_" + fileInfo.fileName() );
176 if(OpenFlipper::Options::gui()) {
185 if(OpenFlipper::Options::gui()) {
194 QStringList list = _toolboxList.split(
";");
202 QStringList list = _toolbarList.split(
";");
210 QStringList list = _contextMenuList.split(
";");
222 if(_side.toLower() ==
"left") {
224 }
else if(_side.toLower() ==
"right") {
227 emit
log(
LOGERR, QString(
"Could not display toolboxes on side '%1'. Use either 'left' or 'right' as string!").arg(_side));
234 std::vector<PluginInfo>::const_iterator pluginIt =
plugins_.end();
235 for (std::vector<PluginInfo>::const_iterator it =
plugins_.begin(), it_end =
plugins_.end(); it != it_end; ++it) {
236 if (it->name == _pluginName) {
240 if (pluginIt ==
plugins_.end())
return 0;
242 for (std::vector<std::pair<QString , QWidget*> >::const_iterator it = pluginIt->toolboxWidgets.begin(), it_end = pluginIt->toolboxWidgets.end();
243 it != it_end; ++it) {
244 if (it->first == _toolboxName)
265 QWidget *_headerAreaWidget) {
269 for ( uint i = 0 ; i <
plugins_.size(); ++i ) {
270 if (
plugins_[i].plugin == sender() ) {
278 for ( uint i = 0 ; i <
plugins_.size(); ++i ) {
279 if (
plugins_[i].name ==
"Scripting" ) {
287 std::cerr <<
"Unknown sender plugin when adding Toolbox!" << std::endl;
292 spinBoxEventFilter_.hookUpToWidgetTree(_widget);
293 plugins_[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
294 plugins_[id].toolboxIcons.push_back( _icon );
295 plugins_[id].headerAreaWidgets.push_back( std::pair< QString,QWidget* >( _name , _headerAreaWidget) );
298 if ( !
viewModes_[0]->visibleToolboxes.contains(_name) ){
303 setViewMode( OpenFlipper::Options::currentViewMode() );
308 if ( OpenFlipper::Options::gui() ){
315 OpenFlipper::Options::blockSceneGraphUpdates();
320 OpenFlipper::Options::unblockSceneGraphUpdates();
336 emit
log(
LOGERR, tr(
"Script error: ") + error.toString());
342 for (
int i = 0; i < context->argumentCount(); ++i) {
345 result.append(context->argument(i).toString());
349 QScriptValue calleeData = context->callee().property(
"textedit");
350 Core *widget = qobject_cast<
Core*>(calleeData.toQObject());
354 return engine->undefinedValue();
359 if ( context->argumentCount() < 2 ) {
360 context->throwError( QScriptContext::SyntaxError,
"Error! printToFileFunction needs at least two arguments, filename and what should be printed" );
361 return engine->undefinedValue();
365 for (
int i = 1; i < context->argumentCount(); ++i) {
368 result.append(context->argument(i).toString());
371 QFile file(context->argument(0).toString());
373 file.open(QIODevice::Append);
374 QTextStream stream(&file);
376 stream << result <<
"\n";
380 return engine->undefinedValue();
383 QScriptValue
helpFunction(QScriptContext *context, QScriptEngine *engine)
385 if ( context->argumentCount() != 1 ) {
386 context->throwError( QScriptContext::SyntaxError,
"Error! helpFunction needs one argument" );
387 return engine->undefinedValue();
390 QString helpString = context->argument(0).toString();
393 QScriptValue calleeData = context->callee().property(
"core");
394 Core *core = qobject_cast<
Core*>(calleeData.toQObject());
396 const std::vector<PluginInfo> plugins = core->
plugins();
398 for (
unsigned int i=0; i < plugins.size(); i++) {
399 if (plugins[i].rpcName == helpString) {
400 core->
scriptLogFunction(
"=======================================================\n" );
403 core->
scriptLogFunction(
"=======================================================\n" );
406 for (
int j = 0 ; j < plugins[i].rpcFunctions.size() ; ++j ) {
416 return engine->undefinedValue();
void addViewModeToolbars(QString _modeName, QString _toolbarList)
Scripting function to set toolbars in a view mode.
void moveToolBoxToBottom(QString _name)
Move a specific toolbox widget to the bottom of the side area.
void slotScriptInfo(QString _pluginName, QString _functionName)
Core scripting engine.
void slotAddViewModeToolboxes(QString _mode, QStringList _usedWidgets)
Add or change Toolboxes for a ViewMode (non-userdefined viewMode)
void createWidget(QString _objectName, QString _uiFilename, bool _show=true)
Create an script object from a ui file.
const std::vector< PluginInfo > plugins() const
List of all loaded plugins_.
void setToolBoxSide(QString _side)
Scripting function to set the side of the main window on which the toolbox should be displayed...
int getObjectId(const QString &_name)
void expandToolBoxWidget(QWidget *widget, bool expand)
QVector< ViewMode * > viewModes_
List of available draw modes.
void unblockSceneGraphUpdates()
Unblock the scenegraph updates.
void slotAddViewModeContextMenus(QString _mode, QStringList _usedToolbars)
Add or change Toolbars for a ViewMode (non-userdefined viewMode)
void setElementActive(QString _name, bool _active)
set the active state of given element
void setToolBoxActive(QString _toolBoxName, bool _active)
Scripting function to activate or deactivate a toolbox.
void moveToolBoxToBottom(QString _name)
Move selected toolbox to bottom of side area.
int getObjectId(QString _filename)
Get object id from filename.
SideArea * toolBox_
Toolbox.
void setView(QString view)
Called when a plugin requests an update in the viewer.
void slotGetAllAvailableFunctions(QStringList &_functions)
Core scripting engine.
void scriptLog(QString _message)
Logging signal for ScriptEngine.
void slotSetViewModeIcon(QString _mode, QString _iconName)
Sets the Icon for a given View Mode (non-userdefined viewMode)
QStringList scriptingFunctions_
List of all registered scripting functions.
void addToolbox(QString _name, QWidget *_widget)
Add a Toolbox from a plugin or from scripting.
QScriptEngine scriptEngine_
Core scripting engine.
QScriptValue printToFileFunction(QScriptContext *context, QScriptEngine *engine)
Special print function for sending output to a file.
void addViewModeContextMenus(QString _modeName, QString _contextMenuList)
Scripting function to set context menus in a view mode.
void setViewMode(QString _viewMode)
Set the active ViewMode.
void addViewModeToolboxes(QString _modeName, QString _toolboxList)
Scripting function to set toolboxes in a view mode.
void executeScript(QString _script)
Core scripting engine.
std::vector< PluginInfo > plugins_
List of all loaded plugins_.
void setViewModeIcon(QString _mode, QString _iconName)
Set the icon of a viewMode.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void setViewMode(QString _mode, bool _expandAll=false)
Set the view Mode to the given Mode.
void setToolBoxOrientationOnTheRight(bool _toolBoxRight)
Set orientation of tool box (either on the right or the left side of the screen)
void moveToolBoxToTop(QString _name)
Move selected toolbox to top of side area.
QWidget * getToolbox(QString _pluginName, QString _toolboxName)
void blockSceneGraphUpdates()
Block the scenegraph updates.
void moveToolBoxToTop(QString _name)
Move a specific toolbox widget to the top of the side area.
void executeFileScript(QString _filename)
Core scripting engine.
void slotSetViewAndWindowGeometry(QString view)
Set the supplied serialized view.
void slotExecuteScript(QString _script)
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
void activateToolbox(QString _pluginName, QString _toolboxName, bool activate)
Gets called by examiner widget when mouse is moved in picking mode.
void slotScriptError(const QScriptValue &error)
Core scripting engine.
QScriptValue helpFunction(QScriptContext *context, QScriptEngine *engine)
Function to print help about scripting functions.
void slotSetView(QString view)
Set the supplied serialized view.
void setViewAndWindowGeometry(QString view)
Called when a plugin requests an update in the viewer.
QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
Special print function for core logger.
void addViewModeIcon(QString _modeName, QString _iconName)
Scripting function to set an icon for a view mode.
void scriptInfo(QString _pluginName, QString _functionName)
Core scripting engine.
void slotGetScriptingEngine(QScriptEngine *&_engine)
Core scripting engine.
QString getCurrentViewMode()
Get current view mode.
void slotAddViewModeToolbars(QString _mode, QStringList _usedToolbars)
Add or change Toolbars for a ViewMode (non-userdefined viewMode)
void slotExecuteFileScript(QString _filename)
void scriptLogFunction(QString _output)
stream for logging to file