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());
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();
QScriptValue printToFileFunction(QScriptContext *context, QScriptEngine *engine)
Special print function for sending output to a file.
QStringList scriptingFunctions_
List of all registered scripting functions.
QScriptValue helpFunction(QScriptContext *context, QScriptEngine *engine)
Function to print help about scripting functions.
void createWidget(QString _objectName, QString _uiFilename, bool _show=true)
Create an script object from a ui file.
void setToolBoxSide(QString _side)
Scripting function to set the side of the main window on which the toolbox should be displayed...
void setToolBoxOrientationOnTheRight(bool _toolBoxRight)
Set orientation of tool box (either on the right or the left side of the screen)
std::vector< PluginInfo > plugins_
List of all loaded plugins_.
void blockSceneGraphUpdates()
Block the scenegraph updates.
void addViewModeContextMenus(QString _modeName, QString _contextMenuList)
Scripting function to set context menus in a view mode.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
void setView(QString view)
Called when a plugin requests an update in the viewer.
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.
QWidget * getToolbox(QString _pluginName, QString _toolboxName)
QString getCurrentViewMode()
Get current view mode.
void slotExecuteScript(QString _script)
void unblockSceneGraphUpdates()
Unblock the scenegraph updates.
void expandToolBoxWidget(QWidget *widget, bool expand)
int getObjectId(QString _filename)
Get object id from filename.
void addViewModeIcon(QString _modeName, QString _iconName)
Scripting function to set an icon for a view mode.
SideArea * toolBox_
Toolbox.
const std::vector< PluginInfo > plugins() const
List of all loaded plugins_.
void setViewMode(QString _mode, bool _expandAll=false)
Set the view Mode to the given Mode.
void slotAddViewModeContextMenus(QString _mode, QStringList _usedToolbars)
Add or change Toolbars for a ViewMode (non-userdefined viewMode)
int getObjectId(const QString &_name)
void slotGetScriptingEngine(QScriptEngine *&_engine)
Core scripting engine.
void setViewModeIcon(QString _mode, QString _iconName)
Set the icon of a viewMode.
void addToolbox(QString _name, QWidget *_widget)
Add a Toolbox from a plugin or from scripting.
QVector< ViewMode * > viewModes_
List of available draw modes.
void addViewModeToolbars(QString _modeName, QString _toolbarList)
Scripting function to set toolbars in a view mode.
void slotSetViewAndWindowGeometry(QString view)
Set the supplied serialized view.
void setViewAndWindowGeometry(QString view)
Called when a plugin requests an update in the viewer.
void setToolBoxActive(QString _toolBoxName, bool _active)
Scripting function to activate or deactivate a toolbox.
void activateToolbox(QString _pluginName, QString _toolboxName, bool activate)
Gets called by examiner widget when mouse is moved in picking mode.
void slotSetView(QString view)
Set the supplied serialized view.
void slotAddViewModeToolboxes(QString _mode, QStringList _usedWidgets)
Add or change Toolboxes for a ViewMode (non-userdefined viewMode)
void executeFileScript(QString _filename)
Core scripting engine.
QScriptEngine scriptEngine_
Core scripting engine.
void slotScriptError(const QScriptValue &error)
Core scripting engine.
void executeScript(QString _script)
Core scripting engine.
void slotGetAllAvailableFunctions(QStringList &_functions)
Core scripting engine.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void moveToolBoxToTop(QString _name)
Move selected toolbox to top of side area.
void addViewModeToolboxes(QString _modeName, QString _toolboxList)
Scripting function to set toolboxes in a view mode.
void moveToolBoxToBottom(QString _name)
Move selected toolbox to bottom of side area.
void slotSetViewModeIcon(QString _mode, QString _iconName)
Sets the Icon for a given View Mode (non-userdefined viewMode)
void slotAddViewModeToolbars(QString _mode, QStringList _usedToolbars)
Add or change Toolbars for a ViewMode (non-userdefined viewMode)
void scriptLogFunction(QString _output)
stream for logging to file
void slotExecuteFileScript(QString _filename)
void scriptInfo(QString _pluginName, QString _functionName)
Core scripting engine.
void moveToolBoxToTop(QString _name)
Move a specific toolbox widget to the top of the side area.
void setViewMode(QString _viewMode)
Set the active ViewMode.
void scriptLog(QString _message)
Logging signal for ScriptEngine.
QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
Special print function for core logger.
void setElementActive(QString _name, bool _active)
set the active state of given element