4 from pygobject import *
6 class ContactView(hildon.PannableArea):
7 """Widget which shows a list of contacts in a pannable area.
9 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
10 Released under the Artistic Licence."""
13 # -----------------------------------------------------------------------
14 def __init__(self, contacts):
15 """Constructor. Passed a list of EContacts."""
17 hildon.PannableArea.__init__(self)
18 self.contacts = contacts
19 self.treestore = gtk.ListStore(str, gtk.gdk.Pixbuf)
20 for contact in self.contacts:
21 if not contact.get_name():
24 photo = contact.get_property('photo')
25 pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
27 if pi.contents.data.uri.startswith("image/"):
28 data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
29 pixbuf_loader = gtk.gdk.PixbufLoader()
30 pixbuf_loader.write(data)
32 pixbuf = pixbuf_loader.get_pixbuf()
33 elif pi.contents.data.uri.startswith("file://"):
34 filename = pi.contents.data.uri[7:]
35 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
38 size = min(pixbuf.get_width(), pixbuf.get_height())
39 pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
40 self.treestore.append(row = [contact.get_name(), pixbuf])
42 self.treeview = gtk.TreeView(self.treestore)
43 tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 0)
44 self.treeview.append_column(tvcolumn)
46 cell = gtk.CellRendererPixbuf()
47 cell.set_property('xalign', 1.0)
48 tvcolumn = gtk.TreeViewColumn('Picture', cell, pixbuf = 1)
49 self.treeview.append_column(tvcolumn)
51 self.add(self.treeview)
52 self.set_size_request(600, 380)