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

tfry at users.sf.net tfry at users.sf.net
Fri May 17 08:23:35 UTC 2013


Revision: 4753
          http://sourceforge.net/p/rkward/code/4753
Author:   tfry
Date:     2013-05-17 08:23:33 +0000 (Fri, 17 May 2013)
Log Message:
-----------
First version of the level selector (undocumented).
Final version will not have the varselector/varslot (to be used embedded, only).

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugin/rkvalueselector.cpp
    trunk/rkward/rkward/plugins/under_development.pluginmap
    trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp
    trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h
    trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js

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

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/ChangeLog	2013-05-17 08:23:33 UTC (rev 4753)
@@ -1,3 +1,6 @@
+- Allow plugin UI script code to query R for information
+	TODO: - document
+	      - piece all the new features together and implement an embeddable level selector plugin on top of this
 - Fixed: potential crash when a previously installed pluginmap is not longer readable
 - Allow to connect <varslot>/<valueslot> source to any property, not just <varselectors>
 	TODO: document

Modified: trunk/rkward/rkward/plugin/rkvalueselector.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkvalueselector.cpp	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/rkward/plugin/rkvalueselector.cpp	2013-05-17 08:23:33 UTC (rev 4753)
@@ -54,6 +54,7 @@
 	}
 
 	list_view = new QTreeView (this);
+	list_view->setHeaderHidden (true);
 	list_view->setSelectionMode (QAbstractItemView::ExtendedSelection);
 	list_view->setRootIsDecorated (false);
 	model = new QStringListModel (this);
@@ -86,10 +87,19 @@
 	RK_TRACE (PLUGIN);
 }
 
+static QStringList mergeLists (const QStringList &labels, const QStringList &ids) {
+	if (labels.size () < ids.size ()) {
+		return labels + (ids.mid (labels.size ()));
+	} else if (labels.size () > ids.size ()) {
+		return (labels.mid (0, ids.size ()));
+	}
+	return labels;
+}
+
 void RKValueSelector::labelsPropertyChanged () {
 	RK_TRACE (PLUGIN);
 
-	model->setStringList (labels->values ());
+	model->setStringList (mergeLists (labels->values (), available->values ()));
 	selectionPropertyChanged ();   // To update selected items
 }
 
@@ -102,6 +112,8 @@
 			RK_DEBUG (PLUGIN, DL_WARNING, "Duplicate value index in value selector: %s", qPrintable (vals[i]));
 		}
 	}
