added eugtk examples
This commit is contained in:
74
eugtk/examples/test180.ex
Normal file
74
eugtk/examples/test180.ex
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
--# Passing data using multiple maps
|
||||
|
||||
include GtkEngine.e
|
||||
|
||||
include std/map.e
|
||||
|
||||
constant docs = `<u><b>Passing data using Maps</b></u>
|
||||
|
||||
Another way to attach data to controls.
|
||||
|
||||
This creates a separate map for each person, and
|
||||
passes just that map to the called routine.
|
||||
|
||||
These maps can be loaded directly from Euphoria sequences,
|
||||
without having to name the individual fields. Fields must
|
||||
be in the proper order, since they are later referenced by
|
||||
number.
|
||||
|
||||
Maps can be saved to disk, and loaded as necessary.
|
||||
`
|
||||
constant jerrymap = load_map(locate_file("resources/jerry.map"))
|
||||
constant justinmap = load_map(locate_file("resources/justin.map"))
|
||||
|
||||
constant win = create(GtkWindow,"border=10,size=300x100,position=1")
|
||||
connect(win,"destroy","Quit")
|
||||
|
||||
constant panel = create(GtkBox,"orientation=VERTICAL")
|
||||
add(win,panel)
|
||||
|
||||
constant lbl = create(GtkLabel)
|
||||
set(lbl,"markup",docs)
|
||||
add(panel,lbl)
|
||||
|
||||
constant
|
||||
btn1 = create(GtkButton,"gtk-quit","Quit"),
|
||||
btn2 = create(GtkButton,"emblem-ok-symbolic#_Jerry","ShowInfo",jerrymap), -- link by map id;
|
||||
btn3 = create(GtkButton,"emblem-ok-symbolic#_Justin","ShowInfo",justinmap),
|
||||
btn4 = create(GtkButton,"gtk-save","Save"),
|
||||
box = create(GtkButtonBox)
|
||||
-- set(btn4,"sensitive",FALSE)
|
||||
add(box,{btn1,btn2,btn3,btn4})
|
||||
pack(panel,-box)
|
||||
|
||||
show_all(win)
|
||||
main()
|
||||
|
||||
--------------------------------------------------------------
|
||||
global function ShowInfo(atom ctl, object themap) -- map id;
|
||||
---------------------------------------------------------------
|
||||
object data = map:get(themap,"Data")
|
||||
Info(,,data[1], -- must retrieve items by position;
|
||||
format(" age: [2]\n bal: $[3]",data),,
|
||||
locate_file(data[$]))
|
||||
return 1
|
||||
end function
|
||||
|
||||
-----------------------
|
||||
global function Save()
|
||||
-----------------------
|
||||
-- here's how to save a couple of maps, no keys;
|
||||
|
||||
map:put(jerrymap,"Data",{"Jerry Smith",16, 49.95, "Buffalo, NY","000-555-1212","thumbnails/Jerry.jpg"})
|
||||
map:put(justinmap,"Data",{"Justin Jones",14, 12.99, "Reno, NV", "123-456-6789","thumbnails/Justin.jpg"})
|
||||
|
||||
-- SM_RAW map info is encoded, so not readable except to a programmer,
|
||||
-- and is considered a Binary mime type, so there probably aren't any
|
||||
-- apps installed which can read it if clicked on...
|
||||
|
||||
save_map(jerrymap,canonical_path("~/demos/resources/jerry.map"),SM_RAW)
|
||||
save_map(justinmap,canonical_path("~/demos/resources/justin.map"),SM_TEXT)
|
||||
|
||||
return 1
|
||||
end function
|
||||
Reference in New Issue
Block a user