Learn R Programming

gWidgets (version 0.0-25)

gedit: Constructors for widgets to handle text input

Description

The gedit widget is used to enter single lines of text. The gtext widget creates a text buffer for handling multiple lines of text.

Usage

gedit(text = "", width = 25, coerce.with = NULL, handler = NULL, action = NULL, container = NULL, ..., toolkit = guiToolkit())

gtext (text = NULL, width = NULL, height = 300, font.attr = NULL, wrap = TRUE, handler = NULL, action = NULL, container = NULL, ..., toolkit = guiToolkit())

Arguments

Details

The gedit widget has the following methods:

The svalue method retrieves the value. If a function is given to the argument coerce.with it is applied before the value is returned. This can be used to coerce the text value (always of class character) to a numeric, or to a date, or to be quoted, ...

The svalue<- method is used to set the value.

The "[" and "[<-" methods refer to the widgets "type-ahead" values. A familiar usage is when a url is typed into a web browser, matches appear from a users history that could possibly complete the typed url.

The gtext widget has the following methods.

The svalue method returns the text held in the buffer. If drop=TRUE, then only the text in the buffer selected by the mouse is returned.

The svalue<- method replaces the text in the buffer with the new text.

New text is added with the add method. The basic usage is add(obj,text) where "text" could be a single line or a vector of text, or a gwidget (although some, like gedit, are kind of flaky). Extra arguments include do.newline a logical indicating if a new line after the last line should be added (default is TRUE); font.attr to specify any font attributes; where indicating where to add the text (either end or beginning).

The font can be changed. The font.attr argument to the constructon and to add specifies fonts using a namedcharacter vector. For instance c(style="normal", weights="bold",sizes="medium"). The command obj[['tags']] will produce a list containing all the available attributes.

The font<- method is used to change the font of the currently selected text. It too takes a named character vector specifying the font attributes.

The dispose method clears the text in the buffer.

Examples

Run this code
gedit("type here", container=TRUE)
	
	## change handler
	obj = gedit(container=TRUE)
	addhandlerchanged(obj, handler=function(h,...) 
	  cat("You typed", svalue(h$obj),"\n"))

	 ## coerce to numeric
	 obj = gedit("7", container=TRUE, coerce.with=as.numeric)
	 svalue(obj)

        ## gtext example
        obj = gtext("First line", container=TRUE)
        add(obj,"second line", font.attr=c(family="monospace"))
        add(obj,"third line", font.attr=c(foreground.colors="red"))

Run the code above in your browser using DataLab