gtk-General {RGtk2} | R Documentation

## Main loop and Events

### Description

Library initialization, main event loop, and events

### Methods and Functions

`gtkGetDefaultLanguage()`
`gtkInit(args = "R")`
`gtkExit(error.code)`
`gtkEventsPending()`
`gtkMain()`
`gtkMainLevel()`
`gtkMainQuit()`
`gtkMainIteration()`
`gtkMainIterationDo(blocking = TRUE)`
`gtkMainDoEvent(event)`
`gtkTrue()`
`gtkFalse()`
`gtkGrabAdd(object)`
`gtkGrabGetCurrent()`
`gtkGrabRemove(object)`
`gtkInitAdd(fun, data = NULL)`
`gtkQuitAddDestroy(main.level, object)`
`gtkQuitAdd(main.level, fun, data = NULL)`
`gtkQuitAddFull(main.level, fun, data = NULL)`
`gtkQuitRemove(quit.handler.id)`
`gtkQuitRemoveByData(data)`
`gtkTimeoutAddFull(interval, fun, data = NULL)`
`gtkTimeoutAdd(interval, fun, data = NULL)`
`gtkTimeoutRemove(timeout.handler.id)`
`gtkIdleAdd(fun, data = NULL)`
`gtkIdleAddPriority(priority, fun, data = NULL)`
`gtkIdleAddFull(priority, fun, data = NULL)`
`gtkIdleRemove(idle.handler.id)`
`gtkIdleRemoveByData(data)`
`gtkInputRemove(input.handler.id)`
`gtkKeySnooperInstall(snooper, func.data = NULL)`
`gtkKeySnooperRemove(snooper.handler.id)`
`gtkGetCurrentEvent()`
`gtkGetCurrentEventTime()`
`gtkGetCurrentEventState()`
`gtkGetEventWidget(event)`
`gtkPropagateEvent(object, event)`

### Detailed Description

Before using GTK+, you need to initialize it; initialization connects to the window system display, and parses some standard command line arguments. The `gtkInit` function initializes GTK+. `gtkInit` exits the application if errors occur; to avoid this, use `gtkInitCheck()`. `gtkInitCheck()` allows you to recover from a failed GTK+ initialization - you might start up your application in text mode instead.

Like all GUI toolkits, GTK+ uses an event-driven programming model. When the user is doing nothing, GTK+ sits in the main loop and waits for input. If the user performs some action - say, a mouse click - then the main loop "wakes up" and delivers an event to GTK+. GTK+ forwards the event to one or more widgets.

When widgets receive an event, they frequently emit one or more signals. Signals notify your program that "something interesting happened" by invoking functions you've connected to the signal with `gSignalConnect`. Functions connected to a signal are often termed callbacks.

When your callbacks are invoked, you would typically take some action - for example, when an Open button is clicked you might display a `GtkFileSelectionDialog`. After a callback finishes, GTK+ will return to the main loop and await more user input.

Typical `main` function for a GTK+ application

    int
    main (int argc, char **argv)
    {
      /* Initialize i18n support */
      gtk_set_locale (    );
      /* Initialize the widget set */
      gtk_init (&argc, &argv);
      /* Create the main window */
      mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      /* Set up our GUI elements */
      ...
      /* Show the application window */
      gtk_widget_show_all (mainwin);
      /* Enter the main event loop, and wait for user interaction */
      gtk_main (    );
      /* The user lost interest */
      return 0;
    }

It's OK to use the GLib main loop directly instead of `gtkMain`, though it involves slightly more typing. See `GMainLoop` in the GLib documentation.

### User Functions

`GtkModuleInitFunc(argc, argv)`

  Each GTK+ module must have a function `gtkModuleInit()` with this prototype. This function is called after loading the module with the `argc` and `argv` cleaned from any arguments that GTK+ handles itself.

  `argc`

    Pointer to the number of arguments remaining after `gtkInit`.

  `argv`

    Points to the argument vector.

`GtkModuleDisplayInitFunc()`

  Since 2.2

`GtkKeySnoopFunc(grab.widget, event, func.data)`

  Key snooper functions are called before normal event delivery. They can be used to implement custom key event handling.

  `grab.widget`

    the widget to which the event will be delivered.

  `event`

    the key event.

  `func.data`

    the `func.data` supplied to `gtkKeySnooperInstall`.

  Returns: [integer] `TRUE` to stop further processing of `event`, `FALSE` to continue.

### Author(s)

Derived by RGtkGen from GTK+ documentation

### References

https://developer-old.gnome.org/gtk2/stable/gtk2-General.html

[Package RGtk2 version 2.20.40 Index]