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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Mar 7 20:30:23 UTC 2010


Revision: 2773
          http://rkward.svn.sourceforge.net/rkward/?rev=2773&view=rev
Author:   tfry
Date:     2010-03-07 20:30:23 +0000 (Sun, 07 Mar 2010)

Log Message:
-----------
Add basic support for specifying SVG as output format.
For now, PNG continues to be the default, as khtmlpart does not display the SVGs quite correctly (at least, here, it doesn't)

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
    trunk/rkward/rkward/rbackend/rthread.cpp
    trunk/rkward/rkward/resource.ver
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
    trunk/rkward/rkward/version.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/ChangeLog	2010-03-07 20:30:23 UTC (rev 2773)
@@ -1,3 +1,5 @@
+- Add basic settings format settings for graphics output		TODO: somehow, SVG does not work correctly in khtmlpart, thus not the default for now. Can we do anything about this?
+- Convert all plugins to use ECMAscript instead of PHP; RKWard no longer depends on PHP
 - Fixed: Frequent crashes while running automated plugintests
 - Fixed: Filenames without extension would not be shown in file dialogs
 - Fixed: Calling "fix(my.fun)" would remove comments

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-03-07 20:30:23 UTC (rev 2773)
@@ -136,16 +136,37 @@
 }
 
 # Requests a graph to be written.
-"rk.graph.on" <- function (width=480, height=480, ...)
+rk.graph.on <- function (width=getOption ("rk.graphics.width"), height=getOption ("rk.graphics.heigth"), ...) 
 {
-    filename <- rk.get.tempfile.name(prefix = "graph", extension = ".png")
-    png(filename=file.path(filename), width=width, height=height, ...)
-    cat(paste("<img src=\"", filename, "\" width=\"", width, "\" height=\"", height, "\"><br>", sep = ""), 
-        file = rk.get.output.html.file(), append = TRUE)
+	if (!is.numeric (width)) width <- 480
+	if (!is.numeric (height)) height <- 480
+
+	device.type <- getOption ("rk.graphics.type")
+	if (is.null (device.type)) device.type <- "PNG"	# default behavior is PNG for now
+
+	ret <- NULL
+	if (device.type == "PNG") {
+		filename <- rk.get.tempfile.name(prefix = "graph", extension = ".png")
+		ret <- png(filename = file.path(filename), width = width, height = height, ...)
+		.rk.cat.output(paste("<img src=\"", filename, "\" width=\"", width, 
+			"\" height=\"", height, "\"><br>", sep = ""))
+	} else if (device.type == "SVG") {
+		filename <- rk.get.tempfile.name(prefix = "graph", extension = ".svg")
+		ret <- svg(filename = file.path(filename), ...)
+		.rk.cat.output(paste("<object data=\"", filename, "\" type=\"image/svg+xml\" width=\"", width, 
+			"\" height=\"", height, "\">\n", sep = ""))
+		.rk.cat.output(paste("<param name=\"src\" value=\"", filename, "\">\n", sep = ""))
+		.rk.cat.output(paste("This browser appears incapable of displaying SVG object. The SVG source is at:", filename))
+		.rk.cat.output("</object>")
+	} else {
+		stop (paste ("Device type \"", device.type, "\" is unknown to RKWard", sep=""))
+	}
+
+	invisible (ret)
 }
 
 "rk.graph.off" <- function(){
-	cat ("\n", file = rk.get.output.html.file(), append = TRUE)	# so the output will be auto-refreshed
+	.rk.cat.output ("\n")	# so the output will be auto-refreshed
 	dev.off()
 }
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/ver.R	2010-03-07 20:30:23 UTC (rev 2773)
@@ -1 +1 @@
-".rk.app.version" <- "0.5.2"
+".rk.app.version" <- "0.5.3-test1"

Modified: trunk/rkward/rkward/rbackend/rthread.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rthread.cpp	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/rbackend/rthread.cpp	2010-03-07 20:30:23 UTC (rev 2773)
@@ -19,6 +19,7 @@
 #include "rinterface.h"
 #include "rcommandstack.h"
 #include "../settings/rksettingsmoduler.h"
+#include "../settings/rksettingsmoduleoutput.h"
 #include "../settings/rksettingsmodulegeneral.h"
 #include "../rkglobals.h"
 #include "../rkward.h"		// for startup options
@@ -514,7 +515,7 @@
 	delete [] help_base_url;
 
 // apply user configurable run time options
-	QStringList commands = RKSettingsModuleR::makeRRunTimeOptionCommands () + RKSettingsModuleRPackages::makeRRunTimeOptionCommands ();
+	QStringList commands = RKSettingsModuleR::makeRRunTimeOptionCommands () + RKSettingsModuleRPackages::makeRRunTimeOptionCommands () + RKSettingsModuleOutput::makeRRunTimeOptionCommands ();
 	for (QStringList::const_iterator it = commands.begin (); it != commands.end (); ++it) {
 		runCommandInternal ((*it).toLocal8Bit (), &error);
 		if (error) {

Modified: trunk/rkward/rkward/resource.ver
===================================================================
--- trunk/rkward/rkward/resource.ver	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/resource.ver	2010-03-07 20:30:23 UTC (rev 2773)
@@ -1 +1 @@
-0.5.2
+0.5.3-test1

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-03-07 20:30:23 UTC (rev 2773)
@@ -2,7 +2,7 @@
                           rksettingsmoduleoutput  -  description
                              -------------------
     begin                : Fri Jul 30 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -19,19 +19,25 @@
 #include <klocale.h>
 #include <kconfig.h>
 #include <kconfiggroup.h>
+#include <knuminput.h>
 
 #include <qlayout.h>
 #include <qlabel.h>
 #include <QGroupBox>
 #include <qcheckbox.h>
 #include <QVBoxLayout>
+#include <QComboBox>
 
 #include "../rkglobals.h"
+#include "../rbackend/rinterface.h"
 #include "../debug.h"
 
 // static members
 bool RKSettingsModuleOutput::auto_show;
 bool RKSettingsModuleOutput::auto_raise;
+QString RKSettingsModuleOutput::graphics_type;
+int RKSettingsModuleOutput::graphics_width;
+int RKSettingsModuleOutput::graphics_height;
 
 RKSettingsModuleOutput::RKSettingsModuleOutput (RKSettings *gui, QWidget *parent) : RKSettingsModule(gui, parent) {
 	RK_TRACE (SETTINGS);
@@ -40,16 +46,41 @@
 	
 	QGroupBox *group = new QGroupBox (i18n ("Output Window options"), this);
 	QVBoxLayout* group_layout = new QVBoxLayout (group);
-	group_layout->addWidget (auto_show_box = new QCheckBox ("show window on new output", group));
+	group_layout->addWidget (auto_show_box = new QCheckBox (i18n ("show window on new output"), group));
 	auto_show_box->setChecked (auto_show);
 	connect (auto_show_box, SIGNAL (stateChanged (int)), this, SLOT (boxChanged (int)));
-	group_layout->addWidget (auto_raise_box = new QCheckBox ("raise window on new output", group));
+	group_layout->addWidget (auto_raise_box = new QCheckBox (i18n ("raise window on new output"), group));
 	auto_raise_box->setChecked (auto_raise);
 	auto_raise_box->setEnabled (auto_show);
 	connect (auto_raise_box, SIGNAL (stateChanged (int)), this, SLOT (boxChanged (int)));
 
 	main_vbox->addWidget (group);
 
+	group = new QGroupBox (i18n ("Graphics"), this);
+	group_layout = new QVBoxLayout (group);
+	QHBoxLayout *h_layout = new QHBoxLayout (group);
+	group_layout->addLayout (h_layout);
+	h_layout->addWidget (new QLabel (i18n ("File format"), group));
+	h_layout->addWidget (graphics_type_box = new QComboBox (group));
+	h_layout->addStretch ();
+	graphics_type_box->addItem (i18n ("<Default>"), QString ("NULL"));
+	graphics_type_box->addItem (i18n ("PNG"), QString ("\"PNG\""));
+	graphics_type_box->addItem (i18n ("SVG"), QString ("\"SVG\""));
+	graphics_type_box->setCurrentIndex (graphics_type_box->findData (graphics_type));
+	graphics_type_box->setEditable (false);
+	connect (graphics_type_box, SIGNAL (currentIndexChanged (int)), this, SLOT (boxChanged (int)));
+	h_layout = new QHBoxLayout (group);
+	group_layout->addLayout (h_layout);
+	h_layout->addWidget (new QLabel (i18n ("Width:"), group));
+	h_layout->addWidget (graphics_width_box = new KIntSpinBox (1, INT_MAX, 1, graphics_width, group));
+	h_layout->addWidget (new QLabel (i18n ("Height:"), group));
+	h_layout->addWidget (graphics_height_box = new KIntSpinBox (1, INT_MAX, 1, graphics_height, group));
+	h_layout->addStretch ();
+	connect (graphics_width_box, SIGNAL (valueChanged (int)), this, SLOT (boxChanged (int)));
+	connect (graphics_height_box, SIGNAL (valueChanged (int)), this, SLOT (boxChanged (int)));
+
+	main_vbox->addWidget (group);
+
 	main_vbox->addStretch ();
 }
 
@@ -78,6 +109,14 @@
 
 	auto_show = auto_show_box->isChecked ();
 	auto_raise = auto_raise_box->isChecked ();
+
+	graphics_type = graphics_type_box->itemData (graphics_type_box->currentIndex ()).toString ();
+	graphics_width = graphics_width_box->value ();
+	graphics_height = graphics_height_box->value ();
+	QStringList commands = makeRRunTimeOptionCommands ();
+	for (QStringList::const_iterator it = commands.begin (); it != commands.end (); ++it) {
+		RKGlobals::rInterface ()->issueCommand (*it, RCommand::App, QString::null, 0, 0, commandChain ());
+	}
 }
 
 void RKSettingsModuleOutput::save (KConfig *config) {
@@ -92,6 +131,9 @@
 	KConfigGroup cg = config->group ("Output Window");
 	cg.writeEntry ("auto_show", auto_show);
 	cg.writeEntry ("auto_raise", auto_raise);
+	cg.writeEntry ("graphics_type", graphics_type);
+	cg.writeEntry ("graphics_width", graphics_width);
+	cg.writeEntry ("graphics_height", graphics_height);
 }
 
 void RKSettingsModuleOutput::loadSettings (KConfig *config) {
@@ -100,6 +142,22 @@
 	KConfigGroup cg = config->group ("Output Window");
 	auto_show = cg.readEntry ("auto_show", true);
 	auto_raise = cg.readEntry ("auto_raise", true);
+	graphics_type = cg.readEntry ("graphics_type", "NULL");
+	graphics_width = cg.readEntry ("graphics_width", 480);
+	graphics_height = cg.readEntry ("graphics_height", 480);
 }
 
+//static
+QStringList RKSettingsModuleOutput::makeRRunTimeOptionCommands () {
+	QStringList list;
+
+// output format options
+	QString command = "options (\"rk.graphics.type\"=" + graphics_type;
+	command.append (", \"rk.graphics.width\"=" + QString::number (graphics_width));
+	command.append (", \"rk.graphics.height\"=" + QString::number (graphics_height));
+	list.append (command + ")\n");
+	
+	return (list);
+}
+
 #include "rksettingsmoduleoutput.moc"

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-03-07 20:30:23 UTC (rev 2773)
@@ -2,7 +2,7 @@
                           rksettingsmoduleoutput  -  description
                              -------------------
     begin                : Fri Jul 30 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2010 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -19,7 +19,11 @@
 
 #include "rksettingsmodule.h"
 
+#include <QStringList>
+
 class QCheckBox;
+class QComboBox;
+class KIntSpinBox;
 
 /**
 @author Thomas Friedrichsmeier
@@ -27,13 +31,15 @@
 class RKSettingsModuleOutput : public RKSettingsModule {
 	Q_OBJECT
 public:
-    RKSettingsModuleOutput (RKSettings *gui, QWidget *parent);
-
-    ~RKSettingsModuleOutput ();
+	RKSettingsModuleOutput (RKSettings *gui, QWidget *parent);
+	~RKSettingsModuleOutput ();
 	
 	bool hasChanges ();
 	void applyChanges ();
 	void save (KConfig *config);
+
+/** generate the commands needed to set the R run time options */
+	static QStringList makeRRunTimeOptionCommands ();
 	
 	static void saveSettings (KConfig *config);
 	static void loadSettings (KConfig *config);
@@ -47,9 +53,15 @@
 private:
 	QCheckBox *auto_show_box;
 	QCheckBox *auto_raise_box;
+	QComboBox *graphics_type_box;
+	KIntSpinBox *graphics_width_box;
+	KIntSpinBox *graphics_height_box;
 
 	static bool auto_show;
 	static bool auto_raise;
+	static QString graphics_type;
+	static int graphics_width;
+	static int graphics_height;
 };
 
 #endif

Modified: trunk/rkward/rkward/version.h
===================================================================
--- trunk/rkward/rkward/version.h	2010-03-07 12:05:09 UTC (rev 2772)
+++ trunk/rkward/rkward/version.h	2010-03-07 20:30:23 UTC (rev 2773)
@@ -1,2 +1,2 @@
 /* Version number of package */
-#define VERSION "0.5.2"
+#define VERSION "0.5.3-test1"


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