On Wed, 15 Feb 2017 23:09:01 +0100, Mike Wey wrote:
I don't see anything wrong at first hand. Do you have a more complete
example to test with?
Ok. Here is the complete example. I simply want to toggle the button in a cell.
import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeIter;
import gtk.TreeViewColumn;
import gtk.TreeView;
import gtk.CellRendererToggle;
import gtk.CellRendererText;
import gtk.TreePath;
import gobject.Value;
class MyWindow: MainWindow
{
this()
{
super("CellRendererToggle Example");
setDefaultSize(200, 200);
auto model = new ListStore([GType.STRING, GType.BOOLEAN, GType.BOOLEAN]);
void addOs(string name, bool toggle, bool radio)
{
TreeIter iter = model.createIter();
model.setValue(iter, 0, name);
model.setValue(iter, 1, new Value(toggle));
model.setValue(iter, 2, new Value(radio));
}
addOs("Debian", false, true);
addOs("Ubuntu", true, false);
addOs("Bodhi linux", false, false);
auto view = new TreeView(model);
auto rendererText = new CellRendererText();
auto columnText = new TreeViewColumn("Text", rendererText, "text", 0);
view.appendColumn(columnText);
auto rendererToggle = new CellRendererToggle();
rendererToggle.addOnToggled((path, renderer)
{onCellToggled(path, renderer, model);});
auto columnToggle = new TreeViewColumn("Toggle", rendererToggle, "active", 1);
view.appendColumn(columnToggle);
add(view);
showAll();
}
void onCellToggled(string path, CellRendererToggle renderer, ListStore model)
{
auto path_ = new TreePath(path);
auto iter = new TreeIter(model, path_);
auto status = model.getValue(iter, 1).getBoolean();
status = (!status);
model.setValue(iter, 1, status);
}
}
void main(string[] args)
{
Main.init(args);
auto myWindow = new MyWindow();
Main.run();
}