Re: Pixbuf column for a tree custom model

Maxence Guesdon <[email protected]> Mon, 5 Jul 2010 12:13:04 +0200
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
Le Mon, 5 Jul 2010 11:02:17 +0400,
Dmitry Bely <[email protected]> a écrit :

> Hello,

Hello,

> 
> How to return GdkPixbuf.pixbuf from a user-defined method
> custom_get_value (custom_tree_model_type)? Probably it should be
> `POINTER but I fail to see how to construct it from a pixbuf. Any
> hints are greatly appreciated.

You may hav a look at the Gmytree module included in cameleon2:
  http://svn.gna.org/viewcvs/cameleon/trunk/src/utils/gmytree.ml?rev=749&view=markup

It gives a way to define a tree with a description of the columns. For
a use case, you may look at
  http://svn.gna.org/viewcvs/cameleon/trunk/src/editor/ed_odoc.ml?rev=749&view=markup
 (in class view)

The important part of Gmytree is;

  ...
  let tcols = new GTree.column_list in
  let disp_cols = List.map
      (function
          `String _ ->
            `String (tcols#add Gobject.Data.string)
        | `Pixmap _ ->
            `Pixbuf (tcols#add (Gobject.Data.gobject : GdkPixbuf.pixbuf
  Gobject.data_conv)) ) cols
  in
  let (datacol : 'a GTree.column) =  tcols#add Gobject.Data.caml in
  let store = GTree.tree_store tcols in
  let view = GTree.view
      ~headers_visible: false
      ~model: store ~packing: wscroll#add_with_viewport () in
  let renderer = GTree.cell_renderer_text [] in
  let pix_renderer = GTree.cell_renderer_pixbuf [] in
  let _ =
    List.iter
      (fun c ->
        let col =
          match c with
            `String c -> GTree.view_column () ~renderer: (renderer,
  ["text", c]) | `Pixbuf c -> GTree.view_column () ~renderer:
  (pix_renderer, ["pixbuf",c]) in
        ignore (view#append_column col)
      )
      disp_cols
  in
  ...

Hope this helps,

Maxence