wxErlang in Action -- Listing 1.2
So, after a long episode of IRL (and work), and some fruitless delving through the wxErlang docs...
-module('spare'). | |
-export([start/0]). | |
-include_lib("wx/include/wx.hrl"). | |
start() -> | |
_WX = wx:new(), | |
Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Spare"), | |
wxFrame:connect(Frame, close_window), | |
wxFrame:show(Frame), | |
% No obvious equivalent to wxApp.SetTopWindow(Frame) found in wxErlang 0.98.2 | |
loop(Frame), | |
wx:destroy(). | |
loop(Frame) -> | |
receive | |
#wx{event=#wxClose{type=close_window}} -> | |
ok % this is not needed --> wxWindow:close(Frame,[]) | |
end. |
Now there are factorings that could be made to make this more "subclass"-able -- let loop
take an arbitrary term and a fun/3 of loop
, the term and a message term, passed in as a handler for any other message, and return ok
if looping is to continue, and allowing for code hot-swapping; but this is probably better to just be a template at the source level.
No comments :
Post a Comment