[Sciviews-commits] r258 - in komodo/SciViews-K: . content content/js locale/en-GB locale/fr-FR

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 30 01:37:31 CEST 2010


Author: prezez
Date: 2010-04-30 01:37:30 +0200 (Fri, 30 Apr 2010)
New Revision: 258

Modified:
   komodo/SciViews-K/content/RObjectsOverlay.xul
   komodo/SciViews-K/content/RPkgManager.xul
   komodo/SciViews-K/content/js/commands.js
   komodo/SciViews-K/content/js/r.js
   komodo/SciViews-K/content/js/robjects.js
   komodo/SciViews-K/content/overlayMain.xul
   komodo/SciViews-K/install.rdf
   komodo/SciViews-K/locale/en-GB/sciviewsk.dtd
   komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd
Log:
Many small changes. Continuous R checking disabled. startR now redirects to Preferences window if R interpreter is not set. Not functional buttons on package-manager disabled. Option to save data.frame to file added in object browser.

Modified: komodo/SciViews-K/content/RObjectsOverlay.xul
===================================================================
--- komodo/SciViews-K/content/RObjectsOverlay.xul	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/RObjectsOverlay.xul	2010-04-29 23:37:30 UTC (rev 258)
@@ -84,6 +84,11 @@
 			<menuitem id="menu_robjects_cmd_str" command="robjects_cmd_str"/>
 			<!--<menuitem id="menu_robjects_cmd_args" command="robjects_cmd_args"/>-->
 			<menuitem id="menu_robjects_cmd_names" command="robjects_cmd_names"/>
+
+			<menuitem id="menu_robjects_cmd_write_table"
+					  class="menuitem-iconic save-buffer-icon"
+					  command="robjects_cmd_write_table"/>
+
 			<menuseparator keep="false" intoplevel="true"/>
 			<menuitem id="menu_robjects_cmd_help" command="robjects_cmd_help"/>
 		</menupopup>
@@ -118,6 +123,11 @@
 				oncommand="sv.r.objects.do('str');" accesskey="T"/>
 			<command id="robjects_cmd_names" label="&sciviews.robjects.names;"
 				oncommand="sv.r.objects.do('names');" accesskey="N"/>
+
+			<command id="robjects_cmd_write_table" label="&sciviews.robjects.write_table;"
+				oncommand="sv.r.objects.do('write.table');" accesskey="T"/>
+
+
 			<command id="robjects_cmd_help" label="&sciviews.robjects.help;"
 				oncommand="sv.r.objects.do('help');" accesskey="H"/>
 

Modified: komodo/SciViews-K/content/RPkgManager.xul
===================================================================
--- komodo/SciViews-K/content/RPkgManager.xul	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/RPkgManager.xul	2010-04-29 23:37:30 UTC (rev 258)
@@ -31,10 +31,10 @@
  the terms of any one of the MPL, the GPL or the LGPL.
 
  ***** END LICENSE BLOCK ***** -->
- 
+
 <!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN"
 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- 
+
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/bindings/buttons.css" type="text/css"?>
@@ -125,10 +125,10 @@
 		var eol = "\n\n\n";
 
 		var cmd = [
-				'ipkg <- as.data.frame(installed.packages(fields = c("Description"))[, c("Package", "Version", "Description", "Depends")])',
-				'ipkg$Loaded <- ipkg$Package %in% .packages()',
-				'ipkg$Required <- ipkg$Package %in% .required',
-				'write.table(ipkg [, c("Package", "Version", "Description", "Loaded", "Required", "Depends")], eol="'
+				'svtmp.ipkg <- as.data.frame(installed.packages(fields = c("Description"))[, c("Package", "Version", "Description", "Depends")])',
+				'svtmp.ipkg$Loaded <- svtmp.ipkg$Package %in% .packages()',
+				'svtmp.ipkg$Required <- svtmp.ipkg$Package %in% .required',
+				'write.table(svtmp.ipkg [, c("Package", "Version", "Description", "Loaded", "Required", "Depends")], eol="'
 				+ addcslashes(eol, "\n") + '", na = "", sep="\\t", quote=FALSE, row.names = FALSE, col.names = FALSE)',
 		];
 
