Delivered-To: garrigue at math.nagoya-u.ac.jp Authentication-Results: mailhost.math.nagoya-u.ac.jp sender=lablgtk-bounces at yquem.inria.fr; domainkey=neutral (no query protocol specified; no policy for yquem.inria.fr) Delivered-To: lablgtk at yquem.inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=ruv7hw5BDygCOtCKlxM4JCQwbtTzXfshynbP4RE552Q=; b=K2oQlcSsh472DrXlTu+GPxU6kyIWix1TZF3/I8glfkiV+HaIpoelUlAsf9xHJoRGyc zftg13Efh4Y7AYBk7eYMDhp1gfk7x54MFaHuW4gpYrWg48kOzGy+ZENxPZex9baSy45S toSDRLTUwu583nL3DEtxzPdaO7ZbWBTOTEumo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=R/ASMGo3y9Hm3AXRnVw0ZYOzz7yyABsDv2f0Qic9VHx8KQ5qKP9V/hA/nob1uicRRi xVMpa1GqfTiR3xk1GdDnbhn/gU5lFd7yPIvpLB3fGK6tzhPysDjXrIbVZkyoFkZwdqbV w0wF9e6+UOjwaGKJaZbXbTdpVE5JUMxDTNsC0= MIME-Version: 1.0 In-Reply-To: <20100705204812.56cd05ee at haddock.home> References: <20100705121304.6c3d7845@haddock.home> <20100705204812.56cd05ee@haddock.home> Date: Tue, 6 Jul 2010 15:04:14 +0400 Message-ID: Subject: Re: [Lablgtk] Pixbuf column for a tree custom model From: Dmitry Bely To: lablgtk at yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Status: U On Mon, Jul 5, 2010 at 10:48 PM, Maxence Guesdon wrote: > Le Mon, 5 Jul 2010 14:56:43 +0400, > Dmitry Bely a =E9crit : > >> 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 > > Oups, sorry, I read too fast. I made an attempt to modify the example > custom_tree_generic.ml. Here is a modified version where I managed to > display a pixbuf in an additional column, but I get warning about > incompatible types: > =A0(ocaml:3769): GLib-GObject-WARNING **: unable to set property > =A0`pixbuf' of type `GdkPixbuf' from value of type `Caml' OK, thanks. To get rid of this you should use let _ =3D GdkPixbuf.create ~width:1 ~height:1 ();; (* at least one GdkPixbuf should exist or (Gobject.Data.gobject_by_name "GdkPixbuf") will fail *) let col_pb =3D (column_list#add (Gobject.Data.gobject_by_name "GdkPixbuf"= ));; instead of let col_pb =3D (column_list#add Gobject.Data.caml: GdkPixbuf.pixbuf GTree.column);; because pixbuf is Gtk object, not Caml one! That's what I use for conventional list models. But then you should return the proper variant from custom_value method, otherwise you will have Exception: Failure "custom_value returned a value of incompatible type for column 4 of type GdkPixbuf". The question how to return GdkPixbuf is still open... > I may have missed something. > > The custom_tree_generic.ml example works fine on my system (but I had > to make clean lablgtk to prevent some problem with > ml_gtk_tree_....._visible_range). Yes, it works. I was just not patient enough: it needs more than 20 seconds to initialize in my system (Windows). >> (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 >> >> =A0 method custom_value (t:Gobject.g_type) (row:custom_tree) ~column =3D >> =A0 =A0 if column =3D 0 then `CAML (Obj.repr row) >> =A0 =A0 else if column =3D 1 then >> =A0 =A0 =A0 `BOOL (match row with File {finfo=3D{fchecked=3Db}} -> b >> =A0 =A0 =A0 =A0 =A0 =A0 =A0| _ -> false ) >> =A0 =A0 else if column =3D 2 then >> =A0 =A0 =A0 `INT (5+(get_nb row)) >> =A0 =A0 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 >> wrote: >> > Le Mon, 5 Jul 2010 11:02:17 +0400, >> > Dmitry Bely a =E9crit : >> > >> >> 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: >> > =A0http://svn.gna.org/viewcvs/cameleon/trunk/src/utils/gmytree.ml?rev= =3D749&view=3Dmarkup >> > >> > It gives a way to define a tree with a description of the columns. >> > For a use case, you may look at >> > =A0http://svn.gna.org/viewcvs/cameleon/trunk/src/editor/ed_odoc.ml?rev= =3D749&view=3Dmarkup >> > =A0(in class view) >> > >> > The important part of Gmytree is; >> > >> > =A0... >> > =A0let tcols =3D new GTree.column_list in >> > =A0let disp_cols =3D List.map >> > =A0 =A0 =A0(function >> > =A0 =A0 =A0 =A0 =A0`String _ -> >> > =A0 =A0 =A0 =A0 =A0 =A0`String (tcols#add Gobject.Data.string) >> > =A0 =A0 =A0 =A0| `Pixmap _ -> >> > =A0 =A0 =A0 =A0 =A0 =A0`Pixbuf (tcols#add (Gobject.Data.gobject : >> > GdkPixbuf.pixbuf Gobject.data_conv)) ) cols >> > =A0in >> > =A0let (datacol : 'a GTree.column) =3D =A0tcols#add Gobject.Data.caml = in >> > =A0let store =3D GTree.tree_store tcols in >> > =A0let view =3D GTree.view >> > =A0 =A0 =A0~headers_visible: false >> > =A0 =A0 =A0~model: store ~packing: wscroll#add_with_viewport () in >> > =A0let renderer =3D GTree.cell_renderer_text [] in >> > =A0let pix_renderer =3D GTree.cell_renderer_pixbuf [] in >> > =A0let _ =3D >> > =A0 =A0List.iter >> > =A0 =A0 =A0(fun c -> >> > =A0 =A0 =A0 =A0let col =3D >> > =A0 =A0 =A0 =A0 =A0match c with >> > =A0 =A0 =A0 =A0 =A0 =A0`String c -> GTree.view_column () ~renderer: (r= enderer, >> > =A0["text", c]) | `Pixbuf c -> GTree.view_column () ~renderer: >> > =A0(pix_renderer, ["pixbuf",c]) in >> > =A0 =A0 =A0 =A0ignore (view#append_column col) >> > =A0 =A0 =A0) >> > =A0 =A0 =A0disp_cols >> > =A0in >> > =A0... >> > >> > Hope this helps, >> > >> > Maxence >> > >> > >> > _______________________________________________ >> > Lablgtk mailing list >> > Lablgtk@yquem.inria.fr >> > http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk >> > >> >> _______________________________________________ >> Lablgtk mailing list >> Lablgtk@yquem.inria.fr >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk > > _______________________________________________ > Lablgtk mailing list > Lablgtk@yquem.inria.fr > http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk > - Dmitry Bely _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk