> The following code gives me "interesting" results:
> module Main where
> import Graphics.UI.WX
> main = start $ do f <- frame [text := "layout demo"]
> h <- staticText f 
> hello h
> q <- button f [text := "quit", on command
> := close f]
> set f [layout := column 5 [widget h,
> widget q]]
> hello st = set st [text := "Hello world!",
> on click := \_ -> goodbye st]
> goodbye st = set st [text := "Goodbye world!",
> on click := \_ -> hello st]
> The code is intended to alternate between displaying "Hello
> world!" and "Goodbye world!" each time you click on the text.
> Instead, sometimes it crashes, and it never ends up getting
> back to displaying "Hello world!" after you've clicked it.
> It seems to occasionally go into a frenzy of alternating
> between "Hello world!" and "Goodbye world!" for quite a
> while--presumably stopping when some sort of a race condition
> has been satisfied.
> So my question is, am I supposed to be allowed to modify a
> callback function within that callback function?
Yes, you should definitely be able to set callbacks within
callbacks -- and it happens all the time too, so the general
mechanism works. (for example, the initialization code given
as an argument to "start" is a callback itself..)
Regarding your example, it is either a bug in my code or in
the wxWindows code and I'll have to debug it myself in more
detail (but I am extremely busy getting my phd-thesis to the
presses so it can take a few more days).
It might have something to do with chain of "click" events
that keep occurring. Maybe you should call "propegateEvent" at
the end of each event handler.
I'll investigate this further,
Thanks for the report,
> Obviously I
> could get the same functionality either using an IORef or by
> checking the current contents of the text, but I don't see
> why you shouldn't be able to modify a callback within the
> callback. Or perhaps there is some other more subtle problem
> going on here...
> David Roundy
> This SF.net email is sponsored by: SF.net Giveback Program.
> SourceForge.net hosts over 70,000 Open Source Projects. See
> the people who have HELPED US provide better services: Click
> here: http://sourceforge.net/supporters.php
> wxhaskell-users mailing list wxhaskell-users@...