On Sat, 25 Feb 2017 16:30:40 +0100, Mike Wey wrote:
You can use TreeModel.getIterFirst to get an TreeIter pointing to the
first row.
[...]
Thanks.. How about resetting the progress bar. Might there be a better approach to iterate through rows of the model.
import gtk.Main;
import gtk.MainWindow;
import gtk.Box;
import gtk.ListStore;
import gtk.TreeIter;
import gtk.TreeView;
import gtk.CellRendererText;
import gtk.TreeViewColumn;
import gtk.CellRendererProgress;
import gtk.CellRendererToggle;
import gobject.Value;
import glib.Timeout;
class MyWindow: MainWindow
{
ListStore model;
TreeIter iter;
this()
{
super("Cell renderer demo");
setDefaultSize(200, 200);
model = new ListStore([GType.STRING, GType.INT, GType.BOOLEAN]);
void addTask(string name, int percent, bool inverted)
{
model.append(iter);
model.setValue(iter, 0, name);
model.setValue(iter, 1, percent);
model.setValue(iter, 2, new Value(inverted));
}
addTask("Make soup", 0, false);
addTask("Write program", 0, false);
addTask("Go to grocery", 0, false);
model.getIterFirst(iter);
auto view = new TreeView(model);
auto rendererText = new CellRendererText();
auto columnText = new TreeViewColumn("Text", rendererText, "text", 0);
view.appendColumn(columnText);
auto rendererProgress = new CellRendererProgress();
auto columnProgress = new TreeViewColumn("Progress", rendererProgress, "value", 1);
columnProgress.addAttribute(rendererProgress, "inverted", 2);
view.appendColumn(columnProgress);
auto rendererToggle = new CellRendererToggle();
auto columnToggle = new TreeViewColumn("Inverted", rendererToggle, "active", 2);
view.appendColumn(columnToggle);
auto timeout = new Timeout(50, &onTimeout, false);
add(view);
showAll();
}
bool onTimeout()
{
import std.stdio: writeln;
auto newValue = model.getValueInt(iter, 1) + 1;
if (newValue > 100)
{
model.iterNext(iter);
if (iter.stamp == 0)
{
resetModel();
}
newValue = 1;
}
// writeln(newValue);
model.setValue(iter, 1, newValue);
return true;
}
void resetModel()
{
model.getIterFirst(iter);
while (iter.stamp > 0)
{
model.setValue(iter, 1, 0);
model.iterNext(iter);
}
model.getIterFirst(iter);
}
}
void main(string[] args)
{
Main.init(args);
auto myWindow = new MyWindow();
Main.run();
}