-- A little demo program that was proposed on gui@haskell.org to compare -- toolkit APIs. This is a version for the plain Gtk+HS API. -- -- There is a single button, which, when clicked once, changes the display -- and, when clicked a second time, terminates the application. -- import Monad import IOExts (IORef, newIORef, readIORef, writeIORef) import Gtk hiding (init, main) import qualified Gtk (init, main) main :: IO () main = do Gtk.init Nothing -- create a new window with a box to pack widgets vertically -- window <- windowNew WindowToplevel vbox <- vBoxNew False 10 window `containerAdd` vbox -- terminate if the window disappears -- window `signalConnect` WidgetDeleteEventHandler (\_ _ -> mainQuit >> return False) -- add the label and button to the box -- label <- labelNew " Hello World " button <- buttonNewWithLabel " Bye " butlbl <- liftM fromWidget $ binGetChild button :: IO Label boxPackStart vbox label True True 2 boxPackStart vbox button True True 2 -- create a stateful signal handler for the button -- clickedAlreadyRef <- newIORef False button `signalConnect` ButtonClickedHandler (\_ -> do clickedAlready <- readIORef clickedAlreadyRef if clickedAlready then mainQuit else do labelSetText label " Goodbye " labelSetText butlbl " Exit " writeIORef clickedAlreadyRef True) -- display the window and enter the event loop -- widgetShowAll window Gtk.main