Reputation: 7067
i have some general questions about using ListView
s and ListStore
s etc..
My program contains a ToDo-list which is a list of Task
-objects. A Task
-object has two attributes: title
and progress
. Now i want to display these ToDo-list in a ListView
showing the title
of the task in the first column and the progress
in the second column.
So i could create a ListView
with two TreeViewColumn
s, each with a CellRendererText
and a data function (set_cell_data_func
) to set the appropriate column-text (title
- or progress
-attribute of the Task
-object).
Of course, the progress
of a task can change over time in another thread. So the progress-cells should be updated to show the new value. But how can i tell the ListView
that the Task
-object has changed and the view should be updated?
And what is the simplest way to keep track of list-changes? For example a new Task
-object is added to the ToDo-list. Do i need to append the new added Task
-object to the ListStore
by myself or is there an easier way? ... because i would have two lists: the original ToDo-list and the ListStore
which seems to be unnecessary.
So what is the best/simplest/easiest way to show my ToDo-list in a ListView
? :-)
Best regards,
Biggie
Upvotes: 0
Views: 403
Reputation: 20492
I would rather use gtk.ListStore as your list model and primary\only "TODO list" data source , once you change values in the model, your list view content should be updated, smth like this:
# get first row of the list store
iter = self.model.get_iter_first()
# set new values to the first column
self.model.set_value(iter, 1, 'new value')
# set new values to columns 0 and 1
self.model.set(iter, 0, 'new 0', 1, 'new 1')
if you need to track changes for your model fields, connect to the "row-changed" signal:
self.model.connect("row-changed", self.on_model_changed, 0)
...
def on_model_changed(self, treemodel, path, iter, user_param1):
print 'model_changed ' + treemodel.get_value(iter, 0)
hope this helps, regards
Upvotes: 1