[Haskell-beginners] gtk2hs and threadDelay

gabre at caesar.elte.hu gabre at caesar.elte.hu
Mon Dec 26 09:37:17 CET 2011


Hello!

I ve some questions in connection with GTK2HS and threadDelay. GTK2HS  
is a well known GUI tool for Haskell, I wanted to draw with it (in  
Cairo). The threadDelay is the function from Control.Concurrent. I  
wanted nothing else but make my unthreaded program wait for X  
microseconds. (one-threaded)

Consider the following parts from a code:

-- onClick event for a button
onClicked (btn gui) (drawProgram gui preprocPrg)

-- code for drawProgram
drawProgram gui preprocPrg = do
let drArea = (drawWin gui)
drw <- widgetGetDrawWindow drArea
renderWithDrawable drw (myDraw 200 200)
threadDelay 1800000
renderWithDrawable drw (myDraw2 200 200)

I expect this code to do the following: when somebody clicks the  
button "btn" from record gui, the program draws something, and then  
waits for 1800000 microsecs (I hope threadDelay is measured in  
microsecs), and then draws something else. In fact, the code doesnt do  
this, but waits 1800000+ microsecs, and draws everything at the same  
time. Is there an error somewhere?

MyDraw functions are:

myDraw w h = do
setSourceRGB 255 0 0
setLineWidth 2
moveTo (0.5 * w) (0.43 * h)
lineTo (0.33 * w) (0.71 * h)
stroke

myDraw2 w h = do
moveTo (0.33 * w) (0.71 * h)
setSourceRGB 1 2 0
setLineWidth 15
lineTo (0.66 * w) (0.71 * h)
lineTo (0.5 * w) (0.43 * h)
stroke

If it is needed, I ll give more information and code.
Thank you for your help!

Gabor Hosszu




More information about the Beginners mailing list