added eugtk examples
This commit is contained in:
64
eugtk/examples/test18.ex
Normal file
64
eugtk/examples/test18.ex
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
--# Data passing, custom buttons
|
||||
|
||||
include GtkEngine.e
|
||||
|
||||
object secret = load(canonical_path(locate_file("resources/secret_message")))
|
||||
|
||||
object docs = `<b><u>Key/Value Pairs</u></b>
|
||||
This demo shows how to use a control's data space
|
||||
to pass multiple key/value pairs to Eu functions.
|
||||
`
|
||||
ifdef UNIX then -- links in labels aren't working in Windows;
|
||||
docs &= sprintf(
|
||||
`See <a href='FILE://%s'>%s</a>.
|
||||
`, -- link to docs;
|
||||
{canonical_path("documentation/HowItWorks.html#datapassing"),"Passing Data"})
|
||||
end ifdef
|
||||
|
||||
constant win = create(GtkWindow,
|
||||
"title=`Flo's Bakery`,size=300x-1,border=10,position=1,$destroy=Quit")
|
||||
|
||||
constant panel = create(GtkBox,"orientation=VERTICAL")
|
||||
add(win,panel)
|
||||
|
||||
constant lbl = create(GtkLabel)
|
||||
set(lbl,"markup",docs)
|
||||
add(panel,lbl)
|
||||
|
||||
constant box = add(panel,create(GtkButtonBox,
|
||||
"orientation=HORIZONTAL,layout=1,spacing=10"))
|
||||
|
||||
constant
|
||||
btn1 = create(GtkButton,"gtk-quit","Quit"),
|
||||
btn2 = create(GtkButton,"thumbnails/pie.png#_Pie",_("Yum")),
|
||||
btn3 = create(GtkButton,"thumbnails/cake.png#_Cake",_("Yum"))
|
||||
|
||||
add(box,{btn1,btn2,btn3})
|
||||
|
||||
set(btn2,{ -- each time "data" is declared, another data item is created.
|
||||
{"data","dessert","Pumpkin Pie"}, -- first is named "dessert", value is "Pumpkin Pie"
|
||||
{"data","price","1.95"}, -- can only pass strings, not atoms/integers
|
||||
{"data","format","<span font='24' color='green'>%s</span>"},
|
||||
{"data","pix","thumbnails/pie.png"}})
|
||||
|
||||
set(btn3,{
|
||||
{"data","dessert","Birthday Cake"},
|
||||
{"data","price","2.10"},
|
||||
{"data","format",secret[2]},
|
||||
{"data","pix","thumbnails/cake.png"}})
|
||||
|
||||
show_all(win)
|
||||
main()
|
||||
|
||||
--------------------------------
|
||||
function Yum(atom ctl)
|
||||
--------------------------------
|
||||
object fmt = get(ctl,"data","format")
|
||||
object snack = get(ctl,"data","dessert")
|
||||
object price = get(ctl,"data","price")
|
||||
object pix = get(ctl,"data","pix")
|
||||
Info(win,"Flo's",sprintf(fmt,{snack}),price,,pix)
|
||||
return 1
|
||||
end function
|
||||
|
||||
Reference in New Issue
Block a user