New Lazy Patch for pypaq (was Re: Lazy Patch for pypaq)

From: James ''Wez'' Weatherall <jnw22.a.t.cam.ac.uk>
Date: Sat May 26 2001 - 16:50:33 EDT

I have finally found a way to support lazy traversal of the directory tree
AND "directory toggles contents" semantics. The new patch is below.

It has the nasty side-effect that the first time you select a directory that
hasn't been opened up before, it gets opened AND selected. It's a little
ugly but otherwise livable-with, I think. :)

Cheers,

James "Wez" Weatherall

--
          "The path to enlightenment is /usr/bin/enlightenment"
Laboratory for Communications Engineering, Cambridge - Tel : 766513
AT&T Labs Cambridge, UK                              - Tel : 343000
---
def createSubTree(item,path):
    mylist=os.listdir(path)
    mylist.sort()
    for each in mylist:
     if os.path.isdir(path+each):
      item_new = GtkTreeItem(each)
                    item_new.set_data('song','%s%s' % (path,each))  # greps
directories
      item.append(item_new)
      item_subtree = GtkTree()
      item_subtree.connect_after('select-child',toggle_song_select)
      item_new.set_subtree(item_subtree)
                    item_new.set_data('expand_handler',
item_new.connect('expand',expand_song_tree))
      item_new.show()
     else:
      item_new = GtkTreeItem(each)
                    songname = path+each
      item_new.set_data('song', songname)
      item.append(item_new)
      item_new.show()
def expand_song_tree(item):
    item.disconnect(item.get_data('expand_handler'))
    item.remove_data('expand_handler')
    createSubTree(item.subtree,item.get_data('song')+'/')
def toggle_song_select(tree,item):
    global temp_song_list
    song = item.get_data('song')
    if song!=None:
        if os.path.isdir(song):
            if item.get_data('expand_handler'):
               # *** This is just here to avoid a hideous Segfault!!!
               item.expand()
               # *** REMOVE AT YOUR PERIL!!!
            for child in item.subtree.children()[:]:
                item.subtree.select_child(child)
        else:
            if song in temp_song_list:
                temp_song_list.remove(song)
            else:
                temp_song_list.append(song)
Received on Sat May 26 13:49:26 2001

This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:38:25 EDT