import Tkinter, ConfigParser, string, time
cp = ConfigParser.ConfigParser ()
cp.read("example.dpk")

def display_name(s): return s
def display_comment(s): return s
def display_bitrate(s): return "%d mbps"%(int(s)/1000000)
def display_start(s):
    delay = int(s) - time.time()
    if delay<0: suffix=" ago"
    else: suffix=""
    delay=abs(delay)
    ddd=[ (60,"s",1), (60*60,"m",60), (60*60*24,"h",60*60),
          (1000000000, "d",60*60*24) ]
    for maxdelay,unit,divisor in ddd:
        if delay<maxdelay:
            return "%d%s%s"%(delay/divisor,unit,suffix)

class Flowtable(Tkinter.Frame):
    def __init__(self,root):
        Tkinter.Frame.__init__(self,root)
        self.root=root
        self.columns = ["DL","Name","Comment","Bitrate", "Start"]
        self.labels = {}
        for c in self.columns:
            self.labels[c] = Tkinter.Label(self.root,text=c)
            self.labels[c].grid(column=self.columns.index(c),row=0)
        self.rowcount = 0
        self.rows = {}
    def add(self,**row):
        self.rowcount += 1
        self.rows[self.rowcount]={}
        for c in self.columns:
            lc=string.lower(c)
            if c=="DL":
                self.rows[self.rowcount][c] = Tkinter.Checkbutton ()
                self.rows[self.rowcount][c].grid(column=self.columns.index(c),
                                                 row=self.rowcount)
                continue
            self.rows[self.rowcount][c] = Tkinter.Label(self.root,
                                                        text=globals()\
                                                        ["display_%s"%lc]\
                                                        (row[lc]))
            self.rows[self.rowcount][c].grid(column=self.columns.index(c),
                                             row=self.rowcount)
            
        
r=Tkinter.Tk()
ft=Flowtable(r)
for flowname in cp.sections():
    parms={}
    for p in cp.options(flowname):
        parms[p]=cp.get(flowname,p)
    ft.add(name=flowname,**parms)
