4 from pygobject import *
6 class MapContact(hildon.PannableArea):
7 """Widget which shows a list of friends from various feeds and allows
8 the mapping to a particular contact.
10 Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
11 Released under the Artistic Licence."""
14 # -----------------------------------------------------------------------
15 def __init__(self, friends, contact):
16 """Constructor. Passed a list of `friends' and the contact we're mapping."""
18 hildon.PannableArea.__init__(self)
19 self.friends = friends
20 self.contact = contact
21 self.treestore = gtk.ListStore(gtk.gdk.Pixbuf, str, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT)
24 _tick = gtk.icon_theme_get_default().load_icon('widgets_tickmark_list', 48, 0)
26 self.contact_mapped = False
28 for key in sorted(self.friends.keys(), cmp = lambda a, b: cmp(a.lower(), b.lower())):
29 friend = self.friends[key]
30 if friend.get_source() not in accounts:
32 accounts[friend.get_source()] = gtk.gdk.pixbuf_new_from_file("/opt/hermes/share/account-%s.png" % (friend.get_source()))
33 except glib.GError, e:
34 accounts[friend.get_source()] = None
35 print "Couldn't find icon:", e.message
38 if friend.get_contact() is not None:
39 if friend.get_contact() == contact:
41 self.contact_mapped = True
42 mapped_iter = self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend])
46 self.treestore.append([accounts[friend.get_source()], friend.get_name(), pixbuf, friend])
48 self.treeview = gtk.TreeView(self.treestore)
49 hildon.hildon_gtk_tree_view_set_ui_mode(self.treeview, gtk.HILDON_UI_MODE_EDIT)
51 self.treeview.append_column(gtk.TreeViewColumn('Account', gtk.CellRendererPixbuf(), pixbuf = 0))
52 self.treeview.append_column(gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 1))
54 cell = gtk.CellRendererPixbuf()
55 cell.set_property('xalign', 1.0)
56 self.treeview.append_column(gtk.TreeViewColumn('Picture', cell, pixbuf = 2))
59 path = self.treestore.get_path(mapped_iter)
60 self.treeview.get_selection().select_path(path)
61 self.treeview.scroll_to_cell(path)
63 self.treeview.get_selection().unselect_all()
65 self.add(self.treeview)
66 self.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN)
69 # -----------------------------------------------------------------------
70 def get_selected_friend(self):
71 """Return the selected friend, or `None' if none."""
73 (model, iter) = self.treeview.get_selection().get_selected()
77 return model.get_value(iter, 3)
80 _account_selected = gobject.signal_new('account-selected', MapContact, gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])