[rkward/work/generalized_preview] rkward: Implement first generalized preview proof of concept (with obvious usability flaws).

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Dec 14 21:06:08 UTC 2015


Git commit d3d0a7a00a3b75edc1725b6452507d53c148bb35 by Thomas Friedrichsmeier.
Committed on 14/12/2015 at 21:05.
Pushed by tfry into branch 'work/generalized_preview'.

Implement first generalized preview proof of concept (with obvious usability flaws).

M  +30   -9    rkward/plugin/rkpreviewbox.cpp
M  +1    -0    rkward/plugin/rkpreviewbox.h
A  +12   -0    rkward/plugins/testing/preview.js
A  +11   -0    rkward/plugins/testing/preview.xml
M  +2    -0    rkward/plugins/under_development.pluginmap
M  +4    -5    rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R

http://commits.kde.org/rkward/d3d0a7a00a3b75edc1725b6452507d53c148bb35

diff --git a/rkward/plugin/rkpreviewbox.cpp b/rkward/plugin/rkpreviewbox.cpp
index 7bf9731..7bd8fc1 100644
--- a/rkward/plugin/rkpreviewbox.cpp
+++ b/rkward/plugin/rkpreviewbox.cpp
@@ -31,7 +31,7 @@
 #include "../debug.h"
 
 #define START_DEVICE 101
-#define DO_PLOT 102
+#define DO_PREVIEW 102
 
 RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
@@ -44,7 +44,7 @@ RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_comp
 	// get xml-helper
 	XMLHelper *xml = parent_component->xmlHelper ();
 
-	preview_mode = (PreviewMode) xml->getMultiChoiceAttribute (element, "mode", "plot;data;custom", 0);
+	preview_mode = (PreviewMode) xml->getMultiChoiceAttribute (element, "mode", "plot;data;custom", 0, DL_INFO);
 	idprop = RObject::rQuote (QString ().sprintf ("%p", this));
 
 	// create and add property
@@ -144,7 +144,7 @@ void RKPreviewBox::tryPreviewNow () {
 	if (s != Satisfied) {
 		if (s == Processing) tryPreview ();
 		else {
-			RKCaughtX11Window::setStatusMessage (dev_num, i18n ("Preview not (currently) possible"));
+			setStatusMessage (i18n ("Preview not (currently) possible"));
 		}
 		return;
 	}
@@ -156,9 +156,16 @@ void RKPreviewBox::tryPreviewNow () {
 	}
 
 	preview_active = true;
-	RKGlobals::rInterface ()->issueCommand (".rk.startPreviewDevice (" + idprop + ')', RCommand::Plugin | RCommand::Sync | RCommand::GetIntVector, QString (), this, START_DEVICE);
-	RKCaughtX11Window::setStatusMessage (dev_num, i18n ("Preview updating"));
-	RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PLOT);
+
+	if (preview_mode == PlotPreview) {
+		RKGlobals::rInterface ()->issueCommand (".rk.startPreviewDevice (" + idprop + ')', RCommand::Plugin | RCommand::Sync | RCommand::GetIntVector, QString (), this, START_DEVICE);
+		setStatusMessage (i18n ("Preview updating"));
+		RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
+	} else if (preview_mode == DataPreview) {
+		RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "\nrk.assign.preview.data(" + idprop + ", preview_data)\nrk.edit(rkward::.rk.variables$.rk.preview.data[[" + idprop + "]])\n})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
+	} else {
+		RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
+	}
 
 	prior_preview_done = false;
 	new_preview_pending = false;
@@ -166,12 +173,26 @@ void RKPreviewBox::tryPreviewNow () {
 	updateStatusLabel ();
 }
 
+void RKPreviewBox::setStatusMessage(const QString& status) {
+	RK_TRACE (PLUGIN);
+
+	if (preview_mode == PlotPreview) {
+		RKCaughtX11Window::setStatusMessage (dev_num, status);
+	} else {
+#warning TODO
+	}
+}
+
 void RKPreviewBox::killPreview () {
 	RK_TRACE (PLUGIN);
 
 	if (!preview_active) return;
 	preview_active = false;
-	RKGlobals::rInterface ()->issueCommand (".rk.killPreviewDevice (" + idprop + ')', RCommand::Plugin | RCommand::Sync);
+
+	QString command;
+	if (preview_mode == PlotPreview) command = ".rk.killPreviewDevice (" + idprop + ')';
+	else command = "rk.discard.preview.data (" + idprop + ')';
+	RKGlobals::rInterface ()->issueCommand (command, RCommand::Plugin | RCommand::Sync);
 
 	prior_preview_done = true;
 	new_preview_pending = false;
@@ -191,10 +212,10 @@ void RKPreviewBox::rCommandDone (RCommand *command) {
 			RKCaughtX11Window *window = RKCaughtX11Window::getWindow (dev_num);
 			if (window) connect (window, SIGNAL (destroyed(QObject*)), this, SLOT(previewWindowClosed()));
 		}
-	} else if (command->getFlags () == DO_PLOT) {
+	} else if (command->getFlags () == DO_PREVIEW) {
 		QString warnings = command->warnings () + command->error ();
 		if (!warnings.isEmpty ()) warnings = QString ("<b>%1</b>\n<pre>%2</pre>").arg (i18n ("Warnings or Errors:")).arg (Qt::escape (warnings));
-		RKCaughtX11Window::setStatusMessage (dev_num, warnings);
+		setStatusMessage (warnings);
 	}
 	updateStatusLabel ();
 }
