The wxWidnows library is one of the best open source libraries for developing cross-platform user interface. Its smart API for event handling makes it very easy to embed a scripting language for widget creation. The embedded Z-Script uses a derived wxEvtHandler to handle most events of menu bar, tool bar, key, mouse, and standard control widgets.
Upon startup, the widget program creates a main frame window and then executes the Z-Script file of the same name as the widget program but the extension of ".zs". The script should first obtain the frame and then add menubar, toolbar, or controls in it. For instance,
frame = wxframe();
a = frame:menubar("&File", "&Item-1\tCtrl-I", "_", "I&tem-2\tCtrl-t",
">", "Submenu", "&Sub-1\tCtrl-S", "S&ub-2\tCtrl-u",
"<", "It&em-3\tCtrl-e");
b = frame:menubar("&Help", "&About\tCtrl-A");
na = size(a);
nb = size(b);
for (i = 0; i < nb; i++) a[na+i] = b[i];
frame = wxcast(frame);
frame:push("event_handler", "menu", a);
function event_handler(id)
{
s = " " + id;
wxmsg(s);
}
You may have noticed in the reference that the function push() is registered to the base window, when we want to push a event-handling callback function to handle menu event in the frame, we have to cast the frame from top window type to base window type.