-- A little demo program that was proposed on gui@haskell.org to compare -- toolkit APIs. This is a version for the iHaskell 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 Gtk (binGetChild) import IH hiding (init, main) import qualified IH (init, main) main :: IO () main = do IH.init Nothing -- create a counter for clicks -- clicksPort <- newPort 0 -- create the label and button, where the button increments the click count -- label <- newLabel " Hello World " button <- newButtonWithLabel " Bye " (clicksPort <-$ (+1)) butlbl <- liftM fromWidget $ binGetChild button :: IO Label -- pack the label and button vertically and embed them into a window -- contents <- newBox Vertical True 10 [widget label, widget button] newWindow " Bye Demo " contents mainQuit False -- clicks are handled by `handleClick' depending on the number of clicks -- let handleClick 2 = mainQuit handleClick 1 = do setLabelText label " Goodbye " setLabelText butlbl " Exit " clicks <- listenToPort clicksPort forkIO $ mapM_ handleClick clicks -- enter the event loop -- IH.main