
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

On Mon, Dec 26, 2011 at 03:37,
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?
The usual behavior is to "batch" screen updates until your handler returns. I *think* you want Graphics.UI.Gtk.Gdk.drawWindowProcessUpdates. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Mon, Dec 26, 2011 at 6:37 AM,
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?
Yes, you should not block the UI thread. Never. If you want your code to behave well, you'll need to do something like adding a timer that goes off after 1.8s or something like that. If you keep blocking your UI thread, you'll have many many headaches. Cheers, -- Felipe.
participants (3)
-
Brandon Allbery
-
Felipe Almeida Lessa
-
gabre@caesar.elte.hu