Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
1 import gtk
2 import hildon
3 from ctypes import *
5 class ContactView(hildon.PannableArea):
6   """Widget which shows a list of contacts in a pannable area.
7        
8      Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
9      Released under the Artistic Licence."""
12   # -----------------------------------------------------------------------
13   def __init__(self, contacts):
14     """Constructor. Passed a list of EContacts."""
15     
16     hildon.PannableArea.__init__(self)
17     self.contacts = contacts
18     self.treestore = gtk.ListStore(str, gtk.gdk.Pixbuf)
19     for contact in self.contacts:
20       if not contact.get_name():
21         continue
22         
23       photo = contact.get_property('photo')
24       pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
25       pixbuf = None
26       if pi.contents.data.uri.startswith("image/"):
27         data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
28         pixbuf_loader = gtk.gdk.PixbufLoader()
29         pixbuf_loader.write(data)
30         pixbuf_loader.close()
31         pixbuf = pixbuf_loader.get_pixbuf()
32       elif pi.contents.data.uri.startswith("file://"):
33         filename = pi.contents.data.uri[7:]
34         pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
35             
36       if pixbuf:
37         size = min(pixbuf.get_width(), pixbuf.get_height())
38         pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
39       self.treestore.append(row = [contact.get_name(), pixbuf])
41     self.treeview = gtk.TreeView(self.treestore)
42     tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 0)
43     self.treeview.append_column(tvcolumn)
45     cell = gtk.CellRendererPixbuf()
46     cell.set_property('xalign', 1.0)
47     tvcolumn = gtk.TreeViewColumn('Picture', cell, pixbuf = 1)
48     self.treeview.append_column(tvcolumn)
50     self.add(self.treeview)
51     self.set_size_request(600, 380)
54 class EContactPhoto_inlined(Structure):
55   _fields_ = [('mime_type', c_char_p),
56               ('length', c_uint),
57               ('data', c_void_p)]
59 class EContactPhoto_data(Union):
60   _fields_ = [('inlined', EContactPhoto_inlined),
61               ('uri', c_char_p)]
63 class EContactPhoto(Structure):
64   _fields_ = [('type', c_int),
65               ('data', EContactPhoto_data)]

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment