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

kapatp at users.sourceforge.net kapatp at users.sourceforge.net
Sat Sep 11 13:25:18 UTC 2010


Revision: 3014
          http://rkward.svn.sourceforge.net/rkward/?rev=3014&view=rev
Author:   kapatp
Date:     2010-09-11 13:25:18 +0000 (Sat, 11 Sep 2010)

Log Message:
-----------
Dynamically enable/disable plot history.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2010-09-11 13:25:18 UTC (rev 3014)
@@ -23,6 +23,7 @@
 
 	.rk.do.call ("endOpenX11", as.character (dev.cur ()));
 
+	if (getOption ("rk.enable.graphics.history"))
 	rk.record.plot$onAddDevice (old_dev, dev.cur (), is.being.duplicated, is.preview.device)
 
 	invisible (x)
@@ -43,7 +44,6 @@
 ".rk.preview.devices" <- list ();
 
 ".rk.startPreviewDevice" <- function (x) {
-	rk.record.plot$getDevSummary() ## DEBUG
 	a <- .rk.preview.devices[[x]]
 	if (is.null (a)) {
 		a <- dev.cur ()
@@ -54,7 +54,6 @@
 	} else {
 		dev.set (a)
 	}
-	rk.record.plot$getDevSummary() ## DEBUG
 }
 
 ".rk.killPreviewDevice" <- function (x) {
@@ -70,10 +69,12 @@
 "plot.new" <- function () 
 {
 	if (dev.cur() == 1) rk.screen.device ()
+	if (getOption ("rk.enable.graphics.history")) {
 rk.record.plot$.my.message ("------- call begin -----------")
 	.callstr <- sys.call (-sys.parents()[sys.nframe ()])
 	rk.record.plot$record (nextplot.pkg = "graphics", nextplot.call = .callstr)
 rk.record.plot$.my.message ("------- call end   -----------")
+	}
 	eval (body (.rk.plot.new.default))
 }
 formals (plot.new) <- formals (graphics::plot.new)
@@ -81,6 +82,7 @@
 
 "dev.off" <- function (which = dev.cur ())
 {
+	if (getOption ("rk.enable.graphics.history"))
 	rk.record.plot$onDelDevice (devId = which)
 	
 	# see http://thread.gmane.org/gmane.comp.statistics.rkward.devel/802
@@ -105,13 +107,17 @@
 			{
 				if (dev.cur() == 1) rk.screen.device ()
 				## TODO: use "trellis" instead of "lattice" to accomodate ggplot2 plots?
+				if (getOption ("rk.enable.graphics.history")) {
 rk.record.plot$.my.message ("------- call begin -----------")
 				rk.record.plot$record (nextplot.pkg = "lattice")
 rk.record.plot$.my.message ("------- call end   -----------")
+				}
 				plot (x, ...)
+				if (getOption ("rk.enable.graphics.history")) {
 rk.record.plot$.my.message ("------- call begin -----------")
 				rk.record.plot$.save.tlo.in.hP ()
 rk.record.plot$.my.message ("------- call end   -----------")
+				}
 				invisible ()
 			})
 	)
@@ -121,11 +127,14 @@
 		function (...)
 		{
 			if (dev.cur() == 1) rk.screen.device ()
+			if (getOption ("rk.enable.graphics.history")) {
 rk.record.plot$.my.message ("------- call begin -----------")
 			.callstr <- sys.call (-which.max(sys.parents()))
 			rk.record.plot$record (nextplot.pkg = "graphics", nextplot.call = .callstr)
 rk.record.plot$.my.message ("------- call end   -----------")
+			}
 		},
 		action = "append"
 	)
 }
+

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-09-11 13:25:18 UTC (rev 3014)
@@ -429,3 +429,4 @@
 	else if (res < 0) return (FALSE)
 	else return (NULL)	# cancelled
 }
+

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2010-09-11 13:25:18 UTC (rev 3014)
@@ -68,11 +68,13 @@
 ## o/w a user call of dev.set () and dev.copy () will not be set/initiate the history properly
 "rk.activate.device" <- function (devId = dev.cur ())
 {
+	dev.set (devId)
+	if (getOption ("rk.enable.graphics.history")) {
 	rk.record.plot$.my.message ("------- call begin -----------")
-	dev.set (devId)
 	rk.record.plot$.set.trellis.last.object ()
 	rk.record.plot$getDevSummary ()
 	rk.record.plot$.my.message ("------- call end   -----------")
+	}
 }
 
 # A global history of various graphics calls;
@@ -167,6 +169,27 @@
 		.my.message ("------- call end   -----------")
 		invisible ()
 	}
+	initialize.histPositions <- function ()
+	{
+		# this is called from rk.toggle.plot.history ()
+		on.exit (.rk.update.hist.actions (enable.plot.hist = TRUE))
+		
+		# all open screen devices
+		.osd <- which (names (dev.list ()) %in% deviceIsInteractive ()) + 1
+		.opd <- unlist (.rk.preview.devices)
+		# to be managed devices:
+		if (length (.opd) > 0) .osd <-.osd [!(.osd %in% .opd)]
+		if (length (.osd) == 0) return (invisible ())
+		modifyList
+		
+		rk.show.message ("RKWard will re-initiate recording. For empty devices you may see an initial error.")
+		histPositions <<- list ("1" = .hP.template)
+		for (d in as.character (.osd))
+			histPositions [[d]] <<- modifyList(.hP.template, 
+					list (is.this.plot.new = TRUE, is.this.dev.new = FALSE, pkg = "unknown"))
+		.set.hP.names ()
+		getDevSummary ()
+	}
 	onDelDevice <- function (devId = dev.cur())
 	{
 		.my.message ("------- call begin -----------")
@@ -183,6 +206,19 @@
 		.my.message ("------- call end   -----------")
 		invisible ()
 	}
+	flushout.histPositions <- function ()
+	{
+		# this is called from rk.toggle.plot.history ()
+		
+		# save any unsaved plots and "close" the device w/o actually closing the window:
+		getDevSummary ()
+		for (d in .hP.names)
+			record (devId = d, action = "dev.off")
+		getDevSummary ()
+		.rk.update.hist.actions (enable.plot.hist = FALSE)
+		histPositions <<- list ("1" = .hP.template)
+		getDevSummary ()
+	}
 	.save.tlo.in.hP <- function (devId = dev.cur ())
 	{
 		.my.message ("in: .save.tlo.in.hP")
@@ -743,7 +779,7 @@
 	}
 	
 	## Utility / R - C++ connection functions:
-	.rk.update.hist.actions <- function (devIds = .hP.names)
+	.rk.update.hist.actions <- function (devIds = .hP.names, enable.plot.hist = TRUE)
 	{
 		# this function is called whenever the history length changes
 		# or the position changes in any device.
@@ -758,7 +794,7 @@
 			#labels <- NULL
 			#if (sP.length > 0) labels <- sapply (1:sP.length, function (x) try (.get.oldplot.call (x, .cll)))
 			labels <- .get.sP.calls ()
-			.rk.do.call ("updateDeviceHistory", c (sP.length, labels, positions));
+			.rk.do.call ("updateDeviceHistory", c (ifelse (enable.plot.hist, sP.length, 0), labels, positions));
 			.my.message ("uDHA call:")
 			.my.message ("  length: ", sP.length)
 			.my.message ("  positions: ", paste (positions, collapse = ", "))
@@ -797,8 +833,19 @@
 # Users should use only these wrappers:
 # 1 is always the null device
 # TODO : comment / remove getDevSummary call
+"rk.toggle.plot.history" <- function (x = TRUE)
+{
+	if (x) {
+		rk.record.plot$initialize.histPositions ()
+	} else {
+		rk.record.plot$flushout.histPositions ()
+	}
+	options ("rk.enable.graphics.history" = x)
+	invisible ()
+}
 "rk.first.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$showFirst (devId)
 	rk.record.plot$getDevSummary ()
@@ -806,6 +853,7 @@
 }
 "rk.previous.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$showPrevious (devId)
 	rk.record.plot$getDevSummary ()
@@ -813,6 +861,7 @@
 }
 "rk.next.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$showNext (devId)
 	rk.record.plot$getDevSummary ()
@@ -820,12 +869,15 @@
 }
 "rk.last.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$showLast (devId)
 	rk.record.plot$getDevSummary ()
 	rk.record.plot$.my.message ("------- call end   -----------")
 }
-"rk.goto.plot" <- function (devId = dev.cur (), index=1) {
+"rk.goto.plot" <- function (devId = dev.cur (), index=1)
+{
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$.my.message ("in: goto.plot")
 	rk.record.plot$.my.message ("index: ", index)
@@ -835,6 +887,7 @@
 }
 "rk.force.append.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$forceAppend (devId)
 	rk.record.plot$getDevSummary ()
@@ -842,6 +895,7 @@
 }
 "rk.removethis.plot" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$removePlot (devId)
 	rk.record.plot$getDevSummary ()
@@ -849,18 +903,21 @@
 }
 "rk.clear.plot.history" <- function ()
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$clearHistory ()
 	rk.record.plot$.my.message ("------- call end   -----------")
 }
 "rk.show.plot.info" <- function (devId = dev.cur ())
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$showPlotInfo (devId)
 	rk.record.plot$.my.message ("------- call end   -----------")
 }
 "rk.verify.plot.hist.limits" <- function (lmax)
 {
+	if (!getOption ("rk.enable.graphics.history")) return (invisible ())
 	rk.record.plot$.my.message ("------- call begin -----------")
 	rk.record.plot$.verify.hist.limits (as.integer (lmax))
 	rk.record.plot$.my.message ("------- call end   -----------")

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.cpp	2010-09-11 13:25:18 UTC (rev 3014)
@@ -39,6 +39,7 @@
 int RKSettingsModuleOutput::graphics_width;
 int RKSettingsModuleOutput::graphics_height;
 int RKSettingsModuleOutput::graphics_jpg_quality;
+bool RKSettingsModuleOutput::graphics_hist_enable;
 int RKSettingsModuleOutput::graphics_hist_max_length;
 int RKSettingsModuleOutput::graphics_hist_max_plotsize;
 
@@ -94,14 +95,19 @@
 
 	group = new QGroupBox (i18n ("Screen device history"), this);
 	group_layout = new QVBoxLayout (group);
+	group_layout->addWidget (graphics_hist_enable_box = new QCheckBox (i18n ("enable screen device history"), group));
+	graphics_hist_enable_box->setChecked (graphics_hist_enable);
+	connect (graphics_hist_enable_box, SIGNAL (stateChanged (int)), this, SLOT (boxChanged (int)));
 	h_layout = new QHBoxLayout (group);
 	group_layout->addLayout (h_layout);
 	h_layout->addWidget (new QLabel (i18n ("Maximum number of recorded plots:"), group));
 	h_layout->addWidget (graphics_hist_max_length_box = new KIntSpinBox (1, 200, 1, graphics_hist_max_length, group));
+	graphics_hist_max_length_box->setEnabled (graphics_hist_enable);
 	h_layout = new QHBoxLayout (group);
 	group_layout->addLayout (h_layout);
 	h_layout->addWidget (new QLabel (i18n ("Maximum size of a single recorded plot (in KB):"), group));
 	h_layout->addWidget (graphics_hist_max_plotsize_box = new KIntSpinBox (4, 20000, 4, graphics_hist_max_plotsize, group)); // in KB
+	graphics_hist_max_plotsize_box->setEnabled (graphics_hist_enable);
 	connect (graphics_hist_max_length_box, SIGNAL (valueChanged (int)), this, SLOT (boxChanged (int)));
 	connect (graphics_hist_max_plotsize_box, SIGNAL (valueChanged (int)), this, SLOT (boxChanged (int)));
 
@@ -118,6 +124,8 @@
 	RK_TRACE (SETTINGS);
 	change ();
 	auto_raise_box->setEnabled (auto_show_box->isChecked ());
+	graphics_hist_max_length_box->setEnabled (graphics_hist_enable_box->isChecked ());
+	graphics_hist_max_plotsize_box->setEnabled (graphics_hist_enable_box->isChecked ());
 	graphics_jpg_quality_box->setEnabled (graphics_type_box->itemData (graphics_type_box->currentIndex ()).toString () == "\"JPG\"");
 }
 
