I'm writing a script to scan a folder for files, retrieve the version 
information via Win32 API calls, and display the results in a sortable 
list.  I've gotten partway into the process (reading the directory and 
filling in the TreeView with names and blank fields) but the filenames 
never appear on my screen... the rows are there, but they are entirely 
blank.

But if I add a hack to the code to retrieve the value of a column and 
print it, it appears in the console window where I started the script 
(much as I expect it to).  So the filename is there, but it's not appearing.

I've missed something elementary, I know, but I don't know what it is, 
and the examples I've been looking at are not terribly clear.  Perhaps 
someone can tell me what I've done wrong?

(I'm testing on my Ubuntu system at this stage, but without the Win32 
calls, it should still work.)

---------------------------------------

#!/usr/bin/env python

import os, sys, stat

import pygtk
pygtk.require('2.0')
import gtk

verinfoflds = [
    "CompanyName",
    "FileDescription",
    "FileVersion",
    "InternalName",
    "LegalCopyright",
    "LegalTrademarks",
    "OriginalFilename",
    "PrivateBuild",
    "ProductName",
    "ProductVersion",
    "SpecialBuild",
    "Comments",
]

allflds = [ "FileName", ] + verinfoflds

def loadfiles(model):
    fnames = os.listdir(".")
    for fn in fnames:
        if not stat.S_ISDIR(os.stat(fn)[stat.ST_MODE]):
            # get the info
            # stubbed for testing
            row = [ fn ] + ([ "" ] * len(verinfoflds))
            iter = model.append(row)

class MainWindow:

    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("List Programs")
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(2)
        types = tuple([ 'gchararray' ] * len(allflds))
        self.programmodel = gtk.ListStore(*types)
        self.programview = gtk.TreeView(model = self.programmodel)
        self.window.add(self.programview)
        self.programview.set_headers_clickable(True)
        self.programview.set_reorderable(True)
        for i in range(len(allflds)):
            
self.programview.append_column(gtk.TreeViewColumn(allflds[i], 
gtk.CellRendererText()))
        loadfiles(self.programmodel)
        self.programview.show()
        self.window.show()

if __name__ == "__main__":
    hello = MainWindow()
    gtk.main()


_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to