[rkward-cvs] SF.net SVN: rkward:[2675] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Sep 30 16:20:05 UTC 2009
Revision: 2675
http://rkward.svn.sourceforge.net/rkward/?rev=2675&view=rev
Author: tfry
Date: 2009-09-30 16:20:05 +0000 (Wed, 30 Sep 2009)
Log Message:
-----------
More testing and some tuning of the qtscript code backend
Modified Paths:
--------------
trunk/rkward/rkward/plugins/testing/test1.js
trunk/rkward/rkward/plugins/testing/test1.xml
trunk/rkward/rkward/plugins/under_development.pluginmap
trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
Added Paths:
-----------
trunk/rkward/rkward/plugins/testing/test2.js
trunk/rkward/rkward/plugins/testing/test2.xml
Modified: trunk/rkward/rkward/plugins/testing/test1.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.js 2009-09-30 14:46:34 UTC (rev 2674)
+++ trunk/rkward/rkward/plugins/testing/test1.js 2009-09-30 16:20:05 UTC (rev 2675)
@@ -1,11 +1,14 @@
function preprocess () {
printIndented ("\t\t", "This is\n\t\a\ntest");
+ printIndented ("---", getValue ("embedded.code.preprocess"));
}
function calculate () {
echo ('model = glm (' + getValue ("model") + ', data=' + getValue ("model.table") + ')\n');
echo ('labels = ' + getValue ("model.labels") + '\n');
- echo ('result = anova (model)');
+ echo ('result = anova (model)\n');
+
+ printIndented ("---", getValue ("embedded.code.calculate"));
}
function printout () {
Modified: trunk/rkward/rkward/plugins/testing/test1.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.xml 2009-09-30 14:46:34 UTC (rev 2674)
+++ trunk/rkward/rkward/plugins/testing/test1.xml 2009-09-30 16:20:05 UTC (rev 2675)
@@ -22,6 +22,9 @@
<tab label="Model">
<formula id="model" fixed_factors="y" dependent="x" label="Now chose the model"/>
</tab>
+ <tab>
+ <embed id="embedded" component="rkward::qtscript_test2"/>
+ </tab>
</tabbook>
</dialog>
Added: trunk/rkward/rkward/plugins/testing/test2.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/test2.js (rev 0)
+++ trunk/rkward/rkward/plugins/testing/test2.js 2009-09-30 16:20:05 UTC (rev 2675)
@@ -0,0 +1,7 @@
+function preprocess () {
+ echo ("This is\n\tan embedded\ntest");
+}
+
+function calculate () {
+ echo ('embbeded: x: ' + getValue ("x") + 'y: ' + getValue ("y") + 'box: ' + getValue ("box"));
+}
Added: trunk/rkward/rkward/plugins/testing/test2.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/test2.xml (rev 0)
+++ trunk/rkward/rkward/plugins/testing/test2.xml 2009-09-30 16:20:05 UTC (rev 2675)
@@ -0,0 +1,22 @@
+<!DOCTYPE rkplugin>
+
+<document>
+ <code file="test2.js"/>
+
+ <dialog label="An embedded QtScript based test plugin">
+ <text>
+ This plugin is bogus! Do not use!
+ </text>
+ <row>
+ <column>
+ <varselector id="vars"/>
+ <spinbox id="box" type="integer" label="Spin it!"/>
+ </column>
+ <column>
+ <varslot type="numeric" id="x" source="vars" required="true" label="dependent variable"/>
+ <varslot type="numeric" id="y" source="vars" required="true" multi="true" label="fixed factors"/>
+ </column>
+ </row>
+ </dialog>
+
+</document>
\ No newline at end of file
Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap 2009-09-30 14:46:34 UTC (rev 2674)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2009-09-30 16:20:05 UTC (rev 2675)
@@ -4,6 +4,7 @@
<components>
<component type="standard" id="simple_anova" file="simple_anova/description.xml" label="Simple Anova" />
<component type="standard" id="qtscript_test1" file="testing/test1.xml" label="QtScript Test 1" />
+ <component type="standard" id="qtscript_test2" file="testing/test2.xml" label="QtScript Test 2" />
<component type="standard" id="sieve_plot" file="plots/sieve_plot.xml" label="Extended Sieve Plot" />
<component type="standard" id="import_stata" file="00saveload/import/import_stata.xml" label="Import Stata">
<attribute id="format" value="*.dta" label="Stata data files"/>
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2009-09-30 14:46:34 UTC (rev 2674)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2009-09-30 16:20:05 UTC (rev 2675)
@@ -180,13 +180,25 @@
if (!ret.isNull ()) return (ret);
- msleep (5);
+ usleep (20); // getValue () may be called very often, and we expect an answer very soon, so we don't sleep too long.
}
}
+bool QtScriptBackendThread::scriptError () {
+ RK_TRACE (PHP);
+
+ if (!engine.hasUncaughtException ()) return false;
+
+ QString message = i18n ("Script Error: %1\nBacktrace:\n%2", engine.uncaughtException ().toString (), engine.uncaughtExceptionBacktrace ().join ("\n"));
+ engine.clearExceptions ();
+ emit (error (message));
+
+ return true;
+}
+
bool QtScriptBackendThread::includeFile (const QString &filename) {
RK_TRACE (PHP);
-qDebug ("i1");
+
QString _filename = filename;
if (!filename.startsWith ("/")) {
KUrl script_path = KUrl (QUrl::fromLocalFile (_scriptfile)).upUrl ();
@@ -194,29 +206,18 @@
_filename = script_path.toLocalFile ();
}
-qDebug ("i2");
QFile file (_filename);
if (!file.open (QIODevice::ReadOnly | QIODevice::Text)) {
emit (error (i18n ("The file \"%1\" (needed by \"%2\") could not be found. Please check your installation.", _filename, _scriptfile)));
return false;
}
-qDebug ("i3");
// evaluate in global context
engine.currentContext ()->setActivationObject (engine.globalObject ());
-qDebug ("i4");
QScriptValue result = engine.evaluate (file.readAll(), _filename);
-qDebug ("i5");
- if (result.isError ()) {
-qDebug ("i6e");
- QString message = i18n ("File %1, line %2: %3", _filename, engine.uncaughtExceptionLineNumber (), result.toString ());
-qDebug (qPrintable (message));
- emit (error (message));
- return false;
- }
+ if (scriptError ()) return false;
-qDebug ("i6");
return true;
}
@@ -226,14 +227,10 @@
QScriptValue backend_object = engine.newQObject (this);
engine.globalObject ().setProperty ("_RK_backend", backend_object);
-qDebug ("a");
if (!includeFile (_commonfile)) return;
-qDebug ("b");
if (!includeFile (_scriptfile)) return;
-qDebug ("c");
emit (commandDone ("startup complete"));
-qDebug ("d");
QString command;
while (1) {
@@ -245,21 +242,14 @@
mutex.unlock ();
if (command.isNull ()) {
- msleep (5);
+ msleep (1);
continue;
}
// do it!
-qDebug (qPrintable (command));
QScriptValue result = engine.evaluate (command);
- if (result.isError ()) {
- QString message = result.toString ();
-qDebug (qPrintable (message));
- emit (error (message));
- return;
- } else {
- emit (commandDone (result.toString ()));
- }
+ if (scriptError ()) return;
+ emit (commandDone (result.toString ()));
command.clear ();
}
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2009-09-30 14:46:34 UTC (rev 2674)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2009-09-30 16:20:05 UTC (rev 2675)
@@ -77,6 +77,9 @@
protected:
void run ();
private:
+ /** for any script error in the last evaluation. If there was an error, a message is generated, and this function return true (and the thread should be made to exit!) */
+ bool scriptError ();
+
QString _command;
QString _data;
QString _commonfile;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list