comparison frontends/wix/main_window.py @ 53:6dfe5bb10008

Wix: groups in contact list, first draft
author Goffi <goffi@goffi.org>
date Sun, 10 Jan 2010 16:42:09 +1100
parents 6455fb62ff83
children 2ce9e350cdf9
comparison
equal deleted inserted replaced
52:6455fb62ff83 53:6dfe5bb10008
72 72
73 def __init__(self, parent, CM): 73 def __init__(self, parent, CM):
74 wx.SimpleHtmlListBox.__init__(self, parent, -1) 74 wx.SimpleHtmlListBox.__init__(self, parent, -1)
75 QuickContactList.__init__(self, CM) 75 QuickContactList.__init__(self, CM)
76 self.host = parent 76 self.host = parent
77 self.groups = {} #list contacts in each groups, key = group
78 self.Bind(wx.EVT_LISTBOX, self.onSelected)
77 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated) 79 self.Bind(wx.EVT_LISTBOX_DCLICK, self.onActivated)
78 80
79 def __find_idx(self, jid, reverse=False): 81 def __find_idx(self, entity, reverse=False):
80 """Find indexes of given jid in contact list 82 """Find indexes of given jid in contact list
81 @return: list of indexes""" 83 @return: list of indexes"""
82 result=[] 84 result=[]
83 for i in range(self.GetCount()): 85 for i in range(self.GetCount()):
84 if self.GetClientData(i).short == jid.short: 86 if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\
87 self.GetClientData(i) == entity:
85 result.append(i) 88 result.append(i)
86 return result 89 return result
87 90
88 def replace(self, jid): 91 def replace(self, jid):
89 debug("update %s" % jid) 92 debug("update %s" % jid)
93 for i in self.__find_idx(jid): 96 for i in self.__find_idx(jid):
94 self.SetString(i, self.__presentItem(jid)) 97 self.SetString(i, self.__presentItem(jid))
95 98
96 def disconnect(self, jid): 99 def disconnect(self, jid):
97 self.remove(jid) #for now, we only show online contacts 100 self.remove(jid) #for now, we only show online contacts
101
102 def __presentGroup(self, group):
103 """Make a nice presentation for the contact groups"""
104 html = """[%s]""" % group
105
106 return html
98 107
99 def __presentItem(self, jid): 108 def __presentItem(self, jid):
100 """Make a nice presentation of the contact in the list.""" 109 """Make a nice presentation of the contact in the list."""
101 name = self.CM.getAttr(jid,'name') 110 name = self.CM.getAttr(jid,'name')
102 nick = self.CM.getAttr(jid,'nick') 111 nick = self.CM.getAttr(jid,'nick')
131 self.Clear() 140 self.Clear()
132 141
133 def add(self, jid): 142 def add(self, jid):
134 """add a contact to the list""" 143 """add a contact to the list"""
135 debug ("adding %s",jid) 144 debug ("adding %s",jid)
136 idx = self.Append(self.__presentItem(jid)) 145 groups = self.CM.getAttr(jid, 'groups')
137 146 if not groups:
138 self.SetClientData(idx, jid) 147 idx = self.Append(self.__presentItem(jid), jid)
148 else:
149 for group in groups:
150 indexes = self.__find_idx(group)
151 gp_idx = 0
152 if not indexes: #this is a new group, we have to create it
153 gp_idx = self.Append(self.__presentGroup(group), group)
154 else:
155 gp_idx = indexes[0]
156
157 self.Insert(self.__presentItem(jid), gp_idx+1, jid)
158
159
139 160
140 def remove(self, jid): 161 def remove(self, jid):
141 """remove a contact from the list""" 162 """remove a contact from the list"""
142 debug ("removing %s",jid) 163 debug ("removing %s",jid)
143 list_idx = self.__find_idx(jid) 164 list_idx = self.__find_idx(jid)
144 list_idx.reverse() #we me make some deletions, we have to reverse the order 165 list_idx.reverse() #we me make some deletions, we have to reverse the order
145 for i in list_idx: 166 for i in list_idx:
146 self.Delete(i) 167 self.Delete(i)
147 168
169 def onSelected(self, event):
170 """Called when a contact is selected."""
171 data = self.getSelection()
172 if type(data) == JID:
173 event.Skip()
174 else:
175 #We don't want to select groups
176 self.SetSelection(wx.NOT_FOUND)
177 event.Skip(False)
178
148 def onActivated(self, event): 179 def onActivated(self, event):
149 """Called when a contact is clicked or activated with keyboard.""" 180 """Called when a contact is clicked or activated with keyboard."""
150 data = self.getSelection() 181 data = self.getSelection()
151 self.onActivatedCB(data) 182 self.onActivatedCB(data)
152 event.Skip() 183 event.Skip()