comparison frontends/src/primitivus/contact_list.py @ 500:00d3679976ab

primitivus: keep focus position in contacts list on redraw
author Goffi <goffi@goffi.org>
date Wed, 05 Sep 2012 00:19:32 +0200
parents 28f4ce741ae5
children e9634d2e7b38
comparison
equal deleted inserted replaced
499:28f4ce741ae5 500:00d3679976ab
43 urwid.connect_signal(self, 'click', on_click, user_data) 43 urwid.connect_signal(self, 'click', on_click, user_data)
44 if on_change: 44 if on_change:
45 urwid.connect_signal(self, 'change', on_change, user_data) 45 urwid.connect_signal(self, 'change', on_change, user_data)
46 QuickContactList.__init__(self, CM) 46 QuickContactList.__init__(self, CM)
47 47
48 def _update(self):
49 """Update display, keep focus"""
50 widget, position = self.frame.body.get_focus()
51 self.frame.body = self.__buildList()
52 if position:
53 self.frame.body.set_focus(position)
54 self.host.redraw()
55
48 def keypress(self, size, key): 56 def keypress(self, size, key):
49 if key == "meta s": #user wants to (un)hide contacts' statuses 57 if key == "meta s": #user wants to (un)hide contacts' statuses
50 self.show_status = not self.show_status 58 self.show_status = not self.show_status
51 self.frame.body = self.__buildList() 59 self._update()
52 self.host.redraw()
53 return super(ContactList, self).keypress(size, key) 60 return super(ContactList, self).keypress(size, key)
54 61
55 def __contains__(self, jid): 62 def __contains__(self, jid):
56 for group in self.groups: 63 for group in self.groups:
57 if jid.short in self.groups[group][1]: 64 if jid.short in self.groups[group][1]:
68 idx+=1 75 idx+=1
69 76
70 def putAlert(self, jid): 77 def putAlert(self, jid):
71 """Put an alert on the jid to get attention from user (e.g. for new message)""" 78 """Put an alert on the jid to get attention from user (e.g. for new message)"""
72 self.alert_jid.add(jid.short) 79 self.alert_jid.add(jid.short)
73 self.frame.body = self.__buildList() 80 self._update()
74 self.host.redraw()
75 81
76 def __groupClicked(self, group_wid): 82 def __groupClicked(self, group_wid):
77 group = self.groups[group_wid.getValue()] 83 group = self.groups[group_wid.getValue()]
78 group[0] = not group[0] 84 group[0] = not group[0]
79 self.frame.body = self.__buildList() 85 self._update()
80 self.host.redraw()
81 self.setFocus(group_wid.getValue()) 86 self.setFocus(group_wid.getValue())
82 87
83 def __contactClicked(self, contact_wid, selected): 88 def __contactClicked(self, contact_wid, selected):
84 self.selected = contact_wid.data 89 self.selected = contact_wid.data
85 for widget in self.frame.body.body: 90 for widget in self.frame.body.body:
86 if widget.__class__ == sat_widgets.SelectableText: 91 if widget.__class__ == sat_widgets.SelectableText:
87 widget.setState(widget.data == self.selected, invisible=True) 92 widget.setState(widget.data == self.selected, invisible=True)
88 if self.selected in self.alert_jid: 93 if self.selected in self.alert_jid:
89 self.alert_jid.remove(self.selected) 94 self.alert_jid.remove(self.selected)
90 self.frame.body = self.__buildList() 95 self._update()
91 self.host.redraw()
92 self._emit('click') 96 self._emit('click')
93 97
94 def __buildContact(self, content, param_contacts): 98 def __buildContact(self, content, param_contacts):
95 """Add contact representation in widget list 99 """Add contact representation in widget list
96 @param content: widget list, e.g. SimpleListWalker 100 @param content: widget list, e.g. SimpleListWalker
148 def clear_contacts(self): 152 def clear_contacts(self):
149 """clear all the contact list""" 153 """clear all the contact list"""
150 self.groups={} 154 self.groups={}
151 self.selected = None 155 self.selected = None
152 self.unselectAll() 156 self.unselectAll()
153 self.frame.body = self.__buildList() 157 self._update()
154 self.host.redraw()
155 158
156 def replace(self, jid, groups=[None]): 159 def replace(self, jid, groups=[None]):
157 """add a contact to the list if doesn't exist, else update it""" 160 """add a contact to the list if doesn't exist, else update it"""
158 assert isinstance(groups, list) 161 assert isinstance(groups, list)
159 assert isinstance(jid, JID) 162 assert isinstance(jid, JID)
161 groups=[None] 164 groups=[None]
162 for group in groups: 165 for group in groups:
163 if not self.groups.has_key(group): 166 if not self.groups.has_key(group):
164 self.groups[group] = [True,set()] #[unfold,list_of_contacts] 167 self.groups[group] = [True,set()] #[unfold,list_of_contacts]
165 self.groups[group][1].add(jid.short) 168 self.groups[group][1].add(jid.short)
166 self.frame.body = self.__buildList() 169 self._update()
167 self.host.redraw()
168 170
169 171
170 """contacts = self.list_wid.getAllValues() 172 """contacts = self.list_wid.getAllValues()
171 if jid.short not in contacts: 173 if jid.short not in contacts:
172 contacts.append(jid.short) 174 contacts.append(jid.short)
188 contacts.remove(jid.short) 190 contacts.remove(jid.short)
189 if not len(contacts): 191 if not len(contacts):
190 groups_to_remove.append(group) 192 groups_to_remove.append(group)
191 for group in groups_to_remove: 193 for group in groups_to_remove:
192 del self.groups[group] 194 del self.groups[group]
193 self.frame.body = self.__buildList() 195 self._update()
194 self.host.redraw()
195 196
196 def add(self, jid, param_groups=[None]): 197 def add(self, jid, param_groups=[None]):
197 """add a contact to the list""" 198 """add a contact to the list"""
198 self.replace(jid,param_groups) 199 self.replace(jid,param_groups)
199 200