[rkward-cvs] SF.net SVN: rkward:[2674] trunk/rkward/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Wed Sep 30 14:46:35 UTC 2009
Revision: 2674
http://rkward.svn.sourceforge.net/rkward/?rev=2674&view=rev
Author: tfry
Date: 2009-09-30 14:46:34 +0000 (Wed, 30 Sep 2009)
Log Message:
-----------
Make the basics of the qtscript backend work, and add a test plugin
Modified Paths:
--------------
trunk/rkward/rkward/plugins/under_development.pluginmap
trunk/rkward/rkward/scriptbackends/CMakeLists.txt
trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
Added Paths:
-----------
trunk/rkward/rkward/plugins/testing/
trunk/rkward/rkward/plugins/testing/test1.js
trunk/rkward/rkward/plugins/testing/test1.xml
trunk/rkward/rkward/scriptbackends/common.js
Added: trunk/rkward/rkward/plugins/testing/test1.js
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.js (rev 0)
+++ trunk/rkward/rkward/plugins/testing/test1.js 2009-09-30 14:46:34 UTC (rev 2674)
@@ -0,0 +1,15 @@
+function preprocess () {
+ printIndented ("\t\t", "This is\n\t\a\ntest");
+}
+
+function calculate () {
+ echo ('model = glm (' + getValue ("model") + ', data=' + getValue ("model.table") + ')\n');
+ echo ('labels = ' + getValue ("model.labels") + '\n');
+ echo ('result = anova (model)');
+}
+
+function printout () {
+ makeHeaderCode ("SimpleAnova", new Array ("Model", getValue ("model"), "Data", getValue ("model.table"), "Test", noquote ("print ('hi')")))
+// makeHeaderCode ("SimpleAnova", new Array ("Model", "Data"))
+ echo ('rk.echo (result)');
+}
Added: trunk/rkward/rkward/plugins/testing/test1.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.xml (rev 0)
+++ trunk/rkward/rkward/plugins/testing/test1.xml 2009-09-30 14:46:34 UTC (rev 2674)
@@ -0,0 +1,28 @@
+<!DOCTYPE rkplugin>
+
+<document>
+ <code file="test1.js"/>
+
+ <dialog label="Testing QtScript code generation">
+ <text>
+ This plugin is bogus! Do not use!
+ </text>
+ <tabbook>
+ <tab label="Basic settings">
+ <row>
+ <column>
+ <varselector id="vars"/>
+ </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>
+ </tab>
+ <tab label="Model">
+ <formula id="model" fixed_factors="y" dependent="x" label="Now chose the model"/>
+ </tab>
+ </tabbook>
+ </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-29 19:23:02 UTC (rev 2673)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap 2009-09-30 14:46:34 UTC (rev 2674)
@@ -3,6 +3,7 @@
<document base_prefix="" namespace="rkward">
<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="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"/>
@@ -22,6 +23,7 @@
</menu>
<menu id="analysis" label="Analysis" index="4">
<entry component="simple_anova" index="9"/>
+ <entry component="qtscript_test1" index="1"/>
</menu>
<menu id="plots" label="Plots" index="5">
<entry component="sieve_plot" />
Modified: trunk/rkward/rkward/scriptbackends/CMakeLists.txt
===================================================================
--- trunk/rkward/rkward/scriptbackends/CMakeLists.txt 2009-09-29 19:23:02 UTC (rev 2673)
+++ trunk/rkward/rkward/scriptbackends/CMakeLists.txt 2009-09-30 14:46:34 UTC (rev 2674)
@@ -17,7 +17,7 @@
########### install files ###############
-INSTALL(FILES common.php php.ini DESTINATION ${DATA_INSTALL_DIR}/rkward/phpfiles )
+INSTALL(FILES common.php php.ini common.js DESTINATION ${DATA_INSTALL_DIR}/rkward/phpfiles )
Added: trunk/rkward/rkward/scriptbackends/common.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/common.js (rev 0)
+++ trunk/rkward/rkward/scriptbackends/common.js 2009-09-30 14:46:34 UTC (rev 2674)
@@ -0,0 +1,82 @@
+this._script_output = "";
+function echo (text) {
+ this._script_output += text;
+}
+
+function printIndented (indentation, lines) {
+ echo (indentation + lines.replace (/\n/g, "\n" + indentation));
+}
+
+// A string-like object that should not be quoted
+function Literal (text) {
+ this.text = text;
+ this.noquote = 1;
+ this.valueOf = function () { return text };
+}
+
+function noquote (text) {
+ return (new Literal (text));
+}
+
+function quote (text) {
+ if (text.noquote) return text;
+ return ("\"" + text.replace (/\"/g, "\\\"") + "\"");
+}
+
+function makeHeaderCode (title, parameters) {
+ echo ("rk.header(" + quote (title));
+ if (parameters.length) {
+ echo (", parameters=list(");
+ for (p = 0; p < parameters.length; ++p) {
+ if (p) {
+ echo (", ");
+ if (!(p % 2)) echo ("\n\t");
+ }
+ echo (quote(parameters[p]));
+ }
+ echo (")");
+ }
+ echo (")\n");
+}
+
+function getValue (id) {
+ return (_RK_backend.getValue (id));
+}
+
+function printValue (id) {
+ echo (getValue (id));
+}
+
+function include (file) {
+ _RK_backend.includeFile (file);
+}
+
+function flushOutput () {
+ string = this._script_output + "\n";
+ this._script_output = "";
+ return (string);
+}
+
+function do_preprocess () {
+ if (typeof (preprocess) == "undefined") return;
+ preprocess ();
+ return (flushOutput ());
+}
+
+function do_calculate () {
+ if (typeof (calculate) == "undefined") return;
+ calculate ();
+ return (flushOutput ());
+}
+
+function do_printout () {
+ if (typeof (printout) == "undefined") return;
+ printout ();
+ return (flushOutput ());
+}
+
+function do_preview () {
+ if (typeof (preview) == "undefined") return;
+ preview ();
+ return (flushOutput ());
+}
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2009-09-29 19:23:02 UTC (rev 2673)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2009-09-30 14:46:34 UTC (rev 2674)
@@ -58,6 +58,7 @@
connect (script_thread, SIGNAL (commandDone(const QString&)), this, SLOT (commandDone(const QString&)));
connect (script_thread, SIGNAL (needData(const QString&)), this, SLOT (needData(const QString&)));
current_type = ScriptBackend::Ignore;
+ script_thread->start ();
QtScriptBackend::code_property = code_property;
QtScriptBackend::add_headings = add_headings;
@@ -137,7 +138,6 @@
_commonfile = commonfile;
_scriptfile = scriptfile;
- start ();
}
QtScriptBackendThread::~QtScriptBackendThread () {
@@ -148,8 +148,9 @@
RK_TRACE (PHP);
mutex.lock ();
- RK_ASSERT (_command.isEmpty ());
- _command = command;
+ RK_ASSERT (_command.isNull ());
+ if (command.isNull ()) _command = "";
+ else _command = command;
mutex.unlock ();
}
@@ -185,7 +186,7 @@
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 ();
@@ -193,21 +194,29 @@
_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 ()) {
- emit (error (result.toString ()));
+qDebug ("i6e");
+ QString message = i18n ("File %1, line %2: %3", _filename, engine.uncaughtExceptionLineNumber (), result.toString ());
+qDebug (qPrintable (message));
+ emit (error (message));
return false;
}
+qDebug ("i6");
return true;
}
@@ -215,31 +224,38 @@
RK_TRACE (PHP);
QScriptValue backend_object = engine.newQObject (this);
- engine.globalObject ().setProperty ("thingy", backend_object);
+ 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) {
mutex.lock ();
- if (!_command.isEmpty ()) {
+ if (!_command.isNull ()) {
command = _command;
_command.clear ();
}
mutex.unlock ();
- if (command.isEmpty ()) {
+ if (command.isNull ()) {
msleep (5);
continue;
}
// do it!
+qDebug (qPrintable (command));
QScriptValue result = engine.evaluate (command);
if (result.isError ()) {
- emit (error (result.toString ()));
+ QString message = result.toString ();
+qDebug (qPrintable (message));
+ emit (error (message));
return;
} else {
emit (commandDone (result.toString ()));
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2009-09-29 19:23:02 UTC (rev 2673)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2009-09-30 14:46:34 UTC (rev 2674)
@@ -37,10 +37,10 @@
bool initialize (RKComponentPropertyCode *code_property=0, bool add_headings=true);
void destroy ();
- void preprocess (int flags) { callFunction ("preprocess ();\n", flags, Preprocess); };
- void calculate (int flags) { callFunction ("calculate ();\n", flags, Calculate); };
- void printout (int flags) { callFunction ("printout ();\n", flags, Printout); };
- void preview (int flags) { callFunction ("getPreview ();\n", flags, Preview); };
+ void preprocess (int flags) { callFunction ("do_preprocess ();\n", flags, Preprocess); };
+ void calculate (int flags) { callFunction ("do_calculate ();\n", flags, Calculate); };
+ void printout (int flags) { callFunction ("do_printout ();\n", flags, Printout); };
+ void preview (int flags) { callFunction ("do_preview ();\n", flags, Preview); };
void writeData (const QString &data);
public slots:
void threadError (const QString &message);
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