View Single Post
Posts: 7 | Thanked: 0 times | Joined on May 2008
#10
Originally Posted by yerga View Post
A example in Python code:

(code snippet removed, see above)

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 ;-)
Thanks for your example. I'm coding a remote controller app for Squeezebox with python, and I need a window that can display the current playlist. I was prototyping the layout, and the one that I thought to use is a list with

- note symbol on the left showing the currently played track
- track name + "\n" + artist
- track duration

I can show note symbol and track name/artist, but not duration. On the column showing the duration I was get a copy of track name/artist column's content. Why this happens? What I'm doing wrong?

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)

        self.add_columns_to_treeview(treeview)

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


        parea.add(treeview)

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

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

        lstore.append([None, "6. Arie. Buss und Reu\n<small>Andreas Scholl</small>", "3:23"])
        lstore.append([self.set_pix("note.png"), "35. Arie. Geduld, Geduld!\n<small>Werner Gura</small>", "2:49"])

        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, False)
        column.add_attribute(renderer, "pixbuf", 0)
        column.set_min_width(40)
        treeview.append_column(column)

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

        #Column 2 for the treeview
        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("times", renderer, markup=1)
        treeview.append_column(column)

if __name__ == "__main__":
    UI()
    gtk.main()
Screenshot below:
Name:  screenshot.jpg
Views: 944
Size:  19.7 KB

And here the note.png used by the code:
Name:  note.png
Views: 892
Size:  508 Bytes