Learn R Programming

gWidgets (version 0.0-43)

gWidgets-dialogs: Basic dialog constructors

Description

A dialog is a widget that draws its own window. These dialogs are used for simple things -- confirming a choice, gathering a single line of input, etc. Dialogs are always modal, meaning they must be closed before R can be interacted with again.

Usage

gmessage(message, title="message",
icon = c("info", "warning", "error", "question"),
        parent = NULL,
     handler = NULL, 
    action = NULL, ..., toolkit=guiToolkit()) 

ginput(message, text="", title="Input", icon = c("info", "warning", "error", "question"), parent=NULL, handler = NULL, action = NULL,..., toolkit=guiToolkit())

gconfirm(message, title="Confirm", icon = c("info", "warning", "error", "question"), parent=NULL, handler = NULL, action = NULL, ..., toolkit=guiToolkit())

gbasicdialog(title = "Dialog", widget, parent=NULL, handler = NULL, action=NULL, ..., toolkit=guiToolkit())

galert(message, title = "message", delay=3, parent=NULL, ..., toolkit=guiToolkit())

Arguments

message
Message shown for widget
title
Title of window
icon
Which icon to show
text
default value for ginput text
widget
Widget to place in basic dialog. If missing, dialog returns a container.
parent
A gwindow() instance. If specified, dialog will be located in relation to this
handler
Handler called on OK selection.
action
Value passed to handler
delay
For galert, how long the transient message will appear
...
Ignored
toolkit
Toolkit to use for GUI

Details

These basic dialogs do slightly different things.

The gmessage dialog shows a message with an icon and a dismiss button. This dialog returns TRUE or FALSE as appropriate.

The gconfirm dialog shows a message with an icon and an OK button and a dismiss button. A handler may be attached to the OK button selection. This dialog returns TRUE or FALSE as appropriate.

The ginput dialog adds an edit box for gathering user information. The text argument sets the default value. This is then passed to the handler via the component input of the first argument of the handler. This dialog returns the value of the string if OK is clicked, otherwise NA.

For toolkits which support constructors without parent containers, the gbasicdialog dialog wraps a widget around an OK and dismiss button. The handler is called when the OK button is clicked. This dialog returns the TRUE when OK is clicked, otherwise FALSE.

If the toolkit does not support parentless constructors, then the use is different. The widget argument is missing and the return value is a container. This is basically a top-level window with OK and cancel buttons. The container is shown when the visible method is called with a value of set=TRUE. This creates a modal dialog. The handler specified to the constructor is called when OK is clicked and TRUE is returned. The value of FALSE is returned on cancel, and NA otherwise.

These dialogs are modal. This means that the R session freezes until the dialog is dismissed. This may be confusing to users if the window should appear below a currently drawn window.

The galert dialog is non-modal and does not grab the focus. Like gmessage it shows a message but unlike it, only for a short period of time and is unobtrusive.

Examples

Run this code
gmessage("Hi there")
   gconfirm("Are we having fun?", handler = function(h,...)
   print("Yes"))

   ginput("Enter your name", icon="question", handler = function(h,...) cat("Hi",h$input,"\n"))

   ## gbasicdialog
   w <- gbasicdialog(title="Select a state", handler = function(h,...) 
      print(svalue(tbl)))
   tbl <- gtable(data.frame(states = rownames(state.x77)), expand=TRUE, cont = w)
   visible(w, set=TRUE) ## show dialog

Run the code above in your browser using DataLab