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 *
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.
9        
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."""
17         
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)
22         
23         accounts = {}
24         _facebook = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-facebook.png')
25         _twitter  = gtk.gdk.pixbuf_new_from_file('/opt/hermes/share/account-twitter.png')
26         _tick     = gtk.icon_theme_get_default().load_icon('widgets_tickmark_list', 48, 0)
27         
28         self.contact_mapped = False
29         mapped_iter = None
30         for key in sorted(self.friends.keys(), cmp = lambda a, b: cmp(a.lower(), b.lower())):
31             friend = self.friends[key]
32             if friend['account'] not in accounts:
33                 accounts[friend['account']] = gtk.gdk.pixbuf_new_from_file("/opt/hermes/share/account-%s.png" % (friend['account']))
34               
35             photo = friend['pic']
36             pixbuf = None
37             if 'contact' in friend:
38                 if friend['contact'] == contact:
39                     pixbuf = _tick
40                     self.contact_mapped = True
41                     mapped_iter = self.treestore.append([accounts[friend['account']], friend['name'], pixbuf, friend])
42                 else:
43                     continue
44             else:
45                 self.treestore.append([accounts[friend['account']], friend['name'], pixbuf, friend])
46         
47         self.treeview = gtk.TreeView(self.treestore)
48         hildon.hildon_gtk_tree_view_set_ui_mode(self.treeview, gtk.HILDON_UI_MODE_EDIT)
49         
50         self.treeview.append_column(gtk.TreeViewColumn('Account', gtk.CellRendererPixbuf(), pixbuf = 0))
51         self.treeview.append_column(gtk.TreeViewColumn('Name', gtk.CellRendererText(), text = 1))
52         
53         cell = gtk.CellRendererPixbuf()
54         cell.set_property('xalign', 1.0)
55         self.treeview.append_column(gtk.TreeViewColumn('Picture', cell, pixbuf = 2))
56         
57         if mapped_iter:
58             path = self.treestore.get_path(mapped_iter)
59             self.treeview.get_selection().select_path(path)
60             self.treeview.scroll_to_cell(path)
61           
62         self.add(self.treeview)
63         self.set_size_request(600, 320)
64       
65     # -----------------------------------------------------------------------
66     def get_selected_friend(self):
67         """Return the selected friend, or `None' if none."""
68     
69         (model, iter) = self.treeview.get_selection().get_selected()
70         if not iter:
71             return None
72              
73         return model.get_value(iter, 3)
76 _account_selected = gobject.signal_new('account-selected', MapContact, gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment