Debian Codegraph @

demo/hello/World.hs

raw
1 -- A simple program to demonstrate Gtk2Hs.
2 module Main (Main.main) where
3
4 import Graphics.UI.Gtk
5
6 main :: IO ()
7 main = do
8 initGUI
9 -- Create a new window
10 window <- windowNew
11 -- Here we connect the "destroy" event to a signal handler.
12 -- This event occurs when we call widgetDestroy on the window
13 -- or if the user closes the window.
14 on window objectDestroy mainQuit
15 -- Sets the border width and tile of the window. Note that border width
16 -- attribute is in 'Container' from which 'Window' is derived.
17 set window [ containerBorderWidth := 10, windowTitle := "Hello World" ]
18 -- Creates a new button with the label "Hello World".
19 button <- buttonNew
20 set button [ buttonLabel := "Hello World" ]
21 -- When the button receives the "clicked" signal, it will call the
22 -- function given as the second argument.
23 on button buttonActivated (putStrLn "Hello World")
24 -- Gtk+ allows several callbacks for the same event.
25 -- This one will cause the window to be destroyed by calling
26 -- widgetDestroy. The callbacks are called in the sequence they were added.
27 on button buttonActivated $ do
28 putStrLn "A \"clicked\"-handler to say \"destroy\""
29 widgetDestroy window
30 -- Insert the hello-world button into the window.
31 set window [ containerChild := button ]
32 -- The final step is to display this newly created widget. Note that this
33 -- also allocates the right amount of space to the windows and the button.
34 widgetShowAll window
35 -- All Gtk+ applications must have a main loop. Control ends here
36 -- and waits for an event to occur (like a key press or mouse event).
37 -- This function returns if the program should finish.
38 mainGUI