@@ -142,6 +150,7 @@
 	graphics_height = graphics_height_box->value ();
 	graphics_jpg_quality = graphics_jpg_quality_box->value ();
 
+	graphics_hist_enable = graphics_hist_enable_box->isChecked ();
 	graphics_hist_max_length = graphics_hist_max_length_box->value ();
 	graphics_hist_max_plotsize = graphics_hist_max_plotsize_box->value ();
 
@@ -167,6 +176,7 @@
 	cg.writeEntry ("graphics_width", graphics_width);
 	cg.writeEntry ("graphics_height", graphics_height);
 	cg.writeEntry ("graphics_jpg_quality", graphics_jpg_quality);
+	cg.writeEntry ("graphics_hist_enable", graphics_hist_enable);
 	cg.writeEntry ("graphics_hist_max_length", graphics_hist_max_length);
 	cg.writeEntry ("graphics_hist_max_plotsize", graphics_hist_max_plotsize);
 }
@@ -181,6 +191,7 @@
 	graphics_width = cg.readEntry ("graphics_width", 480);
 	graphics_height = cg.readEntry ("graphics_height", 480);
 	graphics_jpg_quality = cg.readEntry ("graphics_jpg_quality", 75);
+	graphics_hist_enable = cg.readEntry ("graphics_hist_enable", true);
 	graphics_hist_max_length = cg.readEntry ("graphics_hist_max_length", 20);
 	graphics_hist_max_plotsize = cg.readEntry ("graphics_hist_max_plotsize", 1024);
 }
@@ -196,7 +207,8 @@
 	if (graphics_type == "\"JPG\"") command.append (", \"rk.graphics.jpg.quality\"=" + QString::number (graphics_jpg_quality));
 	//command.append (", \"rk.graphics.hist.max.length\"=" + QString::number (graphics_hist_max_length));
 	command.append (", \"rk.graphics.hist.max.plotsize\"=" + QString::number (graphics_hist_max_plotsize));
-	list.append (command + ")\nrk.verify.plot.hist.limits (" + QString::number (graphics_hist_max_length) + ")\n");
+	command.append (")\nrk.toggle.plot.history (" + QString (graphics_hist_enable?"TRUE":"FALSE") + ")\n");
+	list.append (command + "rk.verify.plot.hist.limits (" + QString::number (graphics_hist_max_length) + ")\n");
 	
 	return (list);
 }

Modified: trunk/rkward/rkward/settings/rksettingsmoduleoutput.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/settings/rksettingsmoduleoutput.h	2010-09-11 13:25:18 UTC (rev 3014)
@@ -57,6 +57,7 @@
 	KIntSpinBox *graphics_width_box;
 	KIntSpinBox *graphics_height_box;
 	KIntSpinBox *graphics_jpg_quality_box;
+	QCheckBox *graphics_hist_enable_box;
 	KIntSpinBox *graphics_hist_max_length_box;
 	KIntSpinBox *graphics_hist_max_plotsize_box;
 
@@ -66,6 +67,7 @@
 	static int graphics_width;
 	static int graphics_height;
 	static int graphics_jpg_quality;
+	static bool graphics_hist_enable;
 	static int graphics_hist_max_length;
 	static int graphics_hist_max_plotsize;
 };

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-11 12:50:31 UTC (rev 3013)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2010-09-11 13:25:18 UTC (rev 3014)
@@ -455,8 +455,8 @@
 	RKCaughtX11Window::history_length = history_length;
 	RKCaughtX11Window::history_position = position;
 
-	plot_first_action->setEnabled (position > 1);
-	plot_prev_action->setEnabled (position > 1);
+	plot_first_action->setEnabled ((history_length > 0) && (position > 1));
+	plot_prev_action->setEnabled ((history_length > 0) && (position > 1));
 	plot_next_action->setEnabled ((history_length > 0) && (position < history_length));
 	plot_last_action->setEnabled ((history_length > 0) && (position < history_length));
 	QStringList _labels = labels;


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