Mercurial > libervia-backend
comparison frontends/src/primitivus/contact_list.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | 84a6e83157c2 |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
35 self.selected = None | 35 self.selected = None |
36 self.groups={} | 36 self.groups={} |
37 self.alert_jid=set() | 37 self.alert_jid=set() |
38 self.show_status = False | 38 self.show_status = False |
39 self.show_disconnected = False | 39 self.show_disconnected = False |
40 | 40 |
41 #we now build the widget | 41 #we now build the widget |
42 self.frame = urwid.Frame(self.__buildList()) | 42 self.frame = urwid.Frame(self.__buildList()) |
43 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts"))) | 43 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts"))) |
44 urwid.WidgetWrap.__init__(self, self.main_widget) | 44 urwid.WidgetWrap.__init__(self, self.main_widget) |
45 if on_click: | 45 if on_click: |
63 self.show_status = not self.show_status | 63 self.show_status = not self.show_status |
64 self.update() | 64 self.update() |
65 elif key == "meta d": #user wants to (un)hide disconnected contacts | 65 elif key == "meta d": #user wants to (un)hide disconnected contacts |
66 self.show_disconnected = not self.show_disconnected | 66 self.show_disconnected = not self.show_disconnected |
67 self.update() | 67 self.update() |
68 return super(ContactList, self).keypress(size, key) | 68 return super(ContactList, self).keypress(size, key) |
69 | 69 |
70 def __contains__(self, jid): | 70 def __contains__(self, jid): |
71 for group in self.groups: | 71 for group in self.groups: |
72 if jid.short in self.groups[group][1]: | 72 if jid.short in self.groups[group][1]: |
73 return True | 73 return True |
74 return False | 74 return False |
114 def __buildContact(self, content, param_contacts): | 114 def __buildContact(self, content, param_contacts): |
115 """Add contact representation in widget list | 115 """Add contact representation in widget list |
116 @param content: widget list, e.g. SimpleListWalker | 116 @param content: widget list, e.g. SimpleListWalker |
117 @param contacts: list of JID""" | 117 @param contacts: list of JID""" |
118 contacts = list(param_contacts) | 118 contacts = list(param_contacts) |
119 | 119 |
120 widgets = [] #list of built widgets | 120 widgets = [] #list of built widgets |
121 | 121 |
122 for contact in contacts: | 122 for contact in contacts: |
123 if contact.startswith(const_PRIVATE_PREFIX): | 123 if contact.startswith(const_PRIVATE_PREFIX): |
124 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) | 124 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact)) |
125 show_icon = '' | 125 show_icon = '' |
126 status = '' | 126 status = '' |
146 selected = contact==self.selected, | 146 selected = contact==self.selected, |
147 header=header) | 147 header=header) |
148 widget.data = contact | 148 widget.data = contact |
149 widget.comp = contact_disp[1].lower() #value to use for sorting | 149 widget.comp = contact_disp[1].lower() #value to use for sorting |
150 widgets.append(widget) | 150 widgets.append(widget) |
151 | 151 |
152 widgets.sort(key=lambda widget: widget.comp) | 152 widgets.sort(key=lambda widget: widget.comp) |
153 | 153 |
154 for widget in widgets: | 154 for widget in widgets: |
155 content.append(widget) | 155 content.append(widget) |
156 urwid.connect_signal(widget, 'change', self.__contactClicked) | 156 urwid.connect_signal(widget, 'change', self.__contactClicked) |
158 def __buildSpecials(self, content): | 158 def __buildSpecials(self, content): |
159 """Build the special entities""" | 159 """Build the special entities""" |
160 specials = self.specials.keys() | 160 specials = self.specials.keys() |
161 specials.sort() | 161 specials.sort() |
162 for special in specials: | 162 for special in specials: |
163 jid=JID(special) | 163 jid=JID(special) |
164 name = self.getCache(jid, 'name') | 164 name = self.getCache(jid, 'name') |
165 nick = self.getCache(jid, 'nick') | 165 nick = self.getCache(jid, 'nick') |
166 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) | 166 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) |
167 display = [ " " , special_disp] | 167 display = [ " " , special_disp] |
168 header = '(*) ' if special in self.alert_jid else '' | 168 header = '(*) ' if special in self.alert_jid else '' |
174 urwid.connect_signal(widget, 'change', self.__contactClicked) | 174 urwid.connect_signal(widget, 'change', self.__contactClicked) |
175 | 175 |
176 def __buildList(self): | 176 def __buildList(self): |
177 """Build the main contact list widget""" | 177 """Build the main contact list widget""" |
178 content = urwid.SimpleListWalker([]) | 178 content = urwid.SimpleListWalker([]) |
179 | 179 |
180 self.__buildSpecials(content) | 180 self.__buildSpecials(content) |
181 if self.specials: | 181 if self.specials: |
182 content.append(urwid.Divider('=')) | 182 content.append(urwid.Divider('=')) |
183 | 183 |
184 group_keys = self.groups.keys() | 184 group_keys = self.groups.keys() |
203 | 203 |
204 | 204 |
205 def getContact(self): | 205 def getContact(self): |
206 """Return contact currently selected""" | 206 """Return contact currently selected""" |
207 return self.selected | 207 return self.selected |
208 | 208 |
209 def clearContacts(self): | 209 def clearContacts(self): |
210 """clear all the contact list""" | 210 """clear all the contact list""" |
211 QuickContactList.clearContacts(self) | 211 QuickContactList.clearContacts(self) |
212 self.groups={} | 212 self.groups={} |
213 self.selected = None | 213 self.selected = None |
236 if jid.short not in contacts: | 236 if jid.short not in contacts: |
237 contacts.append(jid.short) | 237 contacts.append(jid.short) |
238 contacts.sort() | 238 contacts.sort() |
239 self.list_wid.changeValues(contacts) | 239 self.list_wid.changeValues(contacts) |
240 self._emit('change')""" | 240 self._emit('change')""" |
241 | 241 |
242 def remove(self, jid): | 242 def remove(self, jid): |
243 """remove a contact from the list""" | 243 """remove a contact from the list""" |
244 QuickContactList.remove(self, jid) | 244 QuickContactList.remove(self, jid) |
245 groups_to_remove = [] | 245 groups_to_remove = [] |
246 for group in self.groups: | 246 for group in self.groups: |
250 if not len(contacts): | 250 if not len(contacts): |
251 groups_to_remove.append(group) | 251 groups_to_remove.append(group) |
252 for group in groups_to_remove: | 252 for group in groups_to_remove: |
253 del self.groups[group] | 253 del self.groups[group] |
254 self.update() | 254 self.update() |
255 | 255 |
256 def add(self, jid, param_groups=[None]): | 256 def add(self, jid, param_groups=[None]): |
257 """add a contact to the list""" | 257 """add a contact to the list""" |
258 self.replace(jid,param_groups) | 258 self.replace(jid,param_groups) |
259 | 259 |
260 def setSpecial(self, special_jid, special_type): | 260 def setSpecial(self, special_jid, special_type): |