@@ -287,7 +287,7 @@
 
 function pkgFindUpdates () {
 		var sep = ";;";
-		var cmd = 'write.table(updatePkgs()[,-2], sep="' + sep + '", quote=FALSE, na="", eol="\n", row.names = FALSE, col.names = FALSE)';
+		var cmd = 'write.table(svtmp.updatePkgs()[,-2], sep="' + sep + '", quote=FALSE, na="", eol="\n", row.names = FALSE, col.names = FALSE)';
 
 		var theList = document.getElementById("TheList");
 		var theUpdatesList = document.getElementById("TheUpdatesList");
@@ -335,7 +335,7 @@
 		//f1();
 		var args = window.arguments;
 		sv = args[0];
-		var cmd = 'updatePkgs <- function (lib.loc = .libPaths(), repos = getOption("repos"),'
+		var cmd = 'svtmp.updatePkgs <- function (lib.loc = .libPaths(), repos = getOption("repos"),'
 				+	'	  contriburl = contrib.url(repos, type), method,'
 				+	'	  available = available.packages(contriburl = contriburl, method = method),'
 				+	'	  instlib = update[, "LibPath"], ...,'
@@ -351,6 +351,13 @@
 		//reloadList();
 }
 
+
+
+self.onclose = function() {
+    sv.r.evalHidden('rm(svtmp.updatePkgs, svtmp.ipkg)');
+}
+
+
 ]]>
 	</script>
 
@@ -362,7 +369,7 @@
 	</script>
 
 	<hbox>
-		<radiogroup id="pkgPanelButtons" orient="horizontal">
+		<radiogroup id="pkgPanelButtons" orient="horizontal" disabled="true">
 			<radio label="Available"
 				oncommand="document.getElementById('pkgPanels').selectedIndex = 0;"/>
 			<radio label="Installed" selected="true"
@@ -374,6 +381,12 @@
 		<button label="Close" onclick="self.close();"/>
 	</hbox>
 
+	<vbox style="font-weight:bold; background-color: #feac01; border: 1px black solid; margin: 2px; padding: 3px;">
+<description>
+    This package manager is an experimental feature of SciViews-K. It is not fully functional yet.
+</description>
+</vbox>
+
 	<deck id="pkgPanels" flex="1" style="padding: 0px; border: none;"
 		selectedIndex="1" persists="selectedIndex">
 
@@ -387,7 +400,8 @@
 				</hbox>
 				<hbox align="left" flex="1" maxheight="20">
 					<button label="Find updates" accesskey="F"
-						oncommand="pkgFindUpdates();" align="left"/>
+						oncommand="pkgFindUpdates();" align="left"
+						 disabled="true" />
 					<spacer flex="1"/>
 				</hbox>
 			</vbox>
@@ -402,7 +416,7 @@
 				</hbox>
 				<hbox align="left" flex="1" maxheight="20">
 					<button label="Install updates" accesskey="I" oncommand=""
-						align="left"/>
+						align="left" disabled="disabled"/>
 					<spacer flex="1"/>
 				</hbox>
 			</vbox>

Modified: komodo/SciViews-K/content/js/commands.js
===================================================================
--- komodo/SciViews-K/content/js/commands.js	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/js/commands.js	2010-04-29 23:37:30 UTC (rev 258)
@@ -61,18 +61,21 @@
 	}
 
 	// private methods
+	// continuous checking is now disabled - R often hanged 
 	function _keepCheckingR (stopMe) {
-		clearInterval(sv.r.testInterval);
+		/*
+		//clearInterval(sv.r.testInterval);
 		if (!stopMe) {
 			// checking every second may cause problems when R is busy, changed to 5000
-			sv.r.testInterval = window.setInterval(sv.r.test, 5000);
+			//sv.r.testInterval = window.setInterval(sv.r.test, 5000);
 		}
-		setTimeout(window.updateCommands, 1000, 'r_app_started_closed');
+		//sv.r.running = true;
+		//setTimeout(window.updateCommands, 1000, 'r_app_started_closed');
 		//xtk.domutils.fireEvent(window, 'r_app_started_closed');
+		*/
 	}
 
 	function _isRRunning () {
-		//sv.log.debug("is R Running? " + sv.r.running);
 		return sv.r.running;
 	}
 
@@ -101,7 +104,22 @@
 	var cwd = sv.tools.file.path("ProfD", "extensions",
 	"sciviewsk at sciviews.org", "defaults");
 	var cmd = sv.prefs.getString("svRApplication");
