comparison frontends/src/primitivus/contact_list.py @ 497:50dd2a0196c0

primitivus: contacts list improvments: - icon and color are used to show availability (away, do not disturb, etc) - status are shown with meta-s (hidden by default)
author Goffi <goffi@goffi.org>
date Tue, 04 Sep 2012 01:15:19 +0200
parents 2a072735e459
children 28f4ce741ae5
comparison
equal deleted inserted replaced
496:024b321c1aa2 497:50dd2a0196c0
31 def __init__(self, host, CM, on_click=None, on_change=None, user_data=None): 31 def __init__(self, host, CM, on_click=None, on_change=None, user_data=None):
32 self.host = host 32 self.host = host
33 self.selected = None 33 self.selected = None
34 self.groups={} 34 self.groups={}
35 self.alert_jid=set() 35 self.alert_jid=set()
36 self.show_status = False
36 37
37 #we now build the widget 38 #we now build the widget
38 self.frame = urwid.Frame(self.__buildList()) 39 self.frame = urwid.Frame(self.__buildList())
39 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts"))) 40 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts")))
40 urwid.WidgetWrap.__init__(self, self.main_widget) 41 urwid.WidgetWrap.__init__(self, self.main_widget)
42 urwid.connect_signal(self, 'click', on_click, user_data) 43 urwid.connect_signal(self, 'click', on_click, user_data)
43 if on_change: 44 if on_change:
44 urwid.connect_signal(self, 'change', on_change, user_data) 45 urwid.connect_signal(self, 'change', on_change, user_data)
45 QuickContactList.__init__(self, CM) 46 QuickContactList.__init__(self, CM)
46 47
48 def keypress(self, size, key):
49 if key == "meta s": #user wants to (un)hide contacts' statuses
50 self.show_status = not self.show_status
51 self.frame.body = self.__buildList()
52 self.host.redraw()
53 return super(ContactList, self).keypress(size, key)
54
47 def __contains__(self, jid): 55 def __contains__(self, jid):
48 for group in self.groups: 56 for group in self.groups:
49 if jid.short in self.groups[group][1]: 57 if jid.short in self.groups[group][1]:
50 return True 58 return True
51 return False 59 return False
91 contacts.sort() 99 contacts.sort()
92 for contact in contacts: 100 for contact in contacts:
93 jid=JID(contact) 101 jid=JID(contact)
94 name = self.CM.getAttr(jid,'name') 102 name = self.CM.getAttr(jid,'name')
95 nick = self.CM.getAttr(jid,'nick') 103 nick = self.CM.getAttr(jid,'nick')
96 display = nick or name or jid.node or jid.short 104 status = self.CM.getAttr(jid, 'status')
105 show = self.CM.getAttr(jid, 'show')
106 show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
107 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short)
108 display = [ show_icon + " " , contact_disp]
109 display_selected = [ show_icon + " " , "[ %s ]" % contact_disp[1]]
110 if self.show_status:
111 status_disp = ('status',"\n" + status) if status else ""
112 display.append(status_disp)
113 display_selected.append(status_disp)
97 header = '(*) ' if contact in self.alert_jid else '' 114 header = '(*) ' if contact in self.alert_jid else ''
98 widget = sat_widgets.SelectableText(('alert' if contact in self.alert_jid else 'default',display), 115 widget = sat_widgets.SelectableText(display,
99 selected = contact==self.selected, header=header) 116 selected_text = display_selected,
117 selected = contact==self.selected,
118 header=header)
100 widget.data = contact 119 widget.data = contact
101 content.append(widget) 120 content.append(widget)
102 urwid.connect_signal(widget, 'change', self.__contactClicked) 121 urwid.connect_signal(widget, 'change', self.__contactClicked)
103 122
104 def __buildList(self): 123 def __buildList(self):