[rkward/work/generalized_preview] rkward: Allow preview to be active by default, better handling of errors in data-previews, first "real" Import CSV preview.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 7 11:10:00 UTC 2016


Git commit 86a852880ab6047d605886c8e98e10257009ef8b by Thomas Friedrichsmeier.
Committed on 07/01/2016 at 11:08.
Pushed by tfry into branch 'work/generalized_preview'.

Allow preview to be active by default, better handling of errors in data-previews, first "real" Import CSV preview.

M  +3    -2    rkward/dataeditor/twintable.cpp
M  +2    -2    rkward/plugin/rkpreviewbox.cpp
M  +19   -7    rkward/plugins/00saveload/import/import_csv.js
M  +1    -0    rkward/plugins/00saveload/import/import_csv.xml

http://commits.kde.org/rkward/86a852880ab6047d605886c8e98e10257009ef8b

diff --git a/rkward/dataeditor/twintable.cpp b/rkward/dataeditor/twintable.cpp
index 7a80975..ecfab36 100644
--- a/rkward/dataeditor/twintable.cpp
+++ b/rkward/dataeditor/twintable.cpp
@@ -198,8 +198,9 @@ void TwinTable::setWindowStyleHint (const QString& hint) {
 	if (hint == "preview") { // preview skin: Squeeze header as much as possible
 		metaview->horizontalHeader ()->hide ();
 		metaview->setMinimumHeight (metaview->rowHeight (0));
-		splitter->setStretchFactor (0, 0);
-		splitter->setStretchFactor (1, 1);
+		// Now, I just don't understand QSplitter sizing, here... Despite stretch factors being set, metaview continues to be the first to grow.
+		// Forcing minimum heigt of dataview help allocating initial size to the dataview, though.
+		dataview->setMinimumHeight (dataview->rowHeight (0) * 5);
 	}
 	RKMDIWindow::setWindowStyleHint (hint);
 }
diff --git a/rkward/plugin/rkpreviewbox.cpp b/rkward/plugin/rkpreviewbox.cpp
index b3a9393..d8aca6e 100644
--- a/rkward/plugin/rkpreviewbox.cpp
+++ b/rkward/plugin/rkpreviewbox.cpp
@@ -38,7 +38,6 @@
 RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
 
-	preview_active = false;
 	prior_preview_done = true;
 	new_preview_pending = false;
 
@@ -47,6 +46,7 @@ RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_comp
 
 	preview_mode = (PreviewMode) xml->getMultiChoiceAttribute (element, "mode", "plot;data;custom", 0, DL_INFO);
 	placement = (PreviewPlacement) xml->getMultiChoiceAttribute (element, "placement", "default;attached;detached;docked", (preview_mode == PlotPreview) ? 0 : 3, DL_INFO);
+	preview_active = xml->getBoolAttribute (element, "active", false, DL_INFO);
 	idprop = RObject::rQuote (QString ().sprintf ("%p", this));
 
 	// create and add property
@@ -175,7 +175,7 @@ void RKPreviewBox::tryPreviewNow () {
 		// creating window generates warnings, sometimes. Don't make those part of the warnings shown for the preview -> separate command for the actual plot.
 		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)\n" + placement_command + "rk.edit(rkward::.rk.variables$.rk.preview.data[[" + idprop + "]])" + placement_end + "\n})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
+		RKGlobals::rInterface ()->issueCommand ("local({try({\n" + code_property->preview () + "\n})\nif(!exists(\"preview_data\",inherits=FALSE)) preview_data <- data.frame ('ERROR')\nrk.assign.preview.data(" + idprop + ", preview_data)\n})\n" + placement_command + "rk.edit(rkward::.rk.variables$.rk.preview.data[[" + idprop + "]])" + placement_end, RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
 	} else {
 		RKGlobals::rInterface ()->issueCommand ("local({\n" + placement_command + code_property->preview () + placement_end + "})\n", RCommand::Plugin | RCommand::Sync, QString (), this, DO_PREVIEW);
 	}
diff --git a/rkward/plugins/00saveload/import/import_csv.js b/rkward/plugins/00saveload/import/import_csv.js
index ecd4e2f..c3aee1e 100644
--- a/rkward/plugins/00saveload/import/import_csv.js
+++ b/rkward/plugins/00saveload/import/import_csv.js
@@ -1,4 +1,12 @@
+function preview () {
+	doCalculate (true);
+}
+
 function calculate () {
+	doCalculate (false);
+}
+
+function doCalculate (is_preview) {
 	var tableOptions = "";
 	var quick = getValue ("quick");
 	if (quick == "custom") quick = "table";   // Difference only relevant in UI
@@ -28,17 +36,21 @@ function calculate () {
 	// doing col class (what a pity...)
 	if (getValue("colclass") == "custoClass") echo( "colClasses = " + getValue ("custoClasses") + ",");
 	//doing what is left
-	echo (' na.strings = "' + getValue("na") + '", nrows = ' + getValue("nrows") + ', skip = ' + getValue("skip") + ', check.names = ' + getValue("checkname") + ', strip.white = ' + getValue("stripwhite") + ', blank.lines.skip = ' + getValue("blanklinesskip") + getValue("allow_escapes") + getValue("flush") + getValue("strings_as_factors") + ')\n');
+	var nrows = 'nrows = ' + (is_preview ? '50' : getString ("nrows"));  // limit preview to first 50 rows for efficiency
+	echo (' na.strings = "' + getValue("na") + '", ' + nrows + ', skip = ' + getValue("skip") + ', check.names = ' + getValue("checkname") + ', strip.white = ' + getValue("stripwhite") + ', blank.lines.skip = ' + getValue("blanklinesskip") + getValue("allow_escapes") + getValue("flush") + getValue("strings_as_factors") + ')\n');
 	echo ('\n');
-	comment ('copy from the local environment to globalenv()');
-	echo ('.GlobalEnv$' + getValue("name") + ' <- imported\n');
-	if (getValue ("doedit")) {
-		echo ('\n');
-		echo ('rk.edit (.GlobalEnv$' + getValue ("name") + ')\n');
+	if (is_preview) {
+		echo ('preview_data <- imported\n');
+	} else {
+		comment ('copy from the local environment to globalenv()');
+		echo ('.GlobalEnv$' + getValue("name") + ' <- imported\n');
+		if (getBoolean ("doedit")) {
+			echo ('\n');
+			echo ('rk.edit (.GlobalEnv$' + getValue ("name") + ')\n');
+		}
 	}
 }
 
 function printout () {
 	new Header (i18n ("Import text / csv data")).addFromUI ("file").addFromUI ("name").print ();
 }
-
diff --git a/rkward/plugins/00saveload/import/import_csv.xml b/rkward/plugins/00saveload/import/import_csv.xml
index 51f67f1..2478d3b 100644
--- a/rkward/plugins/00saveload/import/import_csv.xml
+++ b/rkward/plugins/00saveload/import/import_csv.xml
@@ -138,6 +138,7 @@
 					<saveobject id="name" initial="my.csv.data" label="Object to save to"/>
 					<checkbox id="doedit" value="1" value_unchecked="0" label="Open imported data for editing" checked="true" />
 				</frame>
+				<preview id="preview" active="true" mode="data"/>
 			</tab>
 			<tab id="tab_rows" label="Rows and Columns" >
 				<row>



More information about the rkward-tracker mailing list