gtk-0.11.0: Binding to the Gtk+ graphical user interface library.ContentsIndex
Graphics.UI.Gtk.General.General
Portabilityportable (depends on GHC)
Stabilityprovisional
Maintainergtk2hs-users@lists.sourceforge.net
Contents
Initialisation
Support for OS threads
Main event loop
Less commonly used event loop functions
Grab widgets
Timeout and idle callbacks
Description
library initialization, main event loop, and events
Synopsis
initGUI :: IO [String]
unsafeInitGUIForThreadedRTS
postGUISync :: IO a -> IO a
postGUIAsync :: IO () -> IO ()
threadsEnter :: IO ()
threadsLeave :: IO ()
mainGUI :: IO ()
mainQuit :: IO ()
eventsPending :: IO Int
mainLevel :: IO Int
mainIteration :: IO Bool
mainIterationDo :: Bool -> IO Bool
grabAdd :: WidgetClass wd => wd -> IO ()
grabGetCurrent :: IO (Maybe Widget)
grabRemove :: WidgetClass w => w -> IO ()
Priority
priorityLow
priorityDefaultIdle
priorityHighIdle
priorityDefault
priorityHigh
timeoutAdd
timeoutAddFull
timeoutRemove
idleAdd
idleRemove
inputAdd
inputRemove
IOCondition (IOIn, IOOut, IOPri, IOErr, IOHup, IOInvalid)
HandlerId
Initialisation
initGUI :: IO [String]

Initialize the GUI.

This must be called before any other function in the Gtk2Hs library.

This function initializes the GUI toolkit and parses all Gtk specific arguments. The remaining arguments are returned. If the initialization of the toolkit fails for whatever reason, an exception is thrown.

  • Throws: error "Cannot initialize GUI."
  • If you want to use Gtk2Hs and in a multi-threaded application then it is your obligation to ensure that all calls to Gtk+ happen on a single OS thread. If you want to make calls to Gtk2Hs functions from a Haskell thread other than the one that calls this functions and mainGUI then you will have to 'post' your GUI actions to the main GUI thread. You can do this using postGUISync or postGUIAsync. See also threadsEnter.
Support for OS threads
unsafeInitGUIForThreadedRTS
postGUISync :: IO a -> IO a

Post an action to be run in the main GUI thread.

The current thread blocks until the action completes and the result is returned.

postGUIAsync :: IO () -> IO ()

Post an action to be run in the main GUI thread.

The current thread continues and does not wait for the result of the action.

threadsEnter :: IO ()

Acquired the global Gtk lock.

  • During normal operation, this lock is held by the thread from which all interaction with Gtk is performed. When calling mainGUI, the thread will release this global lock before it waits for user interaction. During this time it is, in principle, possible to use a different OS thread (any other Haskell thread that is bound to the Gtk OS thread will be blocked anyway) to interact with Gtk by explicitly acquiring the lock, calling Gtk functions and releasing the lock. However, the Gtk functions that are called from this different thread may not trigger any calls to the OS since this will lead to a crash on Windows (the Win32 API can only be used from a single thread). Since it is very hard to tell which function only interacts on Gtk data structures and which function call actual OS functions, it is best not to use this feature at all. A better way to perform updates in the background is to spawn a Haskell thread and to perform the update to Gtk widgets using postGUIAsync or postGUISync. These will execute their arguments from the main loop, that is, from the OS thread of Gtk, thereby ensuring that any Gtk and OS function can be called.
threadsLeave :: IO ()

Release the global Gtk lock.

  • The use of this function is not recommended. See threadsEnter.
Main event loop
mainGUI :: IO ()
Run the Gtk+ main event loop.
mainQuit :: IO ()
Exit the main event loop.
Less commonly used event loop functions
eventsPending :: IO Int
Inquire the number of events pending on the event queue
mainLevel :: IO Int

Inquire the main loop level.

  • Callbacks that take more time to process can call mainIteration to keep the GUI responsive. Each time the main loop is restarted this way, the main loop counter is increased. This function returns this counter.
mainIteration :: IO Bool

Process an event, block if necessary.

  • Returns True if mainQuit was called while processing the event.
mainIterationDo :: Bool -> IO Bool

Process a single event.

  • Called with True, this function behaves as mainIteration in that it waits until an event is available for processing. It will return immediately, if passed False.
  • Returns True if the mainQuit was called while processing the event.
Grab widgets
grabAdd :: WidgetClass wd => wd -> IO ()
add a grab widget
grabGetCurrent :: IO (Maybe Widget)
inquire current grab widget
grabRemove :: WidgetClass w => w -> IO ()
remove a grab widget
Timeout and idle callbacks
Priority
priorityLow
priorityDefaultIdle
priorityHighIdle
priorityDefault
priorityHigh
timeoutAdd
timeoutAddFull
timeoutRemove
idleAdd
idleRemove
inputAdd
inputRemove
IOCondition (IOIn, IOOut, IOPri, IOErr, IOHup, IOInvalid)
HandlerId
Produced by Haddock version 2.4.2