comparison frontends/wix/main_window.py @ 54:2ce9e350cdf9

Wix: clicking on group in contact_list now (un)hide it. Quick App: added a method to get all contacts in a group in contact_management
author Goffi <goffi@goffi.org>
date Sun, 10 Jan 2010 17:25:43 +1100
parents 6dfe5bb10008
children 20e54702fc0b
comparison
equal deleted inserted replaced
53:6dfe5bb10008 54:2ce9e350cdf9
77 self.groups = {} #list contacts in each groups, key = group 77 self.groups = {} #list contacts in each groups, key = group
78 self.Bind(wx.EVT_LISTBOX, self.onSelected) 78 self.Bind(wx.EVT_LISTBOX, self.onSelected)
79 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated) 79 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
80 80
81 def __find_idx(self, entity, reverse=False): 81 def __find_idx(self, entity, reverse=False):
82 """Find indexes of given jid in contact list 82 """Find indexes of given jid (or groups) in contact list
83 @return: list of indexes""" 83 @return: list of indexes"""
84 result=[] 84 result=[]
85 for i in range(self.GetCount()): 85 for i in range(self.GetCount()):
86 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\ 86 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\
87 self.GetClientData(i) == entity: 87 self.GetClientData(i) == entity:
96 for i in self.__find_idx(jid): 96 for i in self.__find_idx(jid):
97 self.SetString(i, self.__presentItem(jid)) 97 self.SetString(i, self.__presentItem(jid))
98 98
99 def disconnect(self, jid): 99 def disconnect(self, jid):
100 self.remove(jid) #for now, we only show online contacts 100 self.remove(jid) #for now, we only show online contacts
101
102 def __eraseGroup(self, group):
103 """Erase all contacts in group
104 @param group: group to erase
105 @return: True if something as been erased"""
106 erased = False
107 indexes = self.__find_idx(group)
108 for idx in indexes:
109 while idx<self.GetCount()-1 and type(self.GetClientData(idx+1)) == JID:
110 erased = True
111 self.Delete(idx+1)
112 return erased
113
101 114
102 def __presentGroup(self, group): 115 def __presentGroup(self, group):
103 """Make a nice presentation for the contact groups""" 116 """Make a nice presentation for the contact groups"""
104 html = """[%s]""" % group 117 html = """-- [%s] --""" % group
105 118
106 return html 119 return html
107 120
108 def __presentItem(self, jid): 121 def __presentItem(self, jid):
109 """Make a nice presentation of the contact in the list.""" 122 """Make a nice presentation of the contact in the list."""
170 """Called when a contact is selected.""" 183 """Called when a contact is selected."""
171 data = self.getSelection() 184 data = self.getSelection()
172 if type(data) == JID: 185 if type(data) == JID:
173 event.Skip() 186 event.Skip()
174 else: 187 else:
175 #We don't want to select groups 188 group = self.GetClientData(self.GetSelection())
189 erased = self.__eraseGroup(group)
190 if not erased: #the group was already erased, we can add again the contacts
191 contacts = self.CM.getContFromGroup(group)
192 contacts.sort()
193 id_insert = self.GetSelection()+1
194 for contact in contacts:
195 self.Insert(self.__presentItem(contact), id_insert, contact)
176 self.SetSelection(wx.NOT_FOUND) 196 self.SetSelection(wx.NOT_FOUND)
177 event.Skip(False) 197 event.Skip(False)
178 198
179 def onActivated(self, event): 199 def onActivated(self, event):
180 """Called when a contact is clicked or activated with keyboard.""" 200 """Called when a contact is clicked or activated with keyboard."""
183 event.Skip() 203 event.Skip()
184 204
185 def getSelection(self): 205 def getSelection(self):
186 """Return the selected contact, or an empty string if there is not""" 206 """Return the selected contact, or an empty string if there is not"""
187 if self.GetSelection() == wx.NOT_FOUND: 207 if self.GetSelection() == wx.NOT_FOUND:
188 return "" #FIXME: gof: à améliorer 208 return None
189 data = self.GetClientData(self.GetSelection()) 209 data = self.GetClientData(self.GetSelection())
210 if type(data) != JID:
211 return None
190 return data 212 return data
191 213
192 def registerActivatedCB(self, cb): 214 def registerActivatedCB(self, cb):
193 """Register a callback with manage contact activation.""" 215 """Register a callback with manage contact activation."""
194 self.onActivatedCB=cb 216 self.onActivatedCB=cb