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

tfry at users.sf.net tfry at users.sf.net
Fri Sep 26 18:04:41 UTC 2014


Revision: 4845
          http://sourceforge.net/p/rkward/code/4845
Author:   tfry
Date:     2014-09-26 18:04:39 +0000 (Fri, 26 Sep 2014)
Log Message:
-----------
Add new minimal embeddable plugin for different input elements. Use this is recode_categorical for input of new values.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugins/data/recode_categorical.js
    trunk/rkward/rkward/plugins/data/recode_categorical.xml
    trunk/rkward/rkward/plugins/embedded.pluginmap

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

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2014-09-22 18:53:11 UTC (rev 4844)
+++ trunk/rkward/ChangeLog	2014-09-26 18:04:39 UTC (rev 4845)
@@ -1,3 +1,4 @@
+- New embeddable (minimal) plugin "multi_input" to combine different input elements
 - Fixed: Problems starting from paths with spaces in the file name on Windows
 - Added command line option --r-executable for switching between several installations of R
 - Use a binary wrapper, instead of wrapper shell script for startup on all platforms

Added: trunk/rkward/rkward/plugins/data/multi_input.js
===================================================================
--- trunk/rkward/rkward/plugins/data/multi_input.js	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/multi_input.js	2014-09-26 18:04:39 UTC (rev 4845)
@@ -0,0 +1 @@
+// empty
\ No newline at end of file

