[Lablgtk] GTree.cell_renderer_toggle not activatable by user

Peter Groves pdgroves at gmail.com
Mon Dec 20 02:30:26 CET 2010


For reasons I've never understood, you have to monitor the 'toggled'
events from the cell_renderer and in the monitoring function you have
to 'set' the value in the model to be the opposite of the old value.

Sorry to dump partial code on you, but I don't have time to give you a
good writeup of what happens. Below is the code I have in my app that
does what you're trying to do. This code snippet occurs when I'm
building a GTree.view. Like you, I got it working using guess-and-check
programming (which GTK development requires far too often) so I can't
guarantee you everything in here is really necessary. 

(*************START**************)
(** add the checkbox column to the view *)
let checkBoxModelCol = localModel.checkBoxColumn in
let renderOptionsCheckBox = [(`ACTIVATABLE true); (`ACTIVE true)] in
let rendererCheckBox = GTree.cell_renderer_toggle renderOptionsCheckBox
in 
let toggleMonitor = fun gtkTreePath -> begin
  Log.info "toggle monitor firing";
  let modelIter = treeModel#get_iter gtkTreePath in
  let existingBoolVal = treeModel#get 
    ~row:modelIter 
    ~column:checkBoxModelCol 
  in
  let newBoolVal = (not existingBoolVal) in
  treeModel#set ~row:modelIter ~column:checkBoxModelCol newBoolVal;

  end
in
ignore (rendererCheckBox#connect#toggled ~callback:toggleMonitor);

let viewColumnCheckBox = GTree.view_column
  ~title:"Selected?"
  ~renderer:(rendererCheckBox, [("active",checkBoxModelCol)]) ()
in

viewColumnCheckBox#set_sort_column_id 0;
ignore (treeView#append_column(viewColumnCheckBox));

(*************END**************)


On Mon, 20 Dec 2010 01:10:21 +0100
Adrien <camaradetux at gmail.com> wrote:

> Hi,
> 
> I've been trying to get a treeview with checkboxes that the user can
> toggle but they don't "react" in the interface.
> I'm currently using
>   let renderer_toggle = GTree.cell_renderer_toggle [ `ACTIVATABLE
> true  ] in but in vain.
> 
> I've made a pretty small reproducer (around 30 lines) which I've
> attached.
> 
> Compile with ocamlfind ocamlopt -linkpkg -package lablgtk2
> cell_renderer_toggle_activatable.ml -o
> cell_renderer_toggle_activatable
> 
> I'm not very confortable with treeviews so I may be doing something
> pretty dumb but I really can't see what. Any help is appreciated.
> 
> Thanks. :-)
> 
> --
> 
> Adrien Nader
> 

_______________________________________________
Lablgtk mailing list
Lablgtk at yquem.inria.fr
http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk




More information about the Lablgtk-list mailing list