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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Sep 27 09:16:13 UTC 2012


Revision: 4318
          http://rkward.svn.sourceforge.net/rkward/?rev=4318&view=rev
Author:   tfry
Date:     2012-09-27 09:16:12 +0000 (Thu, 27 Sep 2012)
Log Message:
-----------
Display some status information in preview windows

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugin/rkpreviewbox.cpp
    trunk/rkward/rkward/plugin/rkpreviewbox.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp
    trunk/rkward/rkward/windows/rkwindowcatcher.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/ChangeLog	2012-09-27 09:16:12 UTC (rev 4318)
@@ -1,3 +1,4 @@
+- Preview device windows will display some status information (most importantly, warnings or errors)
 - Most plot plugins gain options to control margins and tick label orientation
 - Added option for installing packages from source (implicitly enabled on Unixoid platforms)
 - Fixed: Wrong handling of carriage returns ('\r') in the console window				TODO: also fix for the command log and other places

Modified: trunk/rkward/rkward/plugin/rkpreviewbox.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkpreviewbox.cpp	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/plugin/rkpreviewbox.cpp	2012-09-27 09:16:12 UTC (rev 4318)
@@ -20,20 +20,26 @@
 #include <qlabel.h>
 #include <qcheckbox.h>
 #include <qtimer.h>
+#include <QTextDocument>
 
 #include <klocale.h>
 
 #include "../rkglobals.h"
 #include "../rbackend/rinterface.h"
 #include "../misc/xmlhelper.h"
+#include "../windows/rkwindowcatcher.h"
 #include "../debug.h"
 
+#define START_DEVICE 101
+#define DO_PLOT 102
+
 RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
 
 	preview_active = false;
 	last_plot_done = true;
 	new_plot_pending = false;
+	dev_num = 0;
 
 	// get xml-helper
 	XMLHelper *xml = XMLHelper::getStaticHelper ();
@@ -113,6 +119,12 @@
 	updateStatusLabel ();
 }
 
+void RKPreviewBox::previewWindowClosed () {
+	RK_TRACE (PLUGIN);
+
+	dev_num = 0;
+}
+
 void RKPreviewBox::tryPreviewNow () {
 	RK_TRACE (PLUGIN);
 
@@ -120,6 +132,9 @@
 	ComponentStatus s = parentComponent ()->recursiveStatus ();
 	if (s != Satisfied) {
 		if (s == Processing) tryPreview ();
+		else {
+			RKCaughtX11Window::setStatusMessage (dev_num, i18n ("Preview not (currently) possible"));
+		}
 		return;
 	}
 
@@ -131,8 +146,9 @@
 
 	preview_active = true;
 	QString dummy;
-	RKGlobals::rInterface ()->issueCommand (dummy.sprintf (".rk.startPreviewDevice (\"%p\")", this), RCommand::Plugin | RCommand::Sync);
-	RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "})\n", RCommand::Plugin | RCommand::Sync, QString::null, this);
+	RKGlobals::rInterface ()->issueCommand (dummy.sprintf (".rk.startPreviewDevice (\"%p\")", this), 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);
 
 	last_plot_done = false;
 	new_plot_pending = false;
@@ -152,12 +168,25 @@
 	new_plot_pending = false;
 }
 
-void RKPreviewBox::rCommandDone (RCommand *) {
+void RKPreviewBox::rCommandDone (RCommand *command) {
 	RK_TRACE (PLUGIN);
 
 	last_plot_done = true;
 	if (new_plot_pending) tryPreview ();
 
+	if (command->getFlags () == START_DEVICE) {
+		int old_devnum = dev_num;
+		dev_num = command->intVector ().value (0, 0);
+		if (dev_num != old_devnum) {
+			disconnect (this, SLOT (previewWindowClosed()));
+			RKCaughtX11Window *window = RKCaughtX11Window::getWindow (dev_num);
+			if (window) connect (window, SIGNAL (destroyed(QObject*)), this, SLOT(previewWindowClosed()));
+		}
+	} else if (command->getFlags () == DO_PLOT) {
+		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);
+	}
 	updateStatusLabel ();
 }
 

Modified: trunk/rkward/rkward/plugin/rkpreviewbox.h
===================================================================
--- trunk/rkward/rkward/plugin/rkpreviewbox.h	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/plugin/rkpreviewbox.h	2012-09-27 09:16:12 UTC (rev 4318)
@@ -2,7 +2,7 @@
                           rkpreviewbox  -  description
                              -------------------
     begin                : Wed Jan 24 2007
