Date: Fri, 28 Oct 2005 09:53:15 +0200 From: Stefano Zacchiroli To: LablGTK Mailing List Subject: Re: example of tree with cell_renderer_combo Message-ID: <20051028075315.GA11657 at aquarium.takhisis.invalid> Mail-Followup-To: LablGTK Mailing List References: <20051027162700.GA10076 at aquarium.takhisis.invalid> <20051027211507.GA11768 at aquarium.takhisis.invalid> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Content-Disposition: inline In-Reply-To: --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Oct 27, 2005 at 03:13:36PM -0700, Eric Stokes wrote: > I think you may have everything correct, except that you forgot to > set the `EDITABLE property to true, and the `TEXT_COLUMN property > needs to be set to the column in your combo store which contains the > enumerated values you want to appear in the popup list. As for the Thanks for your example and tips Eric. Basically, what I was doing wrong was that I did not realize I need two difference columns in the model: one representing the domain of values (another model) and one representing the current value. Attached there's a sample code which may be useful for further reference. Some minor issues still remain however: - I need to manually add attributes to the value_renderer since they have different types (one is a string column, the other a gobject column) and GTree.view_column requires an 'a column list as attributes - I'm not able to extract the only column from the model used by the combo renderer, there seems to be no way to do that. Since such models are added after the creation of the renderer I do not know at that time which column I need to render. As an hack I created a dummy column with the same time and position as the one I need and used it, this seems to work. Cheers. -- Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/ If there's any real truth it's that the entire multidimensional infinity of the Universe is almost certainly being run by a bunch of maniacs. -!- --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tree_combo.ml" let win = GWindow.window ~show:true () in let cols = new GTree.column_list in let name_col = cols#add Gobject.Data.string in let value_col = cols#add Gobject.Data.string in let domain_col = cols#add (Gobject.Data.gobject_by_name "GtkTreeModel") in let name_renderer = GTree.cell_renderer_text [], ["text", name_col] 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_name_col = GTree.view_column ~renderer:name_renderer () 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 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_name_col in let _ = view#append_column view_value_col in let append (list_store: GTree.list_store) n 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:name_col n; list_store#set ~row:iter ~column:value_col v; list_store#set ~row:iter ~column:domain_col d#as_model; in let _ = append list_store "foo" "0" ["0";"1";"2"]; append list_store "bar" "1" ["1";"2";"3"]; append list_store "baz" "2" ["2";"3";"4"]; in GMain.Main.main () --T4sUOijqQbZv57TR--