GTkTreeModel
Ewen Maclean <[email protected]> Wed, 15 Apr 2015 16:28:40 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <CAEC1HmnTvwB_mxLACF54KnT+Y0qQKnYuc8YuKVOnj6f2Sa59-A@mail.gmail.com> |
Hello,
firstly apologies if this question has already been answered, but I
cannot find the answer. Thanks to an old post on here I have managed
to populate a GTree.view with cells which contain drop-down combo
boxes. I cannot work out how though to retrieve the selection made. A
simple version of the code which exmplifies the problem is below.
The problem I have is that I use the line:
let d = model#get ~row:iter ~column:domain_col in
to retrieve the list when something is selected from the the combo
cell. The selection (I believe) has iter i at this point.
I cannot seem to cast this Gobject (d is originally made from
Gobject.Data.gobject_by_name "GtkTreeModel") to anything useful to
which I can apply the iter i to retreive the selection.
I would be really grateful if anyone could give me a clue how to do
this - even so that the correct value is shown in the cell once
selected!
Thanks very much in advance for any help.
=====
let win = GWindow.window ~show:true () in
let cols = new GTree.column_list in
let value_col = cols#add Gobject.Data.string in
let domain_col = cols#add (Gobject.Data.gobject_by_name "GtkTreeModel") in
let string_col = (new GTree.column_list)#add Gobject.Data.string in
let value_renderer =
GTree.cell_renderer_combo
[ `VISIBLE true;
`TEXT_COLUMN string_col;
`HAS_ENTRY false;
`EDITABLE true; ]
in
let view_value_col = GTree.view_column ~renderer:(value_renderer, []) () in
let _ =
view_value_col#add_attribute value_renderer "model" domain_col;
view_value_col#add_attribute value_renderer "text" value_col;
in
let choices = [("0",["0";"1";"2"]);
("1",["0";"1";"2"]);
("2", ["0";"1";"2"])]
in
let list_store = GTree.list_store cols in
let model = (list_store :> GTree.model) in
let view = GTree.view ~model ~packing:win#add ~show:true () in
let _ = view#append_column view_value_col in
let change_val i p (ls:GTree.list_store) =
let iter = model#get_iter p in
let d = model#get ~row:iter ~column:domain_col in
(*let m = (d :> GTree.model) in*)
()
in
ignore(value_renderer#connect#changed ~callback:(fun tp iter ->
change_val iter tp list_store));
let append (list_store: GTree.list_store) v d =
let d, _ = GTree.store_of_list Gobject.Data.string d in
let iter = list_store#append () in
list_store#set ~row:iter ~column:value_col v;
list_store#set ~row:iter ~column:domain_col d#as_model;
in
List.iter (fun (x,y) -> append list_store x y) choices;
GMain.Main.main ()