Next: Simple Button using PyEval Prev: Examples Up: Examples Top: Top
button.uil contains the following text:
module button_test
version = 'V1.0'
names = case_sensitive
object main : XmBulletinBoard { ! bulletin board parent
arguments {
XmNwidth = 200;
XmNheight = 200;
};
controls {
XmPushButton button; ! main is parent of button
};
};
object button : XmPushButton { ! button is labelled Push Me
arguments {
XmNx = 0;
XmNy = 0;
XmNwidth = 100;
XmNheight = 40;
XmNlabelString = 'Push Me';
};
};
end module;
uil button.uil -o button.uid
#!/usr/local/bin/python
import os, sys, Mrm, Xt
def OnActivate(widget, client, call):
print 'OnActivate:',widget,client
def main():
top_level = Xt.Initialize()
# fetch the hierarchy
mrm_hier = Mrm.OpenHierarchy('button.uid')
main_w = mrm_hier.FetchWidget('main', top_level)
button_w = main_w.NameToWidget('button')
button_w.AddCallback('activateCallback', OnActivate, 'Hi')
# manage widgets, realize shell
main_w.ManageChild()
top_level.RealizeWidget()
Xt.MainLoop()
main()
testbutton.py
OnActivate()
. OnActivate
is a typical callback
function, called with widget, client data and call data arguments. It
prints its widget and client data argument. The call data argument is
binary, hence ugly when printed.
Then the script declares the function main()
. main()
opens the hierarchy defined by button.uid, fetches the widget named
"main", which is a bulletin board, and its child, a pushbutton. Next,
main()
uses NameToWidget
to obtain a Python widget
object for the button widget, and adds OnActivate()
as the
XmNactivateCallback
function, passing "Hi" as the client
data. main()
then manages these widgets, realizes the shell,
and enters the Xt Event Loop.
Finally, the script invokes main()
, which executes the function
main()
, and generates the interface as described above.
When the user pushes the pushbutton (labelled "Push Me" by the
XmNlabelString
resource specified in the .uil file), the
OnActivate()
function is called with the string "Hi" as its
client data. OnActivate
prints "Hi" on stdout.