[rkward-cvs] SF.net SVN: rkward:[2920] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jun 30 15:56:35 UTC 2010


Revision: 2920
          http://rkward.svn.sourceforge.net/rkward/?rev=2920&view=rev
Author:   tfry
Date:     2010-06-30 15:56:34 +0000 (Wed, 30 Jun 2010)

Log Message:
-----------
Somewhat experimental: Add support for using the current object in plugins.
Add a sample plugin to generate random data for illustration purposes.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
    trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
    trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
    trunk/rkward/rkward/plugins/testing/test1.xml
    trunk/rkward/rkward/plugins/under_development.pluginmap
    trunk/rkward/rkward/rbackend/rkstructuregetter.cpp
    trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js
    trunk/rkward/rkward/windows/rkmdiwindow.h

Added Paths:
-----------
    trunk/rkward/rkward/plugins/data/
    trunk/rkward/rkward/plugins/data/generate_random.js
    trunk/rkward/rkward/plugins/data/generate_random.xml

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/ChangeLog	2010-06-30 15:56:34 UTC (rev 2920)
@@ -1,7 +1,10 @@
 TODO: Do not use SmartInterface for KDE 4.5 and above
 
+- Fixed: Placement of several menu items was broken - again - with KDE 4.4 and above
+- Allow sorting of results in help search window
+- Fixed: CPU usage would go to 100% for no good reason under certain circumstances
 - The save-object selector in plugins now allows to save as part of a data.frame / list		TODO: document plugin-API additions
-- Fixed: On some systems, dev.off() would spawn two new graphics windows.			TODO: write test case
+- Fixed: On some systems, dev.off() would spawn two new graphics windows
 - Support row names in the data.frame-editor
 - Fixed: When starting with an empty table, RKWard would sometimes claim that this object has been removed
 - Fixed: Would crash when trying to configure toolbars under certain circumstances (workaround for bug in kdelibs)

Modified: trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/dataeditor/rkeditordataframe.cpp	2010-06-30 15:56:34 UTC (rev 2920)
@@ -45,6 +45,7 @@
 	RK_ASSERT (!object->isPending ());
 	RKEditor::object = object;
 	RK_ASSERT (object->isDataFrame ());
+	setGlobalContextProperty ("current_object", object->getFullName());
 
 	RKVarEditDataFrameModel* model = new RKVarEditDataFrameModel (object, this);
 	initTable (model, object);
@@ -63,8 +64,9 @@
 
 	RKVarEditDataFrameModel* model = new RKVarEditDataFrameModel (valid, RObjectList::getGlobalEnv (), open_chain, 5, this);
 
-	RKEditor::object = model->getObject ();;
+	RKEditor::object = model->getObject ();
 	RK_ASSERT (object->isDataFrame ());
+	setGlobalContextProperty ("current_object", object->getFullName());
 
 	initTable (model, object);
 	connect (model, SIGNAL (modelObjectDestroyed()), this, SLOT (deleteLater()));

Modified: trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/dataeditor/rkvareditmodel.cpp	2010-06-30 15:56:34 UTC (rev 2920)
@@ -146,6 +146,7 @@
 // TODO: this does not emit any data change notifications to other editors
 		objects[i]->insertRows (row, count);
 	}
+#warning TODO: adjust dimensions of the data.frame!
 	endInsertRows ();
 
 	return true;

Modified: trunk/rkward/rkward/plugin/rkstandardcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/plugin/rkstandardcomponent.cpp	2010-06-30 15:56:34 UTC (rev 2920)
@@ -37,6 +37,8 @@
 #include "../scriptbackends/rkcomponentscripting.h"
 #include "../misc/xmlhelper.h"
 #include "../settings/rksettingsmoduleplugins.h"
+#include "../windows/rkmdiwindow.h"
+#include "../windows/rkworkplace.h"
 
 // component widgets
 #include "rkvarselector.h"
@@ -73,6 +75,17 @@
 	addChild ("code", code = new RKComponentPropertyCode (this, true));		// do not change this name!
 	code->setInternal (true);
 
