[pygtk] gtk.GenericTreeModel, tricky one...
John Stowers
john.stowers.lists at gmail.com
Tue Jun 3 06:07:48 WST 2008
On Mon, 2008-06-02 at 13:04 +0200, Markus W. Barth wrote:
> I am working on a package that provides some models for use with SQLObject
> (see http://www.sqlobject.org for further details), thus creating database
> frontends is made a lot easier.
Cool. I did something similar with a wrapper around sqlite. See:
http://www.johnstowers.co.nz/blog/index.php/2007/12/06/the-big-move/
I cant offer too much advice on your specific problem, but you may find
something useful in my code. TBH The ordeal was quite painful, and I
have forgotten much of what I learnt while implementing it.
John
>
> Internally, the model uses a python list of SQLObject instances.
>
> Now I have bumped into the following:
>
> As long as I use _one_ instance of the model (SqlListView), there are no
> problems, but as soon as I use two instances of the model, strange behaviour
> starts to happen, apart from getting the following assertion error.
>
> (main.py:16261): CRITICAL **: pygtk_generic_tree_model_get_value: assertion
> `VALID_ITER(iter, tree_model)' failed
> (yes, self.row_deleted() is called for every row that is deleted)
>
> But things don't stop here. The module contains two classes of models:
>
> * SqlListModel
> * SlaveListModel
>
> Both are very similar, the only difference is the way how they retrieve their
> data. For this reason I created a base class BaseListModel and derived both
> SqlListModel and SlaveListModel.
>
> The base class has an attribute "select_list", which holds the list with the
> SQLObject instances.
>
> Now if I use one instance of SqlListModel (for showing the data from one
> table) and one instance of SlaveListModel (for showing data from a 1:n
> relation), in the SlaveListModel appears data from the SqlListModel.
>
> Just to give it a try, I moved teh attribute "select_list" to the subclasses
> (SqlListModel and SlaveListModel), and the problem disappeared - as long as I
> only use one instance of each.
>
> I suspect, that the problem arises when any instance clears rows from the list
> to populate it with new rows. So I simply added
>
> self.select_list = []
>
> at the end of the method that evacuates the list and things seem to work
> (until now).
>
> The whole method is:
>
> def evacuate(self):
> num_items = len(self.select_list)
> for i in range(num_items):
> last_path = num_items-(i+1)
> my_iter = self.get_iter(last_path)
> row = self.get_row(my_iter)
> self.select_list.remove(row)
> self.row_deleted(last_path)
> self.select_list = [] #<=UGLY
>
> However I think that the problem seems to point to a (heavy) leakage of iters,
> and I really do not understand why this happens. Anyone any idea?
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
More information about the pygtk
mailing list