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, 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)
        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)?


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

Android: Set Bluetooth Discoverability Unbounded

android bluetooth android-bluetooth connectivity discoverability

I have spent the last couple of days trying to make an app that keeps my Samsung Galaxy S3 mini (Android 2.1.4) discoverable for an "infinite" amount of time. My code looks currently as follows:

Changing Vabinary(Max) back to text<MS SQL “2005”>

python sql sql-server sql-server-2005


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.