Contact: zeng  @  zegraph.com      Last update: 20 January 2010

Embedding ZeScript in wxWindows

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 ZeScript uses a derived wxEvtHandler to handle most events of menu bar, tool bar, key, mouse, and standard control widgets.

Upon startup, the widget program zsw.exe creates a main frame window and then executes the ZeScript file zsw.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.