1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
-- Example of concurrent Haskell and Gtk.
--
-- This demo uses GHC's support for OS level threads. It has to be
-- linked using the ghc -threaded flag.
--
-- Because Gtk+ is single threaded we have to be very careful to call
-- Gtk+ only from the main GUI thread. So while it's ok to forkIO,
-- any GUI actions in that thread have to be 'posted' to the main GUI
-- thread using postGUI, or postGUIAsync as in the example here.
import Graphics.UI.Gtk
import Control.Applicative
import Prelude
import Control.Concurrent
main :: IO ()
main = do
-- It is marked unsafe because it is your obligation to ensure you
-- only call Gtk+ from one OS thread, or 'bad things' will happen.
unsafeInitGUIForThreadedRTS
dia <- dialogNew
dialogAddButton dia stockClose ResponseClose
contain <- castToBox <$> dialogGetContentArea dia
pb <- progressBarNew
boxPackStart contain pb PackNatural 0
widgetShowAll dia
forkIO (doTask pb)
dialogRun dia
return ()
doTask :: ProgressBar -> IO ()
doTask pb = do
postGUIAsync $ progressBarPulse pb
threadDelay 100000
doTask pb
|