Re: Pixbuf column for a tree custom model

Dmitry Bely <[email protected]> Mon, 5 Jul 2010 14:56:43 +0400
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
Hi Maxence,

Thanks a lot but that's not what I need. You describe how to create a
Gtk list store that holds pixbuf data; I know that. But my question
was about the custom model
(http://www.tupelo-schneck.org/robert/custom-model), now integrated
into Lablgtk. There are some examples in Lablgtk distribution
(examples/custom_*.ml) with a custom_value method like

  method custom_value (t:Gobject.g_type) (row:custom_tree) ~column =
    if column = 0 then `CAML (Obj.repr row)
    else if column = 1 then
      `BOOL (match row with File {finfo={fchecked=b}} -> b
             | _ -> false )
    else if column = 2 then
      `INT (5+(get_nb row))
    else assert false

It illustrates that returning basic Ocaml types is trivial. But how to
return pixbuf? It's not clear to me.

- Dmitry Bely

BTW, custom_tree_generic.ml example does not work in my system. What about you?

On Mon, Jul 5, 2010 at 2:13 PM, Maxence Guesdon
<[email protected]> wrote:
> 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
>
>
> _______________________________________________
> Lablgtk mailing list
> [email protected]
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk
>