-	var path = os.path.dirname(sv.prefs.getString("svRDefaultInterpreter"));
+
+	// trim just in case
+	var path = sv.tools.strings.trim(sv.prefs.getString("svRDefaultInterpreter"));
+
+	if (!path) {
+	    if(ko.dialogs.okCancel(
+		sv.translate("Default R interpreter is not set in " +
+			     "Preferences. Do you want to do it now?"),
+			"OK", null, "SciViews-K") == "OK") {
+		prefs_doGlobalPrefs("svPrefRItem", true);
+	    }
+	    return;
+	}
+
+
+	path = os.path.dirname(path);
 	if (path) path += os.sep;
 	cmd = cmd.replace("%Path%", path).replace("%cwd%", cwd)
 		.replace("%title%", "SciViews-K");
@@ -111,7 +129,7 @@
 	// runIn = "command-output-window", "new-console",
 	// env strings: "ENV1=fooJ\nENV2=bar"
 	// gPrefSvc.prefs.getStringPref("runEnv");
-	
+
 	// Reasonable default values are set in prefs.js... but just in case, we
 	// make sure to redefine reasonable default values here
 	var isWin = navigator.platform.indexOf("Win") === 0;
@@ -189,7 +207,6 @@
 			this.command = command;
 			observerSvc.addObserver(this, 'status_message', false);
 			sv.log.debug("R has been started with command: " + command);
-			sv.r.running = true;
 			// Sending commands to R does not seem to work, I think it is too early, R is still
 			// starting. This should be in .Rprofile
 			//sv.socket.updateCharset(true);
@@ -197,8 +214,8 @@
 			// R task callbacks and make sure R Objects pane is updated
 			//sv.r.evalHidden("try(guiRefresh(force = TRUE), silent = TRUE)");
 
-			//xtk.domutils.fireEvent(window, 'r_app_started_closed');
-			window.updateCommands('r_app_started_closed');
+			// this hopefully will be called from R, when it starts:
+			//_this.updateRStatus(true);
 		},
 		unregister: function () {
 			var observerSvc = Components.
@@ -208,11 +225,19 @@
 
 			sv.log.debug("R has been closed. Command was: " + this.command);
 
-			sv.r.running = false;
+			_this.updateRStatus(false);
+		}
+	};
+
+	this.updateRStatus = function (running) {
+		running = !!running;
+		if (running != sv.r.running) {
+			sv.r.running = !!running;
 			//xtk.domutils.fireEvent(window, 'r_app_started_closed');
 			window.updateCommands('r_app_started_closed');
+			sv.log.debug("R status updated: " + (running? "" : "not ") + "running" );
 		}
-	};
+	}
 
 	// Selects the checkbox on selected element, while deselecting others
 	this.getRApp = function (event) {
@@ -457,7 +482,7 @@
 
 		//TODO: check if R is working before any command is sent,
 		//rather than continously
-		_keepCheckingR();
+		//_keepCheckingR();
 
 		// This is no longer needed:
 		// To run it with the same key as autocompletion with other languages

Modified: komodo/SciViews-K/content/js/r.js
===================================================================
--- komodo/SciViews-K/content/js/r.js	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/js/r.js	2010-04-29 23:37:30 UTC (rev 258)
@@ -209,6 +209,7 @@
 	return(res);
 }
 
+
 // Evaluate code in R in a hidden way
 sv.r.evalHidden = function (cmd, earlyExit) {
 	// If R is not running, do nothing
@@ -1210,6 +1211,8 @@
 	return(dir);
 }
 
+
+//TODO: Allow also for dirs outside Home directory (useful on windows)
 // Set a R session dir and corresponding dir preferences both in R and Komodo
 sv.r.setSession = function (dir, datadir, scriptdir, reportdir,
 	saveOld, loadNew) {
@@ -1358,6 +1361,7 @@
 		}
 	return true;
 	}
+	return false;
 }
 
 // Show the session directory in the file explorer, finder, nautilus, ...
@@ -1867,6 +1871,48 @@
 // Initialize the default (last used) R session
 sv.r.initSession();
 
+
+/////////////////////////////
+
+sv.r.saveDataFrame = function _saveDataFrame(name, fileName, objName, dec, sep) {
+	if (!dec) dec = sv.prefs.getString("r.csv.dec");
+	if (!sep) sep = sv.prefs.getString("r.csv.sep");
+
+	if (!fileName) {
+		var filterIndex;
+		switch(sep) {
+			case '\\t':	filterIndex = 1; break;
+			case ';':
+			case ',': 	filterIndex = 0; break;
+			case ' ': 	filterIndex = 2; break;
+			default: 	filterIndex = 3;
+		}
+
+		var dir = sv.prefs.getString("sciviews.session.dir");
+
+		fileName = sv.tools.fileOpen(dir, objName, "",
+					["Comma separated values (*.csv)|*.csv",
+					 "Tab delimited (*.txt)|*.txt",
+					 "Whitespace delimited values (*.txt)|*.txt"
+					 ], false, true, filterIndex);
+
+
+		// TODO: set delimiter basing on filterIndex...
+	}
+
+	var cmd = 'write.table(' + name + ', file="' + fileName.addslashes() + '", dec="' + dec
+		+ '", sep="' + sep + '")';
+	sv.r.eval(cmd);
+	return cmd;
+}
+
+
+
+
+
+
+
+
 // Temp code
 //sv.r.RinterpreterTrial = function (code) {
 //	var R = Components

