pygtk assertion fail when using a generator to thread and callback to add elements to a treeview due to treeviewiter parent

Using the Generator class from http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html, the following code makes my program fail:

import gtk
import gobject
from GeneratorTask import GeneratorTask

GeneratorTask(self.get_playlist, self.load_playlist).start(playlist_id, model, iter, child)

def get_playlist(self, playlistId=None, treeModel=None, treeIter=None):
    if playlistId is None:
        yield (ten.getRootPlaylist(depth=1), treeModel, treeIter)
    else:
        yield (ten.getPlaylist(playlistId, depth=1), treeModel, treeIter)

def load_playlist(self, playlist, treeModel=None, treeIter=None):
    if treeModel == None:
        treeModel = self.programme

    # Setting treeIter = None prevents assertion fail but 
    # obviously doesn't append the items under the parent
    if len(playlist.find('childPlaylists')):
        for childPlaylist in playlist.find('childPlaylists').findall('playlist'):
            series_iter = treeModel.append(treeIter, [formatTitle(childPlaylist.find('title').text), childPlaylist.find('id').text, True, childPlaylist])
            treeModel.append(series_iter, ['Loading...', None, None, None]) 
    elif len(playlist.find('mediaList')):
        for media in playlist.find('mediaList').findall('media'):
            treeModel.append(treeIter, [media.find('title').text, media.find('id').text, False, media])

The problem seems to be passing the parent ("treeIter" in the code) looses proper reference and is no longer valid by the time the callback is called.

How can I do this properly to ensure new nodes are added under the correct parent, while still maintaining some sort of event-threading (as the ten.getPlaylist functions will block, some threading is needed)?

Answers


Just remembered, that when I was going through lablgtk tutorial, there was a hint that Gtk.tree_iters are short-lived and there was a suggestion to use Gtk.row_references instead. Sorry, this is not python, however You may find it useful: lablgtk:treeview:referring to rows


Need Your Help

Help with Ruby on Rails 5 points ranking algorithm

ruby-on-rails algorithm math ranking

I'm currently in the process of developing a digg-like Ruby on Rails application for my degree's Final Project and I'm stuck in the 5 point ranking algorithm.

Multiple jquery cycle sliders on one page, independent prev/next buttons

jquery cycle jquery-cycle

I've got 12 jQuery cycle sliders on one page. They live inside jquery UI dialog boxes that are fired when a thumbnail is clicked. This all works great, but the issue is that the sliders all share a