53 #include <QScriptEngine> 54 #include <QMessageBox> 60 #include "vsiPlugin.hh" 62 #include "baseWidget.hh" 63 #include "parser/context.hh" 64 #include "parser/input.hh" 65 #include "config/dynamicDialog.hh" 79 VsiPlugin::~ VsiPlugin()
92 if (OpenFlipper::Options::nogui ())
97 emit emit getMenubarMenu(tr(
"&Scripting"), scriptingMenu,
true );
99 QAction* showEditor = scriptingMenu->addAction (
"Visual script editor");
100 showEditor->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"vsi_vsiEditor.png") );
102 connect (showEditor, SIGNAL(triggered()) ,
118 connect (baseWidget_, SIGNAL (codeToScriptEditor (QString)),
122 baseWidget_->show ();
131 QScriptEngine *engine;
132 emit getScriptingEngine (engine);
138 QDir dir = OpenFlipper::Options::dataDir ();
140 dir.cd (
"VsiMetadata");
145 foreach (QString sub, dir.entryList(QDir::Dirs))
152 subdir.makeAbsolute();
154 foreach (QString file, subdir.entryList (QStringList(
"*.xml"), QDir::Files))
156 QFile f (subdir.filePath (file));
157 if (!f.open (QIODevice::ReadOnly))
160 context_->
parse (f.readAll ());
176 return QScriptValue ();
178 QVector<VSI::Input *> inputs;
180 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
190 if (inputs.isEmpty ())
191 return QScriptValue ();
197 QMap<QString, QString> results = d.
getResults ();
199 QString script =
"inputs = { ";
201 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
202 script += s +
": " + results[s] +
",";
204 script.remove (script.length () - 1, 1);
209 QScriptValue rv = context_->
scriptEngine ()->evaluate (script);
210 context_->
scriptEngine ()->globalObject ().setProperty (
"inputs", rv);
224 emit functionExists (
"scripting",
"showScriptInEditor(QString)", ok);
238 msgBox.setText(_message);
248 msgBox.setText(_message);
249 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
250 msgBox.setDefaultButton(QMessageBox::Yes);
251 int ret = msgBox.exec();
252 if (ret == QMessageBox::Yes)
267 if ( msgBox->continueBox() ) {
const QString & name() const
Name.
QScriptValue askForInputs(QString _element, QString _inputs)
Scripting function, that allows to ask the user for inputs during script execution.
void initContext()
initalisation
void messageBox(QString _message)
Scripting function, that displays a message box.
QMap< QString, QString > getResults()
Results.
void showInScriptEditor(QString _script)
Opens the text based script editor with the given script.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
bool continueBox(QString _message)
Shows a non blocking stop box for use inside loops.
void showScriptEditor()
Shows visual script editor.
#define TOOLSMENU
The Menu will be added inside the Tools Menu.
void pluginsInitialized()
Register in menubar.
static BaseWidget * createBaseWidget(Context *_ctx, QWidget *_parent=NULL)
Singleton constructor.
bool questionBox(QString _message)
Scripting function, that displays a Yes/No message box.
void parse(QByteArray _xml)
Parse xml content.
virtual void addMenubarAction(QAction *_action, QString _name)
Adds an action to the menubar.
const QVector< Input * > & inputs() const
Inputs.
QScriptEngine * scriptEngine()
Return script engine pointer.
Element * element(QString _name)
Returns the element with a given name.
const QString & shortDescription() const
Short description.