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 import gobject
4 import evolution
5 from ctypes import *
6 from pygobject import *
8 class ContactView(hildon.PannableArea):
9   """Widget which shows a list of contacts in a pannable area.
10        
11      Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
12      Released under the Artistic Licence."""
15   # -----------------------------------------------------------------------
16   def __init__(self, contacts):
17     """Constructor. Passed a list of EContacts."""
18     
19     hildon.PannableArea.__init__(self)
20     self.contacts = contacts
21     self.treestore = gtk.ListStore(str, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT)
22     for contact in self.contacts:
23       if not contact.get_name():
24         continue
25         
26       photo = contact.get_property('photo')
27       pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
28       pixbuf = None
29       if pi.contents.data.uri.startswith("image/"):
30         data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
31         pixbuf_loader = gtk.gdk.PixbufLoader()
32         pixbuf_loader.write(data)
33         pixbuf_loader.close()
34         pixbuf = pixbuf_loader.get_pixbuf()
35       elif pi.contents.data.uri.startswith("file://"):
36         filename = pi.contents.data.uri[7:]
37         pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
38             
39       if pixbuf:
40         size = min(pixbuf.get_width(), pixbuf.get_height())
41         pixbuf = pixbuf.subpixbuf(0, 0, size, size).scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
42       self.treestore.append(row = [contact.get_name(), pixbuf, contact])
44     self.treeview = gtk.TreeView(self.treestore)
45     tvcolumn = gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 0)
46     self.treeview.append_column(tvcolumn)
48     cell = gtk.CellRendererPixbuf()
49     cell.set_property('xalign', 1.0)
50     tvcolumn = gtk.TreeViewColumn('Picture', cell, pixbuf = 1)
51     self.treeview.append_column(tvcolumn)
52     
53     self.treeview.set_search_column(0)
54     self.treeview.connect('row-activated', self._activated)
55     self.add(self.treeview)
56     self.set_size_request(600, 380)
57     
58     
59   # -----------------------------------------------------------------------
60   def _activated(self, treeview, path, column):
61     """Used to emit the `contact-activated' signal once a row has been
62        selected."""
63        
64     iter    = treeview.get_model().get_iter(path)
65     contact = treeview.get_model().get_value(iter, 2)
66     self.emit('contact-activated', contact)
69 _contact_activated = gobject.signal_new('contact-activated', ContactView, gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT])

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment