Terminology (Re: [GUI] Re: Know you backends)
Axel Simon
A.Simon@ukc.ac.uk
Sat, 1 Feb 2003 20:56:07 +0000
--0OAP2g/MAC+5xKAE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Fri, Jan 31, 2003 at 10:49:33AM -0800, John Meacham wrote:
> I propose a simple program which pops up a window saying
>
> 'Hello World' with a button saying 'Bye' which you click and it changes
> the message to 'Goodbye'. if you click the button again the program
> exits.
Sorry for the delay. Here is the gtk2hs version. Compiled with
ghc --make Demo.hs -package mogul
Cheers,
Axel.
--0OAP2g/MAC+5xKAE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Demo.hs"
-- A simple program which pops up a window saying 'Hello World' with a
-- button saying 'Bye' which you click and it changes the message to
-- 'Goodbye'. if you click the button again the program exits.
-- This is the gtk2hs solution.
import Mogul
import Control.Concurrent.MVar
main :: IO ()
main = do
initGUI
-- create a top-level window
win <- newWindow
-- create a VBox to hold different sized widgets and but it into the window
vbox <- newVBox False 5
win `containerAdd` vbox
-- create the two UI elements
but <- newButtonWithLabel "Bye"
lab <- newLabel $ Just "Hello World"
-- add them to the VBox such that the button stays the same size and
-- that the label spreads out over the available area when resized
boxPackStart vbox lab PackRepel 0
boxPackEnd vbox but PackNatural 0
-- add a handler for the button clicked signal
stop <- newMVar False
but `onClicked` do
state <- readMVar stop
if state then mainQuit else do
lab `labelSetText` "Goodbye"
but `buttonSetLabel` "Exit"
swapMVar stop True
return ()
-- for completeness: quit the application when the window ceases
win `onDestroy` mainQuit
-- show and run the demo
widgetShowAll win
mainGUI
--0OAP2g/MAC+5xKAE--