added eugtk examples
This commit is contained in:
55
eugtk/examples/test66.ex
Normal file
55
eugtk/examples/test66.ex
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
--# Custom monetary formatting for GtkCellRenderers
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
include GtkEngine.e
|
||||
include std/locale.e
|
||||
|
||||
constant win = create(GtkWindow,
|
||||
"icon=face-cool,size=300x150,border_width=10,position=1,$destroy=Quit")
|
||||
|
||||
constant panel = add(win,create(GtkBox,VERTICAL))
|
||||
constant scrol = pack(panel,create(GtkScrolledWindow),TRUE,TRUE)
|
||||
|
||||
sequence students = { -- name, age, amt due
|
||||
{"Sam Smith", 15, 1009.95},
|
||||
{"Sue Jones", 14, 12.99},
|
||||
{"Freddie Farkel",16,20.0054}, -- will round up
|
||||
$}
|
||||
|
||||
constant store = create(GtkListStore,{gSTR,gINT,gDBL})
|
||||
gtk:set(store,"data",students)
|
||||
|
||||
constant dollar = call_back(routine_id("monetary_format"))
|
||||
|
||||
constant tv = add(scrol,create(GtkTreeView,{{"model",store}}))
|
||||
|
||||
constant
|
||||
-- note: Column is not a GTK widget, it is implemented
|
||||
-- in EuGTK for convenience in creating GtkTreeViewColumns
|
||||
-- and associated GtkCellRenderers with less coding...
|
||||
col1 = create(GtkColumn,"title=Name,type=text,text=1"),
|
||||
col2 = create(GtkColumn,"title=Age,type=text,text=2"),
|
||||
rend3 = create(GtkCellRendererText,{{"alignment",1,0}}),
|
||||
col3 = create(GtkTreeViewColumn,{
|
||||
{"title","Amt Due"},
|
||||
{"pack start",rend3,TRUE},
|
||||
{"add attribute",rend3,"text",3},
|
||||
{"cell data func",rend3,dollar}})
|
||||
|
||||
gtk:add(tv,{col1,col2,col3})
|
||||
|
||||
show_all(win)
|
||||
main()
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- generic monetary formatting function;
|
||||
-- currently broken in Windows, possibly because of locale problem?
|
||||
----------------------------------------------------------------------
|
||||
function monetary_format(atom layout, atom rend, atom mdl, atom iter)
|
||||
----------------------------------------------------------------------
|
||||
atom val = gtk:get(mdl,"col data from iter",iter,3)
|
||||
gtk:set(rend,"property","markup",locale:money(val)) -- must set "property" here!
|
||||
return 1
|
||||
end function
|
||||
Reference in New Issue
Block a user