-    copyright            : (C) 2007 by Thomas Friedrichsmeier
+    copyright            : (C) 2007,2 012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -47,6 +47,7 @@
 	void changedState (RKComponentPropertyBase *);
 	void changedCode (RKComponentPropertyBase *);
 	void tryPreviewNow ();
+	void previewWindowClosed ();
 protected:
 	void rCommandDone (RCommand *);
 private:
@@ -57,6 +58,7 @@
 	void tryPreview ();
 	void killPreview ();
 	void updateStatusLabel ();
+	int dev_num;
 	QTimer *update_timer;
 	QCheckBox *toggle_preview_box;
 	QLabel *status_label;

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2012-09-27 09:16:12 UTC (rev 4318)
@@ -59,11 +59,14 @@
 		x11 (is.preview.device = TRUE)
 		if (devnum != dev.cur ()) {
 			.rk.variables$.rk.preview.devices[[x]] <- list (devnum=dev.cur(), par=par (no.readonly=TRUE))
+		} else {
+			return (0L)	# no device could be opened
 		}
 	} else {
 		dev.set (a$devnum)
 		par (a$par)
 	}
+	as.integer (dev.cur ())
 }
 
 #' @export
@@ -77,6 +80,20 @@
 	}
 }
 
+".rk.discard.preview.device.num" <- function (devnum) {
+	for (dev in names (.rk.variables$.rk.preview.devices)) {
+		if (.rk.variables$.rk.preview.devices[[dev]]$devnum == devnum) {
+			.rk.variables$.rk.preview.devices[[dev]] <- NULL
+			return (invisible (TRUE))
+		}
+	}
+	invisible (FALSE)
+}
+
+".rk.list.preview.device.numbers" <- function () {
+	unlist (sapply (.rk.variables$.rk.preview.devices, function (x) x$devnum))
+}
+
 .rk.variables$.rk.printer.devices <- list ()
 
 # see .rk.fix.assignmetns () in internal.R
@@ -105,6 +122,8 @@
 				.rk.variables$.rk.printer.devices[[as.character (which)]] <- NULL
 			}
 
+			rkward:::.rk.discard.preview.device.num(which)
+
 			return (ret)
 		})
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2012-09-27 09:16:12 UTC (rev 4318)
@@ -199,7 +199,7 @@
 		
 		# all open screen devices
 		.osd <- which (names (dev.list ()) %in% deviceIsInteractive ()) + 1
-		.opd <- unlist (.rk.variables$.rk.preview.devices)
+		.opd <- .rk.list.preview.device.numbers()
 		# to be managed devices:
 		if (length (.opd) > 0) .osd <-.osd [!(.osd %in% .opd)]
 		if (length (.osd) == 0) return (invisible ())

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2012-09-27 09:16:12 UTC (rev 4318)
@@ -2,7 +2,7 @@
                           rwindowcatcher.cpp  -  description
                              -------------------
     begin                : Wed May 4 2005
-    copyright            : (C) 2005, 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2005, 2006, 2007, 2009, 2010, 2011, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -521,6 +521,15 @@
 	}
 }
 
+// static
+void RKCaughtX11Window::setStatusMessage(int dev_num, const QString& message, RCommand* command) {
+	RK_TRACE (MISC);
+
+	RKCaughtX11Window *window = getWindow (dev_num);
+	if (!window) return;
+	window->setStatusMessage (message, command);
+}
+
 void RKCaughtX11Window::rCommandDone (RCommand *command) {
 	RK_TRACE (MISC);
 

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h	2012-09-27 07:44:24 UTC (rev 4317)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h	2012-09-27 09:16:12 UTC (rev 4318)
@@ -2,7 +2,7 @@
                           rwindowcatcher.h  -  description
                              -------------------
     begin                : Wed May 4 2005
-    copyright            : (C) 2005, 2006, 2009, 2010, 2011 by Thomas Friedrichsmeier
+    copyright            : (C) 2005, 2006, 2009, 2010, 2011, 2012 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -120,6 +120,9 @@
 This should be used, when the plot is currently out-of-date (e.g. when loading a plot from history), _not_ when the window
 is simply busy (e.g. when saving the current plot to history). */
 	void setStatusMessage (const QString& message, RCommand* command=0);
+/** static convencience wrapper around setStatusMessage (). Sets the message on the window corresponding to the given device number.
+ * NOTE: If no device exists (or isn't known to the system), this function does nothing */
+	static void setStatusMessage (int dev_num, const QString &message, RCommand *command=0);
 public slots:
 /** Fixed size action was (potentially) toggled. Update to the new state */
 	void fixedSizeToggled ();

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