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 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) 181 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
183 foreach (QString s, _inputs.split (
",", Qt::SkipEmptyParts))
194 if (inputs.isEmpty ())
195 return QScriptValue ();
201 QMap<QString, QString> results = d.
getResults ();
203 QString script =
"inputs = { ";
205 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) 206 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
207 script += s +
": " + results[s] +
",";
209 foreach (QString s, _inputs.split (
",", Qt::SkipEmptyParts))
210 script += s +
": " + results[s] +
",";
213 script.remove (script.length () - 1, 1);
218 QScriptValue rv = context_->
scriptEngine ()->evaluate (script);
219 context_->
scriptEngine ()->globalObject ().setProperty (
"inputs", rv);
233 emit functionExists (
"scripting",
"showScriptInEditor(QString)", ok);
247 msgBox.setText(_message);
257 msgBox.setText(_message);
258 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
259 msgBox.setDefaultButton(QMessageBox::Yes);
260 int ret = msgBox.exec();
261 if (ret == QMessageBox::Yes)
276 if ( msgBox->continueBox() ) {
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
bool questionBox(QString _message)
Scripting function, that displays a Yes/No message box.
const QString & name() const
Name.
void initContext()
initalisation
const QVector< Input * > & inputs() const
Inputs.
QMap< QString, QString > getResults()
Results.
void messageBox(QString _message)
Scripting function, that displays a message box.
void parse(QByteArray _xml)
Parse xml content.
const QString & shortDescription() const
Short description.
void pluginsInitialized()
Register in menubar.
Element * element(QString _name)
Returns the element with a given name.
QScriptEngine * scriptEngine()
Return script engine pointer.
bool continueBox(QString _message)
Shows a non blocking stop box for use inside loops.
QScriptValue askForInputs(QString _element, QString _inputs)
Scripting function, that allows to ask the user for inputs during script execution.
void showInScriptEditor(QString _script)
Opens the text based script editor with the given script.
void showScriptEditor()
Shows visual script editor.