diff --git a/rkward/plugin/rkpreviewbox.h b/rkward/plugin/rkpreviewbox.h
index 11029ea..470049c 100644
--- a/rkward/plugin/rkpreviewbox.h
+++ b/rkward/plugin/rkpreviewbox.h
@@ -58,6 +58,7 @@ private:
 	void tryPreview ();
 	void killPreview ();
 	void updateStatusLabel ();
+	void setStatusMessage (const QString& status);
 	int dev_num;
 	enum PreviewMode {
 		PlotPreview,
diff --git a/rkward/plugins/testing/preview.js b/rkward/plugins/testing/preview.js
new file mode 100644
index 0000000..18dd918
--- /dev/null
+++ b/rkward/plugins/testing/preview.js
@@ -0,0 +1,12 @@
+function preview () {
+	doPrintout (false);
+}
+
+function printout () {
+	doPrintout (true);
+}
+
+function doPrintout (real) {
+	echo ('x <- as.data.frame (matrix (' + getString ("value") + ', nrow=' + getString ("size") + ', ncol=' + getString ("size") + '))\n');
+	if (!real) echo ('preview_data <- x');
+}
\ No newline at end of file
diff --git a/rkward/plugins/testing/preview.xml b/rkward/plugins/testing/preview.xml
new file mode 100644
index 0000000..0088fad
--- /dev/null
+++ b/rkward/plugins/testing/preview.xml
@@ -0,0 +1,11 @@
+<!DOCTYPE rkplugin>
+
+<document>
+	<code file="preview.js"/>
+
+	<dialog label="Testing various preview features">
+		<spinbox id="size" type="integer" min="0" label="Size" initial="3"/>
+		<spinbox id="value" type="real" min="0" label="Value" initial="1.23"/>
+		<preview mode="data" label="Preview data"/>
+	</dialog>
+</document> 
diff --git a/rkward/plugins/under_development.pluginmap b/rkward/plugins/under_development.pluginmap
index 21bbe3e..319f68a 100644
--- a/rkward/plugins/under_development.pluginmap
+++ b/rkward/plugins/under_development.pluginmap
@@ -21,6 +21,7 @@
 		<component type="standard" id="sort_data2" file="data/sort2.xml" label="Sort data (Variant 2)" />
 
 <!-- These are purely for testing: -->
+		<component type="standard" id="preview_test" file="testing/preview.xml" label="Preview Test" />
 		<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="optionset_test" file="testing/optionset.xml" label="Optionset Test" />
@@ -54,6 +55,7 @@
 			<entry component="optionset_test" group="testing"/>
 			<entry component="matrix_test1" group="testing"/>
 			<entry component="valueselect_test1" group="testing"/>
+			<entry component="preview_test" group="testing"/>
 		</menu>
 		<menu id="plots" label="Plots">
 			<group id="testing" group="bottom" separated="true"/>
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index ad70b7d..5093d39 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -230,11 +230,9 @@ assign(".rk.preview.data", list (), envir=.rk.variables)
 #' @aliases rk.get.preview.data .rk.discard.preview.data
 "rk.assign.preview.data" <- function (id, value=list ()) {
 	pdata <- .rk.variables$.rk.preview.data
-	if (is.null (pdata[[id]])) {
-		pdata[[id]] <- value
-		assign (".rk.preview.data", pdata, envir=.rk.variables)
-		rk.sync (.rk.variables$.rk.preview.data)
-	}
+	pdata[[id]] <- value
+	assign (".rk.preview.data", pdata, envir=.rk.variables)
+	rk.sync (.rk.variables$.rk.preview.data)
 	invisible (pdata[[id]])
 }
 
@@ -251,5 +249,6 @@ assign(".rk.preview.data", list (), envir=.rk.variables)
 	if (!is.null (pdata[[id]]) && !is.null (pdata[[id]]$on.exit)) pdata[[id]]$on.delete (id)
 	pdata[[id]] <- NULL
 	assign (".rk.preview.data", pdata, envir=.rk.variables)
+	rk.sync (.rk.variables$.rk.preview.data)
 	invisible (NULL)
 }



More information about the rkward-tracker mailing list