Re: 7GUIs
- Posted by irv Nov 20, 2017
- 1667 views
Here's crud (er.. the 5th challenge:)
include GtkEngine.e sequence names = { "Emil, Hans", "Mustermann, Max", "Tisch, Roman" } constant win = create(GtkWindow,"size=200x200,border=10,$destroy=Quit"), pan = create(GtkBox,"orientation=VERTICAL"), grd = create(GtkGrid,"row spacing=5,column spacing=10,row homogeneous=TRUE"), L1 = create(GtkLabel,"Filter prefix:"), Tp = create(GtkEntry,"width-chars=10"), Lx = create(GtkTreeView,"headers visible=FALSE"), L2 = create(GtkLabel,"Name:"), Tn = create(GtkEntry,"width-chars=10"), L3 = create(GtkLabel,"Surname:"), Ts = create(GtkEntry,"width-chars=10"), BX = create(GtkButtonBox,"layout=2"), Bc = create(GtkButton,"Create","AppendName"), Bu = create(GtkButton,"Update","ReplaceName"), Bd = create(GtkButton,"Delete","DeleteName") add(win,pan) pack_start(pan,grd,1,1) add(BX,{Bc,Bu,Bd}) set(grd,{ {"attach",L1,1,1,1,1}, {"attach",Tp,2,1,1,1}, {"attach",Lx,1,2,2,5}, {"attach",L2,3,2,1,1}, {"attach",Tn,4,2,1,1}, {"attach",L3,3,3,1,1}, {"attach",Ts,4,3,1,1}, {"attach",BX,1,7,3,1}}) constant buffer = get(Tp,"buffer") connect(buffer,"inserted-text","UpdateSearch") connect(buffer,"deleted-text","UpdateSearch") constant col1 = create(GtkColumn,"type=text,text=1") set(Lx,"append column",col1) object store = create(GtkListStore,{gSTR}) set(store,"data",names) set(Lx,"model",store) object selection = get(Lx,"selection") show_all(win) main() ------------------------------ global function UpdateSearch() ------------------------------ object data = FilterSurname(names) set(store,"clear") set(store,"data",data) return 1 end function ------------------------------------------- function FilterSurname(object x) ------------------------------------------- object o = {} object p = upper(get(Tp,"text")) if length(p) = 0 then return names end if for i = 1 to length(x) do if match(p,upper(x[i])) = 1 then o = append(o,x[i]) end if end for return o end function -------------------------- function input_name() -------------------------- return text:format("[], []",{get(Ts,"text"),get(Tn,"text")}) end function --------------------------------------------- global function AppendName() --------------------------------------------- object x = input_name() set(store,"append row",x) names = append(names,x) return 1 end function -------------------------------------------- global function ReplaceName() -------------------------------------------- integer i = get(selection,"selected row") if i > 0 then object x = input_name() set(store,"replace row",{x},i) i = match(x,names) if i > 0 then names[i] = x end if end if return 1 end function -------------------------------------------- global function DeleteName() -------------------------------------------- integer i = get(selection,"selected row") if i > 0 then object x = get(selection,"selected row data") set(store,"remove row",i) names = remove_item(x[1],names) end if return 1 end function