Example Code for GUI programming

A simple file browser

#!/usr/bin/env python2.5

import logging
log = logging.getLogger(__name__)
import gtk
import hildon

class FileManager(hildon.Program):
    
    def __init__(self):
        hildon.Program.__init__(self)
        self.main_layout()
        
    def main_layout(self):
        ## Main window
        self._window = hildon.Window()

        self.add_window(self._window)
        self._window.connect("delete_event",self.quit)
        self._window.set_title("FM")
        
        self._filestore = gtk.ListStore(str,str)
        self._filestore.insert(0,["initial","data"])
        self._filestore.insert(1,["initial","data"])
        self._filestore.insert(2,["initial","data"])
        
        self._fileview = gtk.TreeView(self._filestore)
        self._window.add(self._fileview)
        self._fileview.connect("row-activated",self.row_activated)
                
        ## 1. column view
        cell = gtk.CellRendererText() # draw cells as text in this column
        column = gtk.TreeViewColumn("Name")
        column.pack_start(cell,True)
        column.add_attribute(cell,"text",0)
        self._fileview.append_column(column) 
        
        ## 2. column view
        cell = gtk.CellRendererText() # draw cells as text in this column
        column = gtk.TreeViewColumn("Thing")
        column.pack_start(cell,True)
        column.add_attribute(cell,"text",0)
        self._fileview.append_column(column) 
        
    def quit(self,*args):
        log.debug("quitting")
        gtk.main_quit()
    
    def row_activated(self,treeview,path,column,*args):
        log.debug("update %(path)s",vars())
        rowref = gtk.TreeRowReference(self._filestore,path)
        print dir(rowref)
        
    
    def run(self):
        self._window.show_all()
        gtk.main()
            


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    program = FileManager()
    program.run()
Last modified: 2013/07/01 14:42