Reputation: 117
So I finally got around to understand how PyGTK really works and I'm working on a simple SQLite manager app.
To show the result of a query I'm using a gtk.ScrolledWindow with a gtk.TreeView. I've managed to add and even change the values in the ListStore object as I need, what I can't do is change the model of the ListStore object.
For example in one query I may have a result of two columns:
self.query_results = gtk.ListStore(str,str)
self.query_results.append(["1"],["John Doe"])
And in another one I may get more columns:
self.query_results = gtk.ListStore(str,str,str,str)
self.query_results.append(["20"],["Jane"],["[email protected]"],["password"])
I know I can use stuff like
self.query_results = gtk.ListStore(*[str]*len(columns))
But aparently gtk.ListStore cannot have it's model changed after being created, so how would I update this query table? Do I need to destroy the Treeview and draw it again everytime I run a different query?
Thanks and this is my first question on StackOverflow so excuse any mistakes/posting guidelines I didn't follow.
Upvotes: 0
Views: 2088
Reputation: 9673
You can use gtk.TreeView.set_model
to assign a new model to a TreeView. So you can generate a new model for each set of results, and then set the TreeView to show that model.
Upvotes: 6