+	RKComponentPropertyBase *current_object_property = new RKComponentPropertyBase (this, false);
+	current_object_property->setInternal (true);
+	RKMDIWindow *w = RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::AnyWindowState);
+	if (w) {
+qDebug ("something's active: %s", qPrintable (w->globalContextProperty ("current_object")));
+		current_object_property->setValue (w->globalContextProperty ("current_object"));
+	} else {
+qDebug ("nothing's active");
+	}
+	addChild ("current_object", current_object_property);
+
 	// open the main description file for parsing
 	XMLHelper* xml = XMLHelper::getStaticHelper ();
 	QDomElement doc_element = xml->openXMLFile (filename, DL_ERROR);

Added: trunk/rkward/rkward/plugins/data/generate_random.js
===================================================================
--- trunk/rkward/rkward/plugins/data/generate_random.js	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/generate_random.js	2010-06-30 15:56:34 UTC (rev 2920)
@@ -0,0 +1,9 @@
+function calculate () {
+	if (getValue ("length.enabled.numeric")) {
+		length = getValue ("length");
+	} else {	// this happens when the saveto.parent is a data.frame, only.
+		length = "dim (" + getValue ("saveto.parent") + ")[1]";
+	}
+
+	echo (".GlobalEnv$" + getValue ("saveto") + " <- rnorm (" + length + ", mean=" + getValue ("mean") + ", sd=" + getValue ("sd") + ")\n");
+}

Added: trunk/rkward/rkward/plugins/data/generate_random.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/generate_random.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/generate_random.xml	2010-06-30 15:56:34 UTC (rev 2920)
@@ -0,0 +1,25 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="generate_random.js"/>
+	<logic>
+		<connect governor="current_object" client="saveto.parent"/>
+		<script><![CDATA[
+			// the top-level block is called only once
+			gui.addChangeCommand ("saveto.parent", "parentChanged ()");
+
+			// this function is called on every change of the saveto's parent
+			parentChanged = function () {
+				parent_object = makeRObject (gui.getValue ("saveto.parent"));
+				gui.setValue ("length.enabled", !parent_object.isDataFrame ());
+			}
+			]]></script>
+	</logic>
+	<dialog label="Generate random data">
+		<text id="text">Well, this could be extended to other distributions in the same dialog. For now, it's normal distribution.</text>
+		<spinbox default_precision="2" type="real" initial="0" id="mean" label="mu (mean)"/>
+		<spinbox default_precision="2" type="real" min="0" initial="1" id="sd" label="sigma (standard deviation)"/>
+		<frame/>
+		<spinbox type="integer" initial="10" id="length" label="Length of generated sequence"/>
+		<saveobject id="saveto" label="Save as" initial="random"/>
+	</dialog>
+</document>

Modified: trunk/rkward/rkward/plugins/testing/test1.xml
===================================================================
--- trunk/rkward/rkward/plugins/testing/test1.xml	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/plugins/testing/test1.xml	2010-06-30 15:56:34 UTC (rev 2920)
@@ -6,7 +6,7 @@
 	<logic>
 		<script><![CDATA[
 			call_num = 0;
-			gui.setValue ("Select a dependent variable!", "text.text");
+			gui.setValue ("text.text", "Select a dependent variable!");
 
 			f = Kross.module('forms');
 			label = f.createWidget(scripty, 'QLabel', 'Label', {});
@@ -19,7 +19,7 @@
 				text = "So, you think it's '" + obj.objectname + "'?\n";
 				text += "That has length " + obj.dimensions() + " and classes " + obj.classes() + "!\n";
 				text += "Updates of this text so far: " + call_num;
-				gui.setValue (text, "text.text");
+				gui.setValue ("text.text", text);
 			}
 			]]></script>
 	</logic>

Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2010-06-30 15:56:34 UTC (rev 2920)
@@ -3,10 +3,13 @@
 <document base_prefix="" namespace="rkward">
 	<components>
 		<component type="standard" id="simple_anova" file="simple_anova/description.xml" label="Simple Anova" />