+	model->setStringList (mergeLists (labels->values (), available->values ()));
+
 	if (!purged_selected_indexes.isEmpty ()) {
 		// This is to handle the case that the "selected" property was updated externally, *before* the "available" property got the corresponding change.
 		// In this case, try to re-apply any selected strings that could not be matched, before

Added: trunk/rkward/rkward/plugins/data/level_select.js
===================================================================
--- trunk/rkward/rkward/plugins/data/level_select.js	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/level_select.js	2013-05-17 08:23:33 UTC (rev 4753)
@@ -0,0 +1 @@
+// empty
\ No newline at end of file

Added: trunk/rkward/rkward/plugins/data/level_select.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/level_select.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/level_select.xml	2013-05-17 08:23:33 UTC (rev 4753)
@@ -0,0 +1,62 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="level_select.js" />
+	<help file="level_select.rkh" />
+	<logic>
+		<external id="variable" default=""/>
+		<external id="custom_expression" default=""/>
+		<external id="limit" default="100"/>
+
+		<connect client="variable" governor="x.available"/>
+
+		<script><![CDATA[
+				last_command_id = -1;
+
+				gui.addChangeCommand ("variable", "update ()");
+				gui.addChangeCommand ("limit", "update ()");
+				gui.addChangeCommand ("custom_expression", "update ()");
+				update = function () {
+					gui.setValue ("selector.available", "");
+					gui.setValue ("selector.enabled", 0);
+
+					variable = gui.getValue ("variable");
+					if (variable == "") return;
+
+					limit = gui.getValue ("limit");
+					custom_expression = gui.getValue ("custom_expression");
+					if (custom_expression != "") {
+						expression = custom_expression.replace ('_X_', variable);
+					} else {
+						expression = 'e <- ' + variable + '; if (is.factor (e)) {levels (e)} else {sort (unique (e, nmax=' + limit*limit + '))}';
+					}
+					code = "local ({\n";
+					code += "\tx <- {" + expression + "}\n";
+					code += "\tif (length (x) > " + limit + ") x <- c (x[1:" + limit + "], \"____LIMIT____\")\n";
+					code += "\tx\n";
+					code += "})";
+
+					last_command_id = doRCommand (code, "commandFinished");
+				}
+
+				commandFinished = function (result, id) {
+					if (id != last_command_id) return;  // another result is about to arrive
+					gui.setValue ("selector.enabled", 1);
+					limit = gui.getValue ("limit");
+					gui.setValue ("limitnote.visible", result.length > limit ? 1 : 0);
+					gui.setListValue ("selector.available", result.slice (0, limit));
+				}
+		]]></script>
+	</logic>
+	<dialog label="Level selector">
+		<row>
+			<varselector id="vars"/>
+			<varslot id="x" source="vars"/>
+		</row>
+		
+		<valueselector id="selector" />
+		<text id="limitnote" type="warning">
+			Note: Some values were cut off.
+		</text>
+	</dialog>
+</document>
+ 

Modified: trunk/rkward/rkward/plugins/under_development.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/under_development.pluginmap	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/rkward/plugins/under_development.pluginmap	2013-05-17 08:23:33 UTC (rev 4753)
@@ -14,6 +14,8 @@
 		<component type="standard" id="optionset_test" file="testing/optionset.xml" label="Optionset Test" />
 		<component type="standard" id="matrix_test1" file="testing/matrix1.xml" label="Input Matrix Test" />
 		<component type="standard" id="valueselect_test1" file="testing/valueselect1.xml" label="Valueselector/valueslot/select Test" />
+
+		<component type="standard" id="level_select" file="data/level_select.xml" label="Select by value" />
 <!-- End -->
 
 		<component type="standard" id="import_xls" file="00saveload/import/import_xls.xml" label="Import MS EXCEL">
@@ -42,6 +44,7 @@
 			<entry component="optionset_test" index="1"/>
 			<entry component="matrix_test1" index="1"/>
 			<entry component="valueselect_test1" index="1"/>
+			<entry component="level_select" index="1"/>
 		</menu>
 		<menu id="plots" label="Plots" index="5">
 			<entry component="sieve_plot" />

Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.cpp	2013-05-17 08:23:33 UTC (rev 4753)
@@ -264,6 +264,23 @@
 	}
 }
 
+void RKComponentScriptingProxy::setListValue (const QStringList& value, const QString& id) {
+	RK_TRACE (PHP);
+
+	QString modifier;
+	RKComponentBase* resolved = component->lookupComponent (id, &modifier);
+	if (resolved && modifier.isEmpty () && resolved->isProperty ()) {
+		RKComponentPropertyAbstractList *l = dynamic_cast<RKComponentPropertyAbstractList*> (resolved);
+		if (l) {
+			l->setValueList (value);
+			return;
+		}
+		static_cast<RKComponentPropertyBase*> (resolved)->setValue (value.join ("\n"));
+	} else {
+		script->setError (QString ("error ('No such property %1 (failed portion was %2)');\n").arg (id, modifier));
+	}
+}
+
 QVariantList RKComponentScriptingProxy::getObjectInfo (const QString &name) {
 	RK_TRACE (PHP);
 

Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.h	2013-05-17 08:23:33 UTC (rev 4753)
@@ -57,6 +57,7 @@
 	QVariant getBoolean (const QString &id) const;
 	QVariant getList (const QString &id) const;
 	void setValue (const QString &value, const QString &id);
+	void setListValue (const QStringList &value, const QString &id);
 
 	QVariantList getObjectInfo (const QString &name);
 	QString getObjectParent (const QString &name);

Modified: trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js
===================================================================
--- trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js	2013-05-16 08:10:35 UTC (rev 4752)
+++ trunk/rkward/rkward/scriptbackends/rkcomponentscripting.js	2013-05-17 08:23:33 UTC (rev 4753)
@@ -47,6 +47,10 @@
 		return (_rkward.setValue (value, this.absoluteId (id)));
 	}
 
+	this.setListValue = function (id, value) {
+		return (_rkward.setListValue (value, this.absoluteId (id)));
+	}
+
 	this.getChild = function (id) {
 		return (new Component (this.absoluteId (id)));
 	}





More information about the rkward-tracker mailing list