Re: EuGTK - List: View - click event
- Posted by irv Sep 25, 2010
- 1478 views
Just connect the "row-activated" signal to your eu routine. This works on double-click - obviously, since a single click only selects a row. See demo below. But first: DOWNLOAD THE LATEST EuGTK 4.2.4! There are many improvements, including fixing one severe memory leak! Get it from wikispaces or my home page or SourceForge
include GtkEngine.e include std/machine.e include ListView.e as LV enum VEG, MG, SERV constant veg = { {"Asparagus, raw",23,8}, {"Beet greens, boiled",164,12}, {"Broccoli, raw",43,14}, {"Cabbage, boiled",36,6}, {"Chard, swiss, boiled",102,5}, {"Collards, boiled",266,4}, {"Onions, raw",37,10} } function Foo(atom view) sequence selected_food = get(view,"text",VEG) integer selected_serv = get(view,"value",SERV) printf(1,"The recommended serving for %s is %d oz.\n",{selected_food,selected_serv}) return 1 end function constant foo = call_back(routine_id("Foo")) object lv = LV:Iter(4) constant tv = LV:View(lv,{"Name","mg/oz","Serving (oz)"}) -- {column headings} set(tv,"reorderable",TRUE) set(tv,"rules hint",TRUE) -- shade alternate lines set(tv,"grid lines",GTK_TREE_VIEW_GRID_LINES_BOTH) set(tv,"enable search",TRUE) -- < optional, but real handy. try it, you'll like it > connect(tv,"row-activated",foo) -- < here > constant img = create(GtkImage,"/home/irv/demos/tiphat.gif") constant win = create(GtkWindow) connect(win,"destroy",quit) set(win,"modify bg",0,"lightgray") set(win,"border width",5) constant panel = create(GtkVBox) add(win,panel) add(panel,tv) object store = LV:Store({gSTR,gINT,gINT}) -- {column data types} set(tv,"model",store) for i = 1 to length(veg) do -- load the list store with data LV:Row(lv,store,veg[i]) end for setRow(2,1,store,"Arthritic Aardvaarks") -- row #, col #, store, value) show_all(win) main()
Note: You seldom want to trigger a list or tree view event from a single click. 1. It doesn't work the way people expect it to if you do that 2. It prevents you from setting up lists which allow multiple selections 3. It prevents the user from being able to drag & drop items within the list