
Use command "zsw.exe example.zs" to test a script example.
/********************************************************************
* execute this script by "zsw.exe script_file_name" command.
********************************************************************/
// set top frame event handler
wxevth("event_handler");
// get the top frame create by zsw.exe
frame = wxframe();
// set top frame title
frame.title("http://www.zegraph.com/");
// create manu bar
menu1 = frame.menubar("&File", "&Color Dialog\tCtrl-c", "_", "Dir Dialog\tCtrl-d",
">", "Submenu", "&File Dialog\tCtrl-f", "S&ub-2\tCtrl-u",
"<", "F&ont DialogCtrl-o");
menu2 = frame.menubar("&Help", "&About\tCtrl-A");
// create tool bar
tool = frame.toolbar("ico1.bmp", "tip1...", "|", " ", "ico2.bmp", "tip2...");
// create status bar
frame.statusbar(2);
frame.statusbar(0, "status-1");
frame.statusbar(1, "status-2");
// cast top frame to generic window control type
win = wxcast(frame);
// push event handlers
win.push("menubar_handler", "menu", menu1, menu2);
win.push("toolbar_handler", "tool", tool);
win.push("key_handler", "key");
win.push("mouse_handler", "mouse");
// menu bar handler: show various dialog windpws
function menubar_handler(id)
{
if (id == menu1[0]) {
a = wxcolor();
if (isarray(a)) wxmsg("R=" + a[0] + " G=" + a[1] + " B=" + a[2]);
}
else if (id == menu1[1]) {
a = wxdir();
if (isstring(a)) wxmsg(a);
}
else if (id == menu1[2]) {
a = wxfile();
if (isstring(a)) {
wxmsg(a);
}
else if (isarray(a)) {
n = a.size();
for (i = 0; i < n; i++) wxmsg(a[i]);
}
}
else if (id == menu1[4]) {
a = wxfont();
if (isarray(a)) {
n = a.size();
for (i = 0; i < n; i++) wxmsg(" "+a[i]);
}
}
else {
wxmsg(" " + id);
}
}
// tool bar handler: turn on/off timer
function toolbar_handler(id)
{
if (id == tool[0]) {
wxtimer(1000);
}
else if (id == tool[1]) {
wxtimer(0);
}
}
// event handler: update status bar message when timer event arrives
function event_handler(evt, p1, p2)
{
if (evt == "timer") {
tm = now();
frame.statusbar(0, tm.hour+":"+tm.minute+":"+tm.second);
}
}
// key handler: turn on/off full screen
function key_handler(p1, p2, p3, p4, win)
{
if (p1 == 70) { // f-key
frame.fullscreen(true);
}
else if (p1 == 27) { // esp-key
frame.fullscreen(false);
}
else if (p1 == 13) { // enter
// do nothing
}
else {
wxmsg("p1="+p1+" p2="+p2+" p3="+p3+" p4="+p4);
}
}
// mouse handler: show mouse click informatopm
function mouse_handler(p1, p2, p3, p4, p5, p6, win)
{
if (p1 == 2) {
wxmsg("p1="+p1+" p2="+p2+" p3="+p3+" p4="+p4+" p5="+p5+" p6="+p6);
}
}
/********************************************************************
* execute this script by "zsw.exe script_file_name" command.
********************************************************************/
// get the top frame create by zsw.exe
frame = wxframe();
// cast top frame to generic window control type
win = wxcast(frame);
// set size
win.size(500, 500);
// create a panel in the top frame
panel = win.panel();
// set background color
panel.bgcolor(255, 255, 255);
// create vertically aligned sizer
topsizer = panel.sizer("verbox");
// add some space
topsizer.add(10, 30);
/*
1) create a horizontally aligned sizer in the top sizer;
2) add label and text box to the sizer.
note: control should be create in a panel and added to a sizer.
*/
sizer = topsizer.sizer("horbox", "aligncenter");
obj = panel.statictext("label ", 0);
obj.fgcolor(0, 0, 255);
obj.font(14);
sizer.add(obj, "all|aligncenter");
obj = panel.textbox("text content", 200, 30);
obj.font(12);
sizer.add(obj);
topsizer.add(10, 20);
/*
1) create a horizontally aligned group sizer in the top sizer;
2) add check boxes to the sizer.
3) add combo box to the sizer.
4) add radio buttons to the sizer.
note: a group sizer must be create in a panel.
*/
panel2 = panel.panel();
topsizer.add(panel2, "all|aligncenter");
sizer = panel2.sizer("horstatic", "Group", 350, 50);
obj = panel2.checkbox("check1", true);
sizer.add(10,10);
sizer.add(obj, "aligncenter");
obj = panel2.checkbox("check2", false);
sizer.add(10,10);
sizer.add(obj, "aligncenter");
combo = panel2.combobox(["item1", "item2", "item3"], 1);
sizer.add(10,10);
sizer.add(combo, "aligncenter");
radio1 = panel2.radiobutton("radio1");
radio1.set(1);
sizer.add(10,10);
sizer.add(radio1, "aligncenter");
radio2 = panel2.radiobutton("radio2");
sizer.add(10,10);
sizer.add(radio2, "aligncenter");
/*
create a row of option radio buttons in the top sizer;
*/
topsizer.add(10, 20);
opt = panel.radiobox("Option", "cols", "opt1 ", "opt2 ", "opt2");
topsizer.add(opt, "all|aligncenter");
/*
create a slider in the top sizer;
*/
topsizer.add(10, 20);
obj = panel.slider("bottom", 0, 100, 20, 10);
topsizer.add(obj, "all|aligncenter");
/*
create a grid sizer in the top sizer and add controls in it.
*/
topsizer.add(10, 20);
sizer = topsizer.sizer("flexgrid", 2, 5, 3, 5, "all|aligncenter");
obj = panel.button("button1");
sizer.add(obj, "all|aligncenter");
obj = panel.button("button2");
sizer.add(obj, "all|aligncenter");
obj = panel.button("button3");
sizer.add(obj, "all|aligncenter");
obj = panel.button("button4");
sizer.add(obj, "all|aligncenter");
obj = panel.button("button5");
sizer.add(obj, "all|aligncenter");
obj = panel.button("button6");
sizer.add(obj, "all|aligncenter");
/*
the OK button
*/
ok = panel.button("OK");
topsizer.add(10,20);
topsizer.add(ok, "aligncenter");
ok.push("ok_handler", "mouse");
////////////////////////////////////////////////
function ok_handler(p1, p2, p3, p4, p5, p6)
{
if (p1 == 1) { // left up
// manually set radio buttons
if (radio1.get() == 1) {
radio1.set(0);
radio2.set(1);
}
else {
radio1.set(1);
radio2.set(0);
}
// show selected option in combobox
wxmsg(combo.get());
// show selected option in radiobox
wxmsg(opt.get());
}
}
/********************************************************************
* execute this script by "zsw.exe script_file_name" command.
********************************************************************/
// cast top frame to generic window control type
win = wxcast(wxframe());
// set size
win.size(500, 500);
// create vertical splitter
vsp = win.splitter(200);
// set minimum split size of the first panel
vsp.min(100);
// create herizontal splitter
hsp = vsp.splitter(2, 200, "h");
// put control in splitter panels
w = vsp.get(1);
w.button("Button1");
w = hsp.get(2);
w.button("Button2");
/******************************************************************** * execute this script by "zsw.exe script_file_name" command. ********************************************************************/ // cast top frame to generic window control type win = wxcast(wxframe()); // set size win.size(500, 500); // create grid control g = win.grid(20, 20); // set column label g.label(0, "Label1"); g.label(1, "Label2"); // set cell values g[0,0] = "X"; g[1,0] = "100"; g[2,0] = "200"; g[0,0] = "Y"; g[1,1] = ""+(integer(g[1,0])+1); g[2,1] = ""+(integer(g[2,0])+1);
/********************************************************************
* execute this script by "zsw.exe script_file_name" command.
********************************************************************/
// cast top frame to generic window control type
win = wxcast(wxframe());
// set size
win.size(500, 500);
// create notebook control
note = win.notebook("top");
// add a panel to notebook
panel = note.add("Note2");
// add buttons to the panel
sizer = panel.sizer("verbox");
sizer.add(20, 20);
b = panel.button("Button3");
sizer.add(b, "aligncenter");
sizer.add(20, 20);
b = panel.button("Button4");
sizer.add(b, "aligncenter");
// add another panel to notebook (insert to the front)
panel = note.add("Note1");
// add buttons to the panel
sizer = panel.sizer("verbox");
sizer.add(20, 20);
b = panel.button("Button1");
sizer.add(b, "aligncenter");
sizer.add(20, 20);
b = panel.button("Button2");
sizer.add(b, "aligncenter");
/********************************************************************
* execute this script by "zsw.exe script_file_name" command.
********************************************************************/
// cast top frame to generic window control type
win = wxcast(wxframe());
// set size
win.size(500, 500);
// create notebook control
tree = win.treeview("callback");
// set root node name
tree.root("root");
// append items to nodes
tree.append("/", "group1");
tree.append("/", "group2");
tree.append("/group1", "item1");
tree.append("/group1", "item2");
tree.append("/group1", "item3");
tree.append("/group2", "item1");
tree.append("/group2", "item2");
tree.append("/group2", "item3");
// handle event here
function callback(evt, s)
{
wxmsg(evt+": "+s);
}