comparison browser_side/contact.py @ 255:da0487f0a2e7

browser_side: small changes to prepare the contact group manager: - group and contact lists are sorted - avoid adding empty group in the "Add group" panel - allow to show/hide the contact panel from another class
author souliane <souliane@mailoo.org>
date Sat, 09 Nov 2013 15:31:39 +0100
parents b77940d8a9bf
children 30c01671e338
comparison
equal deleted inserted replaced
254:28d3315a8003 255:da0487f0a2e7
87 87
88 def add(self, group): 88 def add(self, group):
89 _item = GroupLabel(self._parent.host, group) 89 _item = GroupLabel(self._parent.host, group)
90 _item.addMouseListener(self._parent) 90 _item.addMouseListener(self._parent)
91 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") 91 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
92 VerticalPanel.add(self, _item) 92 index = 0
93 for group_ in [group.group for group in self.getChildren()]:
94 if group_ > group:
95 break
96 index += 1
97 VerticalPanel.insert(self, _item, index)
93 98
94 def remove(self, group): 99 def remove(self, group):
95 for wid in self: 100 for wid in self:
96 if isinstance(wid, GroupLabel) and wid.group == group: 101 if isinstance(wid, GroupLabel) and wid.group == group:
97 VerticalPanel.remove(self, wid) 102 VerticalPanel.remove(self, wid)
103 panel or changing the contact states must be done in a sub-class.""" 108 panel or changing the contact states must be done in a sub-class."""
104 109
105 def __init__(self, host): 110 def __init__(self, host):
106 VerticalPanel.__init__(self) 111 VerticalPanel.__init__(self)
107 self.host = host 112 self.host = host
108 self.contacts = set() 113 self.contacts = []
109 114
110 def add(self, jid, name=None, item_cb=None): 115 def add(self, jid, name=None, item_cb=None):
111 if jid in self.contacts: 116 if jid in self.contacts:
112 return 117 return
113 self.contacts.add(jid) 118 index = 0
119 for contact_ in self.contacts:
120 if contact_ > jid:
121 break
122 index += 1
123 self.contacts.insert(index, jid)
114 _item = ContactLabel(self.host, jid, name) 124 _item = ContactLabel(self.host, jid, name)
115 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") 125 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
116 VerticalPanel.add(self, _item) 126 VerticalPanel.insert(self, _item, index)
117 if item_cb is not None: 127 if item_cb is not None:
118 item_cb(_item) 128 item_cb(_item)
119 129
120 def remove(self, jid): 130 def remove(self, jid):
121 wid = self.getContactLabel(jid) 131 wid = self.getContactLabel(jid)