comparison src/browser/sat_browser/contact_panel.py @ 779:fc941d0d97f8

browser_side: fixed ContactsPanel scrolling
author souliane <souliane@mailoo.org>
date Mon, 30 Nov 2015 21:52:41 +0100
parents 76a9c074327b
children b2a75a103aac
comparison
equal deleted inserted replaced
778:31c682149d52 779:fc941d0d97f8
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from sat.core.log import getLogger 23 from sat.core.log import getLogger
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat_frontends.tools import jid 25 from sat_frontends.tools import jid
26 26
27 from pyjamas.ui.ScrollPanel import ScrollPanel
27 from pyjamas.ui.VerticalPanel import VerticalPanel 28 from pyjamas.ui.VerticalPanel import VerticalPanel
28 29
29 import contact_widget 30 import contact_widget
30 from constants import Const as C 31 from constants import Const as C
31 32
32 33
33 class ContactsPanel(VerticalPanel): 34 class ContactsPanel(ScrollPanel):
34 """ContactList graphic representation 35 """ContactList graphic representation
35 36
36 Special features like popup menu panel or changing the contact states must be done in a sub-class. 37 Special features like popup menu panel or changing the contact states must be done in a sub-class.
37 """ 38 """
38 39
49 @param contacts_menus (tuple): define the menu types that fit this 50 @param contacts_menus (tuple): define the menu types that fit this
50 contact panel, with values from the menus type constants. 51 contact panel, with values from the menus type constants.
51 @param contacts_display (tuple): prioritize the display methods of the 52 @param contacts_display (tuple): prioritize the display methods of the
52 contact's label with values in ("jid", "nick", "bare", "resource") 53 contact's label with values in ("jid", "nick", "bare", "resource")
53 """ 54 """
54 VerticalPanel.__init__(self) 55 self.panel = VerticalPanel()
56 ScrollPanel.__init__(self, self.panel)
57 self.addStyleName("gwt-ScrollPanel") # XXX: no class is set by Pyjamas
58
55 self.host = host 59 self.host = host
56 self.merge_resources = merge_resources 60 self.merge_resources = merge_resources
57 self._contacts = {} # entity jid to ContactBox map 61 self._contacts = {} # entity jid to ContactBox map
58 self.click_listener = None 62 self.panel.click_listener = None
59 63
60 if contacts_click is not None: 64 if contacts_click is not None:
61 self.onClick = contacts_click 65 self.panel.onClick = contacts_click
62 66
63 self.contacts_style = contacts_style 67 self.contacts_style = contacts_style
64 self.contacts_menus = contacts_menus 68 self.contacts_menus = contacts_menus
65 self.contacts_display = contacts_display 69 self.contacts_display = contacts_display
66 70
81 85
82 86
83 def clear(self): 87 def clear(self):
84 """Clear all contacts.""" 88 """Clear all contacts."""
85 self._contacts.clear() 89 self._contacts.clear()
86 VerticalPanel.clear(self) 90 VerticalPanel.clear(self.panel)
87 91
88 def setList(self, jids): 92 def setList(self, jids):
89 """set all contacts in the list in one shot. 93 """set all contacts in the list in one shot.
90 94
91 @param jids (list[jid.JID]): jids to display (the order is kept) 95 @param jids (list[jid.JID]): jids to display (the order is kept)
92 @param name (unicode): optional name of the contact 96 @param name (unicode): optional name of the contact
93 """ 97 """
94 current_jids = [box.jid for box in self.children if isinstance(box, contact_widget.ContactBox)] 98 current_jids = [box.jid for box in self.panel.children if isinstance(box, contact_widget.ContactBox)]
95 if current_jids == jids: 99 if current_jids == jids:
96 # the display doesn't change 100 # the display doesn't change
97 return 101 return
98 for contact_jid in set(current_jids).difference(jids): 102 for contact_jid in set(current_jids).difference(jids):
99 self.removeContactBox(contact_jid) 103 self.removeContactBox(contact_jid)
130 style_name=self.contacts_style, 134 style_name=self.contacts_style,
131 display=self.contacts_display, 135 display=self.contacts_display,
132 plugin_menu_context=self.contacts_menus) 136 plugin_menu_context=self.contacts_menus)
133 self._contacts[self._key(contact_jid)] = box 137 self._contacts[self._key(contact_jid)] = box
134 if index: 138 if index:
135 VerticalPanel.insert(self, box, index) 139 VerticalPanel.insert(self.panel, box, index)
136 else: 140 else:
137 VerticalPanel.append(self, box) 141 VerticalPanel.append(self.panel, box)
138 return box 142 return box
139 143
140 def removeContactBox(self, contact_jid): 144 def removeContactBox(self, contact_jid):
141 """Remove a contact. 145 """Remove a contact.
142 146
143 @param contact_jid (jid.JID): contact JID 147 @param contact_jid (jid.JID): contact JID
144 """ 148 """
145 box = self._contacts.pop(self._key(contact_jid), None) 149 box = self._contacts.pop(self._key(contact_jid), None)
146 if box: 150 if box:
147 VerticalPanel.remove(self, box) 151 VerticalPanel.remove(self.panel, box)