Delivered-To: lablgtk at yquem.inria.fr Message-ID: <487463C8.8080707 at irisa.fr> Date: Wed, 09 Jul 2008 09:07:52 +0200 From: Sebastien Ferre Organization: IRISA MIME-Version: 1.0 To: lablgtk at yquem.inria.fr Subject: Re: [Lablgtk] Gdk.color GTree.column ? References: <4873715E.7080207 at irisa.fr> <18347849.post at talk.nabble.com> In-Reply-To: <18347849.post at talk.nabble.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Length: 1732 In fact, I need to set arbitrary colors from their RGB code. Is it possible to represent any color as a string ? I only know the common colors as strings (e.g., white, blue, ...). --- Sébastien Eddy2 wrote: > Hi, > > If you *really* want to use Gdk.color I cannot help you. But if you just > want to add colors to your treeview, then I have a solution : you may use a > #RRGGBB string in conjunction with "background" property. Here is a little > working example : > > ----- > let cols = new GTree.column_list > let text = cols#add Gobject.Data.string > let bg_color = cols#add Gobject.Data.string (* We use the well-known string > type *) > let model = GTree.list_store cols > > let cell = GTree.cell_renderer_text [`WEIGHT `BOLD; `FOREGROUND "white"] > > let vcol = > let vcol = GTree.view_column ~title:"Exemple" () in > vcol#pack cell; > vcol#add_attribute cell "text" text; > vcol#add_attribute cell "background" bg_color; > vcol > > let window = GWindow.window > ~title:"Color Demo" > ~position:`CENTER > ~width:200 > ~height:550 () > > let view = > let view = GTree.view ~model ~packing:window#add () in > view#append_column vcol; > view > > let to_string r g b = Printf.sprintf "#%02x%02x%02x" r g b > > let _ = > window#connect#destroy GMain.quit; > for i = 0 to 20 do > let j = 5 * i in > let row = model#append () in > model#set ~row ~column:text (Printf.sprintf "Blue %i%%" j); > model#set ~row ~column:bg_color (to_string 0 0 j) > done; > window#show (); > GMain.main () > ----- > > Hope this helps, > Eddy _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk