Mercurial > libervia-backend
comparison frontends/src/wix/contact_list.py @ 1011:5a6354ff468c
wix: use of new logging system
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 05 May 2014 20:12:21 +0200 |
parents | 6f1e03068b5f |
children | 0a9986452bba |
comparison
equal
deleted
inserted
replaced
1010:73a0b7f94674 | 1011:5a6354ff468c |
---|---|
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 import wx | 21 import wx |
22 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList | 22 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList |
23 from sat_frontends.wix.constants import Const | 23 from sat_frontends.wix.constants import Const |
24 from logging import debug, info, error | 24 from sat.core.log import getLogger |
25 log = getLogger(__name__) | |
25 from cgi import escape | 26 from cgi import escape |
26 from sat.tools.jid import JID | 27 from sat.tools.jid import JID |
27 from os.path import join | 28 from os.path import join |
28 | 29 |
29 | 30 |
39 def __init__(self, parent, host, type_="JID"): | 40 def __init__(self, parent, host, type_="JID"): |
40 """init the contact list | 41 """init the contact list |
41 @param parent: WxWidgets parent of the widget | 42 @param parent: WxWidgets parent of the widget |
42 @param host: wix main app class | 43 @param host: wix main app class |
43 @param type_: type of contact list: "JID" for the usual big jid contact list | 44 @param type_: type of contact list: "JID" for the usual big jid contact list |
44 "CUSTOM" for a customized contact list (self.__presentItem must then be overrided) | 45 "CUSTOM" for a customized contact list (self._presentItem must then be overrided) |
45 """ | 46 """ |
46 wx.SimpleHtmlListBox.__init__(self, parent, -1) | 47 wx.SimpleHtmlListBox.__init__(self, parent, -1) |
47 QuickContactList.__init__(self) | 48 QuickContactList.__init__(self) |
48 self.host = host | 49 self.host = host |
49 self.type = type_ | 50 self.type = type_ |
56 def __contains__(self, jid): | 57 def __contains__(self, jid): |
57 return bool(self.__find_idx(jid)) | 58 return bool(self.__find_idx(jid)) |
58 | 59 |
59 def __typeSwitch(self): | 60 def __typeSwitch(self): |
60 if self.type == "JID": | 61 if self.type == "JID": |
61 self.__presentItem = self.__presentItemJID | 62 self._presentItem = self._presentItemJID |
62 elif type_ != "CUSTOM": | 63 elif self.type != "CUSTOM": |
63 self.__presentItem = self.__presentItemDefault | 64 self._presentItem = self._presentItemDefault |
64 | 65 |
65 def __find_idx(self, entity): | 66 def __find_idx(self, entity): |
66 """Find indexes of given contact (or groups) in contact list, manage jid | 67 """Find indexes of given contact (or groups) in contact list, manage jid |
67 @return: list of indexes""" | 68 @return: list of indexes""" |
68 result=[] | 69 result=[] |
82 @param groups (list): list of groups or None to ignore the groups membership. | 83 @param groups (list): list of groups or None to ignore the groups membership. |
83 @param attributes (dict) | 84 @param attributes (dict) |
84 | 85 |
85 XXX: None value for 'groups' has a different meaning than [None] which is for the default group. | 86 XXX: None value for 'groups' has a different meaning than [None] which is for the default group. |
86 """ | 87 """ |
87 debug(_("update %s") % contact) | 88 log.debug(_("update %s") % contact) |
88 if not self.__find_idx(contact): | 89 if not self.__find_idx(contact): |
89 self.add(contact, groups) | 90 self.add(contact, groups) |
90 else: | 91 else: |
91 for i in self.__find_idx(contact): | 92 for i in self.__find_idx(contact): |
92 _present = self.__presentItem(contact) | 93 _present = self._presentItem(contact) |
93 if _present != None: | 94 if _present != None: |
94 self.SetString(i, _present) | 95 self.SetString(i, _present) |
95 | 96 |
96 def __eraseGroup(self, group): | 97 def __eraseGroup(self, group): |
97 """Erase all contacts in group | 98 """Erase all contacts in group |
104 erased = True | 105 erased = True |
105 self.Delete(idx+1) | 106 self.Delete(idx+1) |
106 return erased | 107 return erased |
107 | 108 |
108 | 109 |
109 def __presentGroup(self, group): | 110 def _presentGroup(self, group): |
110 """Make a nice presentation for the contact groups""" | 111 """Make a nice presentation for the contact groups""" |
111 html = u"""-- [%s] --""" % group | 112 html = u"""-- [%s] --""" % group |
112 | 113 |
113 return html | 114 return html |
114 | 115 |
115 def __presentItemDefault(self, contact): | 116 def _presentItemDefault(self, contact): |
116 """Make a basic presentation of string contacts in the list.""" | 117 """Make a basic presentation of string contacts in the list.""" |
117 return contact | 118 return contact |
118 | 119 |
119 def __presentItemJID(self, jid): | 120 def _presentItemJID(self, jid): |
120 """Make a nice presentation of the contact in the list for JID contacts.""" | 121 """Make a nice presentation of the contact in the list for JID contacts.""" |
121 name = self.getCache(jid,'name') | 122 name = self.getCache(jid,'name') |
122 nick = self.getCache(jid,'nick') | 123 nick = self.getCache(jid,'nick') |
123 _show = self.getCache(jid,'show') | 124 _show = self.getCache(jid,'show') |
124 if _show == None or _show == 'unavailable': | 125 if _show == None or _show == 'unavailable': |
156 """Clear all the contact list""" | 157 """Clear all the contact list""" |
157 self.Clear() | 158 self.Clear() |
158 | 159 |
159 def add(self, contact, groups = None): | 160 def add(self, contact, groups = None): |
160 """add a contact to the list""" | 161 """add a contact to the list""" |
161 debug (_("adding %s"),contact) | 162 log.debug (_("adding %s"),contact) |
162 if not groups: | 163 if not groups: |
163 _present = self.__presentItem(contact) | 164 _present = self._presentItem(contact) |
164 if _present: | 165 if _present: |
165 idx = self.Insert(_present, 0, contact) | 166 idx = self.Insert(_present, 0, contact) |
166 else: | 167 else: |
167 for group in groups: | 168 for group in groups: |
168 indexes = self.__find_idx(group) | 169 indexes = self.__find_idx(group) |
169 gp_idx = 0 | 170 gp_idx = 0 |
170 if not indexes: #this is a new group, we have to create it | 171 if not indexes: #this is a new group, we have to create it |
171 gp_idx = self.Append(self.__presentGroup(group), Group(group)) | 172 gp_idx = self.Append(self._presentGroup(group), Group(group)) |
172 else: | 173 else: |
173 gp_idx = indexes[0] | 174 gp_idx = indexes[0] |
174 | 175 |
175 _present = self.__presentItem(contact) | 176 _present = self._presentItem(contact) |
176 if _present: | 177 if _present: |
177 self.Insert(_present, gp_idx+1, contact) | 178 self.Insert(_present, gp_idx+1, contact) |
178 | 179 |
179 def setSpecial(self, special_jid, special_type, show=False): | 180 def setSpecial(self, special_jid, special_type, show=False): |
180 """Set entity as a special | 181 """Set entity as a special |
195 self.SetSelection(indexes[0]) | 196 self.SetSelection(indexes[0]) |
196 self.onActivated(wx.MouseEvent()) | 197 self.onActivated(wx.MouseEvent()) |
197 | 198 |
198 def remove(self, contact): | 199 def remove(self, contact): |
199 """remove a contact from the list""" | 200 """remove a contact from the list""" |
200 debug (_("removing %s"), contact) | 201 log.debug (_("removing %s"), contact) |
201 list_idx = self.__find_idx(contact) | 202 list_idx = self.__find_idx(contact) |
202 list_idx.reverse() #as we make some deletions, we have to reverse the order | 203 list_idx.reverse() #as we make some deletions, we have to reverse the order |
203 for i in list_idx: | 204 for i in list_idx: |
204 self.Delete(i) | 205 self.Delete(i) |
205 | 206 |
213 if not erased: #the group was already erased, we can add again the contacts | 214 if not erased: #the group was already erased, we can add again the contacts |
214 contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)] | 215 contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)] |
215 contacts.sort() | 216 contacts.sort() |
216 id_insert = self.GetSelection()+1 | 217 id_insert = self.GetSelection()+1 |
217 for contact in contacts: | 218 for contact in contacts: |
218 _present = self.__presentItem(contact) | 219 _present = self._presentItem(contact) |
219 if _present: | 220 if _present: |
220 self.Insert(_present, id_insert, contact) | 221 self.Insert(_present, id_insert, contact) |
221 self.SetSelection(wx.NOT_FOUND) | 222 self.SetSelection(wx.NOT_FOUND) |
222 self.ScrollToLine(first_visible) | 223 self.ScrollToLine(first_visible) |
223 event.Skip(False) | 224 event.Skip(False) |