Learn R Programming

gWidgets (version 0.0-54.2)

gwindow: Constructor for base container

Description

Widgets are packed inside containers which may in turn be packed inside other containers. The base container is known as a window. Only one container may be packed inside a window.

Usage

gwindow(title = "Window", visible = TRUE, name=title,
  width = NULL, height= NULL, parent=NULL,
  handler = NULL, action = NULL,
  ..., toolkit = guiToolkit())

Arguments

title

Title of window

visible

If TRUE window is drawn when constructed. Otherwise, window can be drawn latter using visible<-. This value can default to FALSE by setting the option: options("gWidgets:gwindow-default-visible-is-false"=TRUE). There are advantages: windows can draw slowly when adding item by item; ggraphics like to be added to an undrawn widget as this avoids a sizing issue.

name

Name for registry of windows

width

Default width for window at creation

height

Default height for window at creation

parent

If non-NULL, can be used to suggest default location of window. The argument name was changed from location to parent. This can be a coordinate pair (x,y) with (0,0) the upper left corner, or a gwindow instance. In the latter case the location is suggested by the location of the current window. This is useful for placing dialogs near the parent window.

handler

Handler for destroy event.

action

Passed to handler

Not used

toolkit

Which GUI toolkit to use

Details

A base window can also be created using the argument container=TRUE when constructing a widget.

The svalue method returns the window title. Use svalue<- to change the title.

The add method is used to add a widget or container to the base window. For top-level windows, some toolkits only support adding one widget, so in gWidgets only one widget should be added to a window, so usually it would be another container.

Additionally the menubar, toolbar and statusbar widgets should now be added and deleted from the top-level window. Outside of RGtk2, the other toolkits expect these items to be properties of a top-level window.

The dispose method destroys the window.

The size method sets the minimum size. Use the width and height arguments to set the default size when the window is constructed.

A window is destroyed in response to a destroy event. However, when the window managager tries to close a window first a "delete-event" is issued. If this has the right value then the "destroy" event is fired. The addHandlerUnrealize handler can be called to intercept the closing of the window. Its handler should return a logical: TRUE to prevent the closing, FALSE to proceed. This may not work on all toolkits

Examples

Run this code
# NOT RUN {
  ## window with handler
  win <- gwindow("Window example",
    handler=function(h,...) {
     print("See ya")
  })
  gbutton("cancel", container=win,
    handler = function(h,...) dispose(win))

  ## block closing of window
  win <- gwindow("Window example")
  addHandlerUnrealize(win, handler = function(h,...) {
    val <- gconfirm("Really close window", parent=h$obj)
    if(as.logical(val))
      return(FALSE)		# destroy
    else
      return(TRUE)		# don't destroy
  })

  

  ## transient dialog (gWidgetsRGtk2)
  pwin <- gwindow("Parent window")
  cwin <- gwindow("Child window", parent = pwin)
  ## clicking button close parent causing child to close too
  gbutton("close both", container=cwin,
    handler = function(h,...) dispose(pwin))
# }

Run the code above in your browser using DataLab