Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. gtk2hs and threadDelay (ga...@caesar.elte.hu) 2. Re: gtk2hs and threadDelay (Brandon Allbery) 3. Re: gtk2hs and threadDelay (Felipe Almeida Lessa) 4. gtk2hs and threadDelay (ga...@caesar.elte.hu) 5. Re: gtk2hs and threadDelay (Felipe Almeida Lessa) 6. Re: gtk2hs and threadDelay (Brandon Allbery) 7. Re: gtk2hs and threadDelay (Felipe Almeida Lessa) ---------------------------------------------------------------------- Message: 1 Date: Mon, 26 Dec 2011 09:37:17 +0100 From: ga...@caesar.elte.hu Subject: [Haskell-beginners] gtk2hs and threadDelay To: beginners@haskell.org Message-ID: <20111226093717.70642elc9qjsi...@webmail.caesar.elte.hu> Content-Type: text/plain; charset=ISO-8859-2; DelSp="Yes"; format="flowed" 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 ------------------------------ Message: 2 Date: Mon, 26 Dec 2011 04:20:27 -0500 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] gtk2hs and threadDelay To: ga...@caesar.elte.hu Cc: beginners@haskell.org Message-ID: <cakfcl4wnxwurowcx5iqzrv73zkilru6l3afcfsn4ge0q2uq...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Mon, Dec 26, 2011 at 03:37, <ga...@caesar.elte.hu> wrote: > 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 allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111226/078b0d5b/attachment-0001.htm> ------------------------------ Message: 3 Date: Mon, 26 Dec 2011 07:24:20 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] gtk2hs and threadDelay To: ga...@caesar.elte.hu Cc: beginners@haskell.org Message-ID: <CANd=ogf79nxo-huy6m4x39ae56qx-3xho8gnorerzok96z7...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Dec 26, 2011 at 6:37 AM, <ga...@caesar.elte.hu> wrote: > 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. ------------------------------ Message: 4 Date: Mon, 26 Dec 2011 11:33:48 +0100 From: ga...@caesar.elte.hu Subject: [Haskell-beginners] gtk2hs and threadDelay To: beginners@haskell.org Message-ID: <20111226113348.201514rguptlb...@webmail.caesar.elte.hu> Content-Type: text/plain; charset=ISO-8859-2; DelSp="Yes"; format="flowed" Thanks for the quick answers. I dont really know, what timer functions there are, I googled "timing, scheduling, delaying in haskell", but the only function I found, was threaddelay. How did you mean "adding a timer"? On the other side, I checked Graphics.UI.Gtk.Gdk.drawWindowProcessUpdates. I guess, I should use this in the function, where I draw something, and wait, and draw something else, and I should put it between the two drawing steps to get an immediate update. If I do so, the drawing gets blocked again, and nothing happens for some second, and then everything is drawn at the same time. Sorry, I m a very beginner at this topic. ------------------------------ Message: 5 Date: Mon, 26 Dec 2011 08:44:18 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] gtk2hs and threadDelay To: ga...@caesar.elte.hu Cc: beginners@haskell.org Message-ID: <CANd=OGGaDkznHmT=0pcj4gd4giyvoftsuydqq6zwwbj1lpf...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Dec 26, 2011 at 8:33 AM, <ga...@caesar.elte.hu> wrote: > Thanks for the quick answers. > > I dont really know, what timer functions there are, I googled "timing, > scheduling, delaying in haskell", but the only function I found, was > threaddelay. How did you mean "adding a timer"? This is Gtk+ stuff, since the main loop is there. I'm talking about using timeoutAdd [1]. Note that although the docs begin by saying that the function is called at regular intervals, you just need to make sure to return False to avoid that. [1] http://hackage.haskell.org/packages/archive/glib/0.12.2/doc/html/System-Glib-MainLoop.html#v:timeoutAdd > On the other side, I checked Graphics.UI.Gtk.Gdk.drawWindowProcessUpdates. I > guess, I should use this in the function, where I draw something, and wait, > and draw something else, and I should put it between the two drawing steps > to get an immediate update. If I do so, the drawing gets blocked again, and > nothing happens for some second, and then everything is drawn at the same > time. Even if you're able solve this particular problem, your application still won't be processing events. It will feel slugish and it's possible that the window manager may decide that it has crashed. Cheers, -- Felipe. ------------------------------ Message: 6 Date: Mon, 26 Dec 2011 05:45:11 -0500 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] gtk2hs and threadDelay To: ga...@caesar.elte.hu Cc: beginners@haskell.org Message-ID: <cakfcl4wuwnkmos6ey60tqwc1cwpstx8k40dqylz6jgqtw72...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Mon, Dec 26, 2011 at 05:33, <ga...@caesar.elte.hu> wrote: > I dont really know, what timer functions there are, I googled "timing, > scheduling, delaying in haskell", but the only function I found, was > threaddelay. How did you mean "adding a timer"? > http://hackage.haskell.org/packages/archive/gtk/0.12.2/doc/html/Graphics-UI-Gtk-General-General.html#g:7 > On the other side, I checked Graphics.UI.Gtk.Gdk.**drawWindowProcessUpdates. > I guess, I It may not actually be the right function. Felipe was however correct in that it's the wrong way to go about it; see the above to add a callback that executes after a delay, *without locking up the UI* which is what the threadDelay method will do. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111226/db22c5fa/attachment-0001.htm> ------------------------------ Message: 7 Date: Mon, 26 Dec 2011 08:51:36 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] gtk2hs and threadDelay To: Brandon Allbery <allber...@gmail.com> Cc: beginners@haskell.org, ga...@caesar.elte.hu Message-ID: <CANd=OGF9_SKt6aGX5FKM=zuwuc4v2r6wxhurgrbxjjramvb...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Mon, Dec 26, 2011 at 8:45 AM, Brandon Allbery <allber...@gmail.com> wrote: > http://hackage.haskell.org/packages/archive/gtk/0.12.2/doc/html/Graphics-UI-Gtk-General-General.html#g:7 Note that this is a re-export of the function I've linked on my e-mail, so don't worry about having to choose which one you'll use =). Cheers, -- Felipe. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 42, Issue 28 *****************************************