Modified: komodo/SciViews-K/content/js/robjects.js
===================================================================
--- komodo/SciViews-K/content/js/robjects.js	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/js/robjects.js	2010-04-29 23:37:30 UTC (rev 258)
@@ -1224,26 +1224,23 @@
 		var currentIndex = _this.selection.currentIndex;
 
 		if (currentIndex != -1) {
-			var isPackage, noDetach, isFunction, inPackage = false;
+			var isPackage, noDetach, isFunction;
 			var item, type, name;
-			item = this.visibleData[currentIndex].origItem;
+			item = _this.visibleData[currentIndex].origItem;
 			type = item.class;
 			name = item.fullName;
 
-			isPackage = type == "package";
 			noDetach = isPackage && (name == ".GlobalEnv" || name == "TempEnv");
 			isFunction = type == "function";
 
-			/*
-			if (!isPackage) {
-				inPackage = item.env && (item.env.indexOf("package:") == 0);
-			}
-			*/
+			var canSaveToFile = ["data.frame", "matrix", "table"].indexOf(item.class) > -1;
 
-			var hasHelp = (isPackage && item.name.indexOf("package:") == 0) ||
-				(!isPackage && item.env.indexOf("package:") == 0);
+			var selItemCount = _this.selection.count;
 
-			//sv.cmdout.append("hasHelp: " + hasHelp + " ");
+			// help can be shown only for one object:
+			var hasHelp = (selItemCount == 1)
+				&& ((isPackage && item.name.indexOf("package:") == 0) ||
+					(!isPackage && item.env.indexOf("package:") == 0));
 
 			document.getElementById("robjects_cmd_removeobj")
 				.setAttribute("disabled", noDetach);
@@ -1260,25 +1257,21 @@
 			document.getElementById("robjects_cmd_str")
 				.setAttribute("disabled", isPackage);
 
+			//document.getElementById("robjects_cmd_write_table")
+			//	.setAttribute("disabled", !isDataFrame);
+
 			// disable help option for non-package objects, because usually there is none
 			document.getElementById("robjects_cmd_help")
 				.setAttribute("disabled", !hasHelp);
 		}
 	}
 
-
 	this.do = function (action) {
 		var obj = [];
 		var rows = _this.getSelectedRows();
-		var item, pkg, type, name;
 
-		for (i in rows) {
-			item = this.visibleData[rows[i]].origItem;
-			type = item.class;
-			name = item.fullName;
-			pkg = item.env;
-			obj.push({ name: name, type: type, pkg: pkg });
-		}
+		for (i in rows)
+			obj.push(_this.visibleData[rows[i]].origItem);
 
 		var command;
 
@@ -1287,15 +1280,30 @@
 		case 'help':
 			for (i in obj) {
 				// Help only for packages and objects inside a package
-				if (obj[i].pkg.indexOf("package:") == 0) {
-					sv.r.help(obj[i].name, obj[i].pkg.replace(/^package:/, ''));
-				} else if (obj[i].name.indexOf("package:") == 0) {
-					sv.r.help("", obj[i].name.replace(/^package:/, ''));
+				if (obj[i].env.indexOf("package:") == 0) {
+					sv.r.help(obj[i].fullName, obj[i].env.replace(/^package:/, ''));
+				} else if (obj[i].fullName.indexOf("package:") == 0) {
+					sv.r.help("", obj[i].fullName.replace(/^package:/, ''));
 				} else {
-					sv.r.help(obj[i].name);
+					sv.r.help(obj[i].fullName);
 				}
 			}
 		break;
+
+		//TODO: dump data for objects other than 'data.frame'
+		case 'write.table':
+		case 'writeToFile':
+			var cmd = [], expr;
+
+			for (i in obj) {
+				expr = "eval(expression(" + obj[i].fullName +
+					"), envir = as.environment(\"" +
+					obj[i].env.addslashes() + "\"))";
+
+				sv.r.saveDataFrame(expr, '', obj[i].name);
+			}
+		break;
+
 		// Default is to just execute command and display results
 		case 'summary':
 		case 'plot':
@@ -1304,9 +1312,9 @@
 		default:
 			var cmd = [];
 			for (i in obj) {
-				cmd.push(action + "(eval(" + obj[i].name +
-					", envir = as.environment(\"" +
-					obj[i].pkg.addslashes() + "\")))");
+				cmd.push(action + "(eval(expression(" + obj[i].fullName +
+					"), envir = as.environment(\"" +
+					obj[i].env.addslashes() + "\")))");
 			}
 			sv.r.eval(cmd.join("\n"));
 		}

Modified: komodo/SciViews-K/content/overlayMain.xul
===================================================================
--- komodo/SciViews-K/content/overlayMain.xul	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/content/overlayMain.xul	2010-04-29 23:37:30 UTC (rev 258)
@@ -72,9 +72,6 @@
 	</broadcasterset>
 
 	<commandset id="allcommands">
-		<command id="Tasks:svAbout"
-			oncommand="alert('SciViews-K (Komodo R Editor) version ' + sv.version + '\na Komodo extension to interact with R\n(see http://www.sciviews.org/SciViews-K)');"/>
-
 		<commandset id="cmdset_rApp" commandupdater="true"
 			oncommandupdate="ko.commands.updateCommandset(this);"
 			events="r_app_started_closed">
@@ -99,7 +96,7 @@
 		</commandset>
 
 		<commandset id="cmdset_r_control" commandupdater="true"
-		  events="current_view_language_changed"
+		  events="current_view_language_changed,r_app_started_closed"
 		  oncommandupdate="ko.commands.updateCommandset(this);">
 			<command id="cmd_sv_RRunAll" key="key_cmd_sv_RRunAll"
 				oncommand="ko.commands.doCommand('cmd_sv_RRunAll')"

Modified: komodo/SciViews-K/install.rdf
===================================================================
--- komodo/SciViews-K/install.rdf	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/install.rdf	2010-04-29 23:37:30 UTC (rev 258)
@@ -4,9 +4,11 @@
     <Description about="urn:mozilla:install-manifest">
         <em:id>sciviewsk at sciviews.org</em:id>
         <em:name>SciViews-K</em:name>
-        <em:version>0.9.12</em:version>
+        <em:version>0.9.14</em:version>
         <em:description>Edit R (http://www.r-project.org) code with Komodo</em:description>
         <em:creator>Philippe Grosjean</em:creator>
+        <em:contributor>Romain Francois</em:contributor>
+        <em:contributor>Kamil Barton</em:contributor>
         <em:homepageURL>http://sciviews.org/SciViews-K</em:homepageURL>
         <em:iconURL>chrome://sciviewsk/skin/images/appicon.png</em:iconURL>
         <em:type>2</em:type> <!-- type=extension -->

Modified: komodo/SciViews-K/locale/en-GB/sciviewsk.dtd
===================================================================
--- komodo/SciViews-K/locale/en-GB/sciviewsk.dtd	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/locale/en-GB/sciviewsk.dtd	2010-04-29 23:37:30 UTC (rev 258)
@@ -46,6 +46,7 @@
 <!ENTITY sciviews.robjects.plot "Plot">
 <!ENTITY sciviews.robjects.print "Print">
 <!ENTITY sciviews.robjects.summary "Summary">
+<!ENTITY sciviews.robjects.write_table "Write to textfile">
 
 <!ENTITY sciviews.robjects.deleteNow "Delete immediately">
 <!ENTITY sciviews.robjects.deleteNow.acc "D">

Modified: komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd
===================================================================
--- komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd	2010-04-29 22:59:57 UTC (rev 257)
+++ komodo/SciViews-K/locale/fr-FR/sciviewsk.dtd	2010-04-29 23:37:30 UTC (rev 258)
@@ -46,7 +46,7 @@
 <!ENTITY sciviews.robjects.plot "Graphique">
 <!ENTITY sciviews.robjects.print "Contenu">
 <!ENTITY sciviews.robjects.summary "Résumé">
-
+<!ENTITY sciviews.robjects.write_table "Write to textfile">
 <!ENTITY sciviews.robjects.deleteNow "Effacer tout de suite">
 <!ENTITY sciviews.robjects.deleteNow.acc "E">
 <!ENTITY sciviews.robjects.insertQuoted "Insérer avec guillemets">



More information about the Sciviews-commits mailing list