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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sat Sep 4 13:14:54 UTC 2010


Revision: 2996
          http://rkward.svn.sourceforge.net/rkward/?rev=2996&view=rev
Author:   tfry
Date:     2010-09-04 13:14:53 +0000 (Sat, 04 Sep 2010)

Log Message:
-----------
Allow asynchronous information dialogs

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2010-09-03 23:04:51 UTC (rev 2995)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2010-09-04 13:14:53 UTC (rev 2996)
@@ -126,6 +126,7 @@
 QString *SEXPToStringList (SEXP from_exp, unsigned int *count);
 QString SEXPToString (SEXP from_exp);
 int *SEXPToIntArray (SEXP from_exp, unsigned int *count);
+int SEXPToInt (SEXP from_exp);
 
 // ############## R Standard callback overrides BEGIN ####################
 void RSuicide (const char* message) {
@@ -353,7 +354,7 @@
 
 /* FROM R_ext/RStartup.h: "Return value here is expected to be 1 for Yes, -1 for No and 0 for Cancel:
    symbolic constants in graphapp.h" */
-int doDialogHelper (QString caption, QString message, QString button_yes, QString button_no, QString button_cancel) {
+int doDialogHelper (QString caption, QString message, QString button_yes, QString button_no, QString button_cancel, bool wait) {
 	RK_TRACE (RBACKEND);
 
 	RCallbackArgs args;
@@ -363,7 +364,8 @@
 	args.params["button_yes"] = QVariant (button_yes);
 	args.params["button_no"] = QVariant (button_no);
 	args.params["button_cancel"] = QVariant (button_cancel);
-	
+	if (wait) args.params["wait"] = "1";
+
 	REmbedInternal::this_pointer->handleStandardCallback (&args);
 
 	QString ret = args.params["result"].toString ();
@@ -372,10 +374,10 @@
 	return 0;
 }
 
-SEXP doDialog (SEXP caption, SEXP message, SEXP button_yes, SEXP button_no, SEXP button_cancel) {
+SEXP doDialog (SEXP caption, SEXP message, SEXP button_yes, SEXP button_no, SEXP button_cancel, SEXP wait) {
 	RK_TRACE (RBACKEND);
 
-	int result = doDialogHelper (SEXPToString (caption), SEXPToString (message), SEXPToString (button_yes), SEXPToString (button_no), SEXPToString (button_cancel));
+	int result = doDialogHelper (SEXPToString (caption), SEXPToString (message), SEXPToString (button_yes), SEXPToString (button_no), SEXPToString (button_cancel), SEXPToInt (wait));
 
 	SEXP ret = Rf_allocVector(INTSXP, 1);
 	INTEGER (ret)[0] = result;
@@ -385,14 +387,14 @@
 void RShowMessage (const char* message) {
 	RK_TRACE (RBACKEND);
 
-	doDialogHelper (i18n ("Message from the R backend"), message, "ok", QString (), QString ());
+	doDialogHelper (i18n ("Message from the R backend"), message, "ok", QString (), QString (), true);
 }
 
 // TODO: currently used on windows, only!
 int RAskYesNoCancel (const char* message) {
 	RK_TRACE (RBACKEND);
 
-	return doDialogHelper (i18n ("Question from the R backend"), message, "yes", "no", "cancel");
+	return doDialogHelper (i18n ("Question from the R backend"), message, "yes", "no", "cancel", true);
 }
 
 void RBusy (int busy) {
@@ -617,6 +619,19 @@
 	return integers;
 }
 
+// converts SEXP to integers, and returns the first int (INT_MIN, if SEXP contains no ints)
+int SEXPToInt (SEXP from_exp) {
+	RK_TRACE (RBACKEND);
+
+	int ret = INT_MIN;
+	unsigned int count;
+	int *integers = SEXPToIntArray (from_exp, &count);
+	if (count >= 1) ret = integers[0];
+	delete [] integers;
+
+	return ret;
+}
+
 double *SEXPToRealArray (SEXP from_exp, unsigned int *count) {
 	RK_TRACE (RBACKEND);
 
@@ -857,7 +872,7 @@
 		{ "rk.copy.no.eval", (DL_FUNC) &doCopyNoEval, 3 },
 		{ "rk.edit.files", (DL_FUNC) &doEditFiles, 3 },
 		{ "rk.show.files", (DL_FUNC) &doShowFiles, 4 },
-		{ "rk.dialog", (DL_FUNC) &doDialog, 5 },
+		{ "rk.dialog", (DL_FUNC) &doDialog, 6 },
 		{ "rk.update.locale", (DL_FUNC) &doUpdateLocale, 0 },
 		{ "rk.locale.name", (DL_FUNC) &doLocaleName, 0 },
 		{ 0, 0, 0 }

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2010-09-03 23:04:51 UTC (rev 2995)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2010-09-04 13:14:53 UTC (rev 2996)
@@ -495,14 +495,26 @@
 		KGuiItem button_cancel_item = KStandardGuiItem::cancel ();
 		if (button_cancel != "cancel") button_cancel_item.setText (button_cancel);
 
+		bool shown = false;
 		KMessageBox::DialogType dialog_type = KMessageBox::QuestionYesNoCancel;
 		if (button_cancel.isEmpty ()) dialog_type = KMessageBox::QuestionYesNo;
 		if (button_no.isEmpty () && button_cancel.isEmpty ()) {
-			if (button_yes == "ok") button_yes_item = KStandardGuiItem::ok ();
 			dialog_type = KMessageBox::Information;
+			if (args->params["wait"].toString () != "1") {	// non-modal dialogs are not supported out of the box by KMessageBox;
+				KDialog* dialog = new KDialog ();
+				KMessageBox::createKMessageBox (dialog, QMessageBox::Information, message, QStringList (), QString (), 0, KMessageBox::Notify | KMessageBox::NoExec);
+				dialog->setWindowTitle (caption);
+				dialog->setAttribute (Qt::WA_DeleteOnClose);
+				dialog->setButtons (KDialog::Ok);
+				dialog->show();
+				shown = true;
+			}
 		}
 
-		int result = KMessageBox::messageBox (0, dialog_type, message, caption, button_yes_item, button_no_item, button_cancel_item);
+		int result = KMessageBox::Ok;
+		if (!shown) {
+			result = KMessageBox::messageBox (0, dialog_type, message, caption, button_yes_item, button_no_item, button_cancel_item);
+		}
 
 		QString result_string;
 		if ((result == KMessageBox::Yes) || (result == KMessageBox::Ok)) result_string = "yes";

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-09-03 23:04:51 UTC (rev 2995)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2010-09-04 13:14:53 UTC (rev 2996)
@@ -417,14 +417,14 @@
 	.rk.do.call ("select.list", params)
 }
 
-"rk.show.message" <- function (message, caption = "Information") {
-	.Call ("rk.dialog", caption, message, "ok", "", "")
+"rk.show.message" <- function (message, caption = "Information", wait=TRUE) {
+	.Call ("rk.dialog", caption, message, "ok", "", "", isTRUE (wait))
 	invisible (TRUE)
 }
 
 # to disable a button, set it to ""
 "rk.show.question" <- function (message, caption = "Question", button.yes = "yes", button.no = "no", button.cancel = "cancel") {
-	res <- .Call ("rk.dialog", caption, message, button.yes, button.no, button.cancel)
+	res <- .Call ("rk.dialog", caption, message, button.yes, button.no, button.cancel, TRUE)
 	if (res > 0) return (TRUE)
 	else if (res < 0) return (FALSE)
 	else return (NULL)	# cancelled


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