+		<component type="standard" id="sieve_plot" file="plots/sieve_plot.xml" label="Extended Sieve Plot" />
+		<component type="standard" id="generate_random" file="data/generate_random.xml" label="Generate random data" />
+
+<!-- These are purely for testing: -->
 		<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" />
-
+<!-- End -->
 	</components>
 
 	<hierarchy>
@@ -18,6 +21,9 @@
 			<menu id="export" label="Export" index="5">
 			</menu>
 		</menu>
+		<menu id="data" label="Data" index="3">
+			<entry component="generate_random" index="9"/>
+		</menu>
 		<menu id="analysis" label="Analysis" index="4">
 			<entry component="simple_anova" index="9"/>
 			<entry component="qtscript_test1" index="1"/>

Modified: trunk/rkward/rkward/rbackend/rkstructuregetter.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/rbackend/rkstructuregetter.cpp	2010-06-30 15:56:34 UTC (rev 2920)
@@ -246,6 +246,7 @@
 
 	// basic classification
 	for (unsigned int i = 0; i < num_classes; ++i) {
+#warning: Using is.data.frame() may be more reliable (would need to be called only on List-objects, thus no major performance hit)
 		if (classes[i] == "data.frame") type |= RObject::DataFrame;
 	}
 

Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js	2010-06-30 15:56:34 UTC (rev 2920)
@@ -31,7 +31,7 @@
 		return (_rkward.getValue (this.absoluteId (id)));
 	}
 
-	this.setValue = function (value, id) {
+	this.setValue = function (id, value) {
 		return (_rkward.setValue (value, this.absoluteId (id)));
 	}
 
@@ -68,7 +68,7 @@
 	this.initialize();
 
 	this.getName = function () {
-		return (this._name);
+		return (this.objectname);
 	}
 
 	this.exists = function () {

Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h	2010-06-30 15:55:09 UTC (rev 2919)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h	2010-06-30 15:56:34 UTC (rev 2920)
@@ -2,7 +2,7 @@
                           rkmdiwindow  -  description
                              -------------------
     begin                : Tue Sep 26 2006
-    copyright            : (C) 2006, 2007, 2008, 2009 by Thomas Friedrichsmeier
+    copyright            : (C) 2006, 2007, 2008, 2009, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -18,8 +18,8 @@
 #ifndef RKMDIWINDOW_H
 #define RKMDIWINDOW_H
 
-#include <qwidget.h>
 #include <QFrame>
+#include <QMap>
 
 #include <kparts/part.h>
 
@@ -106,6 +106,8 @@
 	bool isActive ();
 /** Returns a pointer to an action collection suitable to place RKStandardAction in. This collection (and the corresponding KXMLGUIClient) is created on the fly. */
 	KActionCollection *standardActionCollection ();
+/** plugin-accessible properties of this object in the global context. Currently used only by RKEditorDataFrame to give information on the currently active data.frame. NOTE: ATM, you cannot set arbitrary properties. Only those supported in RKStandardComponent will have an effect. */
+	QString globalContextProperty (const QString& property) { return global_context_properties.value (property); };
 signals:
 /** This signal is emitted, whenever the window caption was changed.
 @param RKMDIWindow* a pointer to this window */
@@ -120,6 +122,8 @@
 
 /** reimplemented from QWidget to emulate focus-follows-mouse behavior */
 	void enterEvent (QEvent *event);
+/** @see globalContextProperty() */
+	void setGlobalContextProperty (const QString& property, const QString& value) { global_context_properties.insert (property, value); };
 friend class RKWorkplace;
 /** type of this window */
 	int type;
@@ -131,6 +135,8 @@
 	RKToolWindowBar *tool_window_bar;
 	bool active;
 	RKMDIStandardActionClient *standard_client;
+/** @see globalContextProperty() */
+	QMap<QString, QString> global_context_properties;
 };
 
 #endif


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