View Single Post
yerga's Avatar
Posts: 696 | Thanked: 1,012 times | Joined on Mar 2006 @ Asturies, Spain
#4
A example in Python code:

Code:
import hildon, gobject, gtk

class UI:

    def __init__(self):
        self.window = hildon.Window()
        self.window.connect("destroy", gtk.main_quit)

        parea = hildon.PannableArea()

        # gtk.HILDON_UI_MODE_NORMAL -> not selection in the treeview
        # gtk.HILDON_UI_MODE_EDIT -> selection in the treeview
        treeview = hildon.GtkTreeView(gtk.HILDON_UI_MODE_NORMAL)

        model = self.create_model()
        treeview.set_model(model)

        self.add_columns_to_treeview(treeview)

        parea.add(treeview)

        self.window.add(parea)
        self.window.show_all()

    def create_model(self):
        lstore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)

        data = ["Blue color", "Red color"]
        colors = ["blue.png", "red.png"]

        iconlist = []
        for i in range(len(colors))*10:
            iconlist.append([data[i], colors[i]])

        for item in iconlist:
            liter = lstore.append()
            lstore.set(liter, 1, item[0], 0, self.set_pix(item[1]))

        return lstore

    def set_pix(self, filename):
        pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
        return pixbuf

    def add_columns_to_treeview(self, treeview):
        #Column 0 for the treeview
        renderer = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn()
        column.pack_start(renderer, True)
        column.add_attribute(renderer, "pixbuf", 0)
        treeview.append_column(column)

        #Column 1 for the treeview
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn('title', renderer, text=1)
        column.set_property("expand", True)
        treeview.append_column(column)


if __name__ == "__main__":
    UI()
    gtk.main()
Put the blue and red squares in the same directory where the script and call them blue.png and red.png (or you can change the script to use your own images and data).

If you want put the images in a HildonTouchSelector, the code is a bit different than in the Treeview from the example. If you need it ask for it ;-)
Attached Images
   
__________________
Daniel Martín Yerga
maemo.org profile
Twitter
 

The Following 8 Users Say Thank You to yerga For This Useful Post: