You are not logged in.

#1 2010-03-06 15:53:41

robrene
Member
Registered: 2009-04-16
Posts: 168

[python] [gtk] Trouble with gtk.TreeStore

Hey all.

I'm trying to list all files in a directory structure using a gtk TreeView. Any subdirectory should appear as a header for the view.

For example, if this is the directory structure:

/home/user/Music/Classics
/home/user/Music/Club
/home/user/Music/Club/House
/home/user/Music/Club/Trance
/home/user/Music/Pop
/home/user/Music/Rock

...then I want the view to look like this:

> /home/user/Music/Classics
    ♫ file1.mp3
    ♫ file2.mp3
    ...
> /home/user/Music/Club
    ♫ file1.mp3
    ♫ file2.mp3
    ...
> /home/user/Music/Club/House
    ♫ file1.mp3
    ♫ file2.mp3
    ...
> /home/user/Music/Club/Trance
    ♫ file1.mp3
    ♫ file2.mp3
    ...
> /home/user/Music/Pop
    ♫ file1.mp3
    ♫ file2.mp3
    ...
> /home/user/Music/Rock
    ♫ file1.mp3
    ♫ file2.mp3
    ...

I hope this is explained well enough. Anyway, I've been following a tutorial for gtk + C#, modifying it for python as I went along. The part on using TreeIters is very different than anything I can find in the python library though... My code that populates the TreeStore is below, with the two problematic lines commented out. Can someone tell me what I'm doing wrong and what I should be doing in order to archieve the above effect?

    def update_view(self):

        # Update the treeview
        assert not self.location == None
        model = self.tree.get_model()

        model.clear()

        for (dirpath, dirnames, filenames) in sorted(os.walk(self.location)):

            #iter = model.get_iter_from_string(dirpath)

            for file in sorted(filenames):
            
                (type, encoding) = mimetypes.guess_type(file)
                if type not in application.supported_mimetypes:
                    continue

                icon_theme = gtk.icon_theme_get_default()
                icon_name = type.replace("/", "-")

                if icon_theme.has_icon(icon_name):
                    icon = icon_theme.load_icon(icon_name, size=16, flags=0)
                else:
                    icon = icon_theme.load_icon("audio-x-generic", size=16, flags=0)

                #model.append(iter, [icon, file])

smile neutral sad big_smile yikes wink hmm tongue lol mad roll cool

Offline

Board footer

Powered by FluxBB