Added: trunk/rkward/rkward/plugins/data/multi_input.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/multi_input.xml	                        (rev 0)
+++ trunk/rkward/rkward/plugins/data/multi_input.xml	2014-09-26 18:04:39 UTC (rev 4845)
@@ -0,0 +1,103 @@
+<!DOCTYPE rkplugin>
+<document>
+	<code file="multi_input.js" />
+	<logic>
+		<!-- This plugin is meant for embedding only. Provides input elements for character/factor, numbers, and logicals, combined in one.
+			External properties:
+				- datatype: Connect this to the desired type of data. Default is character
+				- value: The resulting value. Logicals are coded as 0 or 1. You can also set this externally. Initially "", 0, depending on datatype.
+				- valuequoted: The resulting value. Automatically quoted, if datatype is character or factor. Logicals are coded as TRUE or FALSE
+				               (without additional quotes). NOTE: Contrary to "value", this is read-only.
+		-->
+		<external id="datatype" default="character"/>
+		<external id="value" default=""/>
+		<external id="valuequoted" default=""""/>
+
+		<script><![CDATA[
+				gui.addChangeCommand ("datatype", "updateType ()");
+				gui.addChangeCommand ("value", "update ()");
+				gui.addChangeCommand ("input.text", "inputChange ()");
+				gui.addChangeCommand ("spinbox.real", "spinboxChange ()");
+				gui.addChangeCommand ("logical.number", "logicalChange ()");
+
+				toNumber = function (value_string) {
+					value = parseFloat (value_string);
+					if (isNaN (value)) {
+						if (value_string == "TRUE") value = 1;
+						else (value = 0);
+					}
+					return value;
+				}
+				
+				updateType = function () {
+					datatype = gui.getValue ("datatype");
+					value = "";
+					logical = 0;
+					character = 0;
+					numeric = 0;
+					if (datatype == "logical") {
+						logical = 1;
+						value = (gui.getBoolean ("value") ? 1 : 0);
+					} else if (datatype == "numeric") {
+						numeric = 1;
+						value = toNumber (gui.getString ("value"));
+					} else {
+						value = gui.getString ("value");
+						character = 1;
+					}
+					gui.setValue ("logical.visible", logical);
+					gui.setValue ("spinbox.visible", numeric);
+					gui.setValue ("input.visible", character);
+					gui.setValue ("value", value);
+				}
+
+				var updatingValue = false;
+				update = function () {
+					updatingValue = true;
+
+					datatype = gui.getValue ("datatype");
+					if (datatype == "logical") {
+						value = (gui.getBoolean ("value") ? 1 : 0);
+						valuequoted = value ? "TRUE" : "FALSE";
+					} else if (datatype == "numeric") {
+						value = toNumber (gui.getValue ("value"));
+						valuequoted = value;
+					} else {
+						value = gui.getString ("value");
+						valuequoted = quote (value);
+					}
+					gui.setValue ("logical.number", value);
+					gui.setValue ("spinbox.real", value);
+					gui.setValue ("input.text", value);
+					gui.setValue ("valuequoted", valuequoted);
+
+					updatingValue = false;
+				}
+
+				// The reason for splitting these into separate functions is to make the element behave better in optionsets,
+				// even if the data-type is changed from _outside_ the optionset. In this case, the optionset may have stored the value of a
+				// sub-element, which is now _inactive/hidden_.
+				spinboxChange = function () {
+					if (updatingValue) return;
+					gui.setValue ("value", gui.getValue ("spinbox.real"));
+				}
+				inputChange = function () {
+					if (updatingValue) return;
+					gui.setValue ("value", gui.getValue ("input.text"));
+				}
+				logicalChange = function () {
+					if (updatingValue) return;
+					gui.setValue ("value", gui.getBoolean ("logical.number") ? 1 : 0);
+				}
+		]]></script>
+	</logic>
+	<dialog label="Level selector">
+		<radio id="logical" label="">
+			<option label="FALSE" value="FALSE"/>
+			<option label="TRUE" value="TRUE"/>
+		</radio>
+		<input id="input" label="" initial="initial"/>
+		<spinbox id="spinbox" label="" default_precision="0"/>
+	</dialog>
+</document>
+ 

Modified: trunk/rkward/rkward/plugins/data/recode_categorical.js
===================================================================
--- trunk/rkward/rkward/plugins/data/recode_categorical.js	2014-09-22 18:53:11 UTC (rev 4844)
+++ trunk/rkward/rkward/plugins/data/recode_categorical.js	2014-09-26 18:04:39 UTC (rev 4845)
@@ -6,8 +6,8 @@
 	output = input;
 	if (getBoolean ("saveto_other_object")) output = getString ("saveto");
 	var datamode = getString ("datamode");
-	var quote_new_values = (datamode == "character" || datamode == "factor");
 	var is_factor = datamode == "factor";
+	var is_character = datamode == "character";
 	var default_values = getString ("other");
 
 	// initialize output vector to defaults
@@ -21,7 +21,7 @@
 	if (default_values == "copy") {
 		echo (input + ")\n");
 	} else {
-		echo ('rep (' + default_values == "na" ? 'NA' : getString ("other_custom") + ', length.out = length (' + input + ')))\n');
+		echo ('rep (' + default_values == "na" ? 'NA' : getString ("other_custom.valuequoted") + ', length.out = length (' + input + ')))\n');
 	}
 
 	// Make replacements
@@ -57,7 +57,8 @@
 		var replacement = 'NA';
 		if (new_value_types[i] != "na") {
 			replacement = new_value_strings[i];
-			if (quote_new_values) replacement = quote (replacement);
+			if (is_factor || is_character) replacement = quote (replacement);
+			else if (datamode == "logical") replacement = Number (replacement) ? "TRUE" : "FALSE";
 		}
 
 		echo ('recoded[' + old_index + '] <- ' + replacement + '\n');

Modified: trunk/rkward/rkward/plugins/data/recode_categorical.xml
===================================================================
--- trunk/rkward/rkward/plugins/data/recode_categorical.xml	2014-09-22 18:53:11 UTC (rev 4844)
+++ trunk/rkward/rkward/plugins/data/recode_categorical.xml	2014-09-26 18:04:39 UTC (rev 4845)
@@ -4,6 +4,7 @@
 	<help file="recode_categorical.rkh" />
 	<logic>
 		<connect governor="x.available" client="set.contents.levels.variable"/>
+		<connect governor="datamode.string" client="set.contents.new_value_custom.datatype"/>
 		
 		<convert id="saveto_other_object" mode="equals" sources="saveto_select.string" standard="other"/>
 		<connect governor="saveto_other_object" client="saveto.enabled"/>
@@ -58,7 +59,7 @@
 							</switch>
 							<switch condition="new_value_na" id="new_value_string">
 								<true standard="na" fixed_value="_NA_" />
-								<false dynamic_value="new_value_custom.text" />
+								<false dynamic_value="new_value_custom.valuequoted" />
 							</switch>
 						</logic>
 						<optioncolumn id="old_values_labelled" connect="old_value_string" label="Old value(s)"/>
@@ -67,7 +68,7 @@
 
 						<optioncolumn id="new_values_labelled" connect="new_value_string" label="New value(s)"/>
 						<optioncolumn id="new_value_types" connect="new_value.string"/>
-						<optioncolumn id="new_value_strings" connect="new_value_custom.text"/>
+						<optioncolumn id="new_value_strings" connect="new_value_custom.value"/>
 						<content>
 							<frame>
 								<optiondisplay index="true"/>
@@ -87,7 +88,7 @@
 											<option value="na" label="NA"/>
 											<option value="custom" label="Value:" checked="true"/>
 										</radio>
-										<input id="new_value_custom" label=""/>
+										<embed id="new_value_custom" component="rkward::multi_input"/>
 										<text id="quotation_note" type="normal">(Value will be quoted, automatically)</text>
 										<stretch/>
 									</column>
@@ -102,7 +103,7 @@
 				<option value="na" label="NA"/>
 				<option value="custom" label="Custom value:"/>
 			</radio>
-			<input id="other_custom" label=""/>
+			<embed id="other_custom" component="rkward::multi_input"/>
 			<stretch/>
 		</tab>
 	</tabbook></dialog>

Modified: trunk/rkward/rkward/plugins/embedded.pluginmap
===================================================================
--- trunk/rkward/rkward/plugins/embedded.pluginmap	2014-09-22 18:53:11 UTC (rev 4844)
+++ trunk/rkward/rkward/plugins/embedded.pluginmap	2014-09-26 18:04:39 UTC (rev 4845)
@@ -16,6 +16,8 @@
 
 		<component type="standard" id="x11grid" file="x11device/grid.xml" label="Draw Grid" />
 
+		<component type="standard" id="multi_input" file="data/multi_input.xml" label="Multi Input" />
+
 		<!-- This plugin does not really belong, here, but nowhere else, either, since it's only for the purpose of testing some things in the
 				automated tests. It definitely should not be shown in the menu, of course. -->
 		<component type="standard" id="testing_run_code" file="testing/run_code.xml" label="Run Code"/>





More information about the rkward-tracker mailing list