Tuesday, August 18, 2009

wxErlang in Action -- Listing 2.3

Listing 2.1 is an example of using wxApp.redirect() -- but that feature doesn't seem to exist in wxErlang at current; and listing 2.2 is an example of a Frame subclass that fixes size, position and title, something implicit in this and the previous listing. So we move on to putting a new control on and listening to its events.

in which I note a systematic error (now corrected) in the previous examples to do with window closing. I had been closing a window a second time in response to its Close event (raised by hitting the kiss-of-death or explicitly calling wxWindow:close(Frame,[])) in the #wx{event=#wxClose{type=close_window}} clauses; more than that, after raising the Close event explicitly, I'd not been handling it, but exiting the main loop.

As seen here, in the handler for the close event, returning the simple atom ok suffices; but after raising the close event, I need to tail-recurse back into the main loop method.

When I didn't handle a close event that I'd raised myself, when I went

C:\Users\Steve\Documents\erlang>"\Program Files\erl5.7.2\bin\erl.exe"
Eshell V5.7.2  (abort with ^G)
1> insertframe:start().
2> insertframe:start().

then having dismissed the first window, when I launched it again, the new window was visible only fleetingly, because the close event I'd raised after close was still in the mailbox for the console. Now I do actually handle it, I can relaunch the app over and over.

Post a Comment