comparison src/browser/sat_browser/contact_list.py @ 617:5baca9d46c34 frontends_multi_profiles

browser_side: add/improve some docstrings
author souliane <souliane@mailoo.org>
date Wed, 11 Feb 2015 11:21:27 +0100
parents 1c0d5a87c554
children 2c41ce0c3b3f 57a651a5b31d
comparison
equal deleted inserted replaced
616:1c0d5a87c554 617:5baca9d46c34
43 unicode = str # XXX: pyjama doesn't manage unicode 43 unicode = str # XXX: pyjama doesn't manage unicode
44 44
45 45
46 def buildPresenceStyle(presence, base_style=None): 46 def buildPresenceStyle(presence, base_style=None):
47 """Return the CSS classname to be used for displaying the given presence information. 47 """Return the CSS classname to be used for displaying the given presence information.
48 @param presence (str): presence is a value in ('', 'chat', 'away', 'dnd', 'xa') 48
49 @param base_style (str): base classname 49 @param presence (unicode): presence is a value in ('', 'chat', 'away', 'dnd', 'xa')
50 @return: str 50 @param base_style (unicode): base classname
51 @return: unicode
51 """ 52 """
52 if not base_style: 53 if not base_style:
53 base_style = "contactLabel" 54 base_style = "contactLabel"
54 return '%s-%s' % (base_style, presence or 'connected') 55 return '%s-%s' % (base_style, presence or 'connected')
55 56
57 def setPresenceStyle(widget, presence, base_style=None): 58 def setPresenceStyle(widget, presence, base_style=None):
58 """ 59 """
59 Set the CSS style of a contact's element according to its presence. 60 Set the CSS style of a contact's element according to its presence.
60 61
61 @param widget (Widget): the UI element of the contact 62 @param widget (Widget): the UI element of the contact
62 @param presence (str): a value in ("", "chat", "away", "dnd", "xa"). 63 @param presence (unicode): a value in ("", "chat", "away", "dnd", "xa").
63 @param base_style (str): the base name of the style to apply 64 @param base_style (unicode): the base name of the style to apply
64 """ 65 """
65 if not hasattr(widget, 'presence_style'): 66 if not hasattr(widget, 'presence_style'):
66 widget.presence_style = None 67 widget.presence_style = None
67 style = buildPresenceStyle(presence, base_style) 68 style = buildPresenceStyle(presence, base_style)
68 if style == widget.presence_style: 69 if style == widget.presence_style:
73 widget.presence_style = style 74 widget.presence_style = style
74 75
75 76
76 class GroupLabel(base_widget.DragLabel, Label, ClickHandler): 77 class GroupLabel(base_widget.DragLabel, Label, ClickHandler):
77 def __init__(self, host, group): 78 def __init__(self, host, group):
79 """
80
81 @param host (SatWebFrontend)
82 @param group (unicode): group name
83 """
78 self.group = group 84 self.group = group
79 Label.__init__(self, group) # , Element=DOM.createElement('div') 85 Label.__init__(self, group) # , Element=DOM.createElement('div')
80 self.setStyleName('group') 86 self.setStyleName('group')
81 base_widget.DragLabel.__init__(self, group, "GROUP", host) 87 base_widget.DragLabel.__init__(self, group, "GROUP", host)
82 ClickHandler.__init__(self) 88 ClickHandler.__init__(self)
85 def onClick(self, sender): 91 def onClick(self, sender):
86 self.host.displayWidget(blog.MicroblogPanel, self.group) 92 self.host.displayWidget(blog.MicroblogPanel, self.group)
87 93
88 94
89 class ContactLabel(HTML): 95 class ContactLabel(HTML):
90 def __init__(self, jid, name=None): 96 def __init__(self, jid_, name=None):
91 HTML.__init__(self) 97 HTML.__init__(self)
92 self.name = name or str(jid) 98 self.name = name or unicode(jid_)
93 self.waiting = False 99 self.waiting = False
94 self.refresh() 100 self.refresh()
95 self.setStyleName('contactLabel') 101 self.setStyleName('contactLabel')
96 102
97 def refresh(self): 103 def refresh(self):
124 130
125 131
126 class ContactBox(VerticalPanel, ClickHandler, base_widget.DragLabel): 132 class ContactBox(VerticalPanel, ClickHandler, base_widget.DragLabel):
127 133
128 def __init__(self, host, jid_, name=None, click_listener=None, handle_menu=None): 134 def __init__(self, host, jid_, name=None, click_listener=None, handle_menu=None):
135 """
136
137 @param host (SatWebFrontend)
138 @param jid_ (jid.JID): contact JID
139 @param name (unicode): contact alias
140 @param click_listener (callable): click callback
141 @param handle_menu (bool): if True, bind a popup menu to the avatar
142 """
129 VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle') 143 VerticalPanel.__init__(self, StyleName='contactBox', VerticalAlignment='middle')
130 base_widget.DragLabel.__init__(self, jid_, "CONTACT", host) 144 base_widget.DragLabel.__init__(self, jid_, "CONTACT", host)
131 self.jid = jid_ 145 self.jid = jid_
132 self.label = ContactLabel(jid_, name) 146 self.label = ContactLabel(jid_, name)
133 self.avatar = ContactMenuBar(self, host) if handle_menu else Image() 147 self.avatar = ContactMenuBar(self, host) if handle_menu else Image()
150 self.label.setMessageWaiting(waiting) 164 self.label.setMessageWaiting(waiting)
151 165
152 def updateAvatar(self, url): 166 def updateAvatar(self, url):
153 """Update the avatar. 167 """Update the avatar.
154 168
155 @param url (str): image url 169 @param url (unicode): image url
156 """ 170 """
157 self.avatar.setUrl(url) 171 self.avatar.setUrl(url)
158 172
159 def onClick(self, sender): 173 def onClick(self, sender):
160 self.click_listener(self.jid) 174 self.click_listener(self.jid)
192 log.warning("Trying to remove a non existent group") 206 log.warning("Trying to remove a non existent group")
193 207
194 def getGroupBox(self, group): 208 def getGroupBox(self, group):
195 """get the widget of a group 209 """get the widget of a group
196 210
197 @param group (str): the group 211 @param group (unicode): the group
198 @return: GroupLabel instance if present, else None""" 212 @return: GroupLabel instance if present, else None"""
199 for wid in self: 213 for wid in self:
200 if isinstance(wid, GroupLabel) and wid.group == group: 214 if isinstance(wid, GroupLabel) and wid.group == group:
201 return wid 215 return wid
202 return None 216 return None
224 238
225 def add(self, jid_, name=None): 239 def add(self, jid_, name=None):
226 """Add a contact to the list. 240 """Add a contact to the list.
227 241
228 @param jid_ (jid.JID): jid_ of the contact 242 @param jid_ (jid.JID): jid_ of the contact
229 @param name (str): optional name of the contact 243 @param name (unicode): optional name of the contact
230 """ 244 """
231 assert isinstance(jid_, jid.JID) 245 assert isinstance(jid_, jid.JID)
232 if jid_ in self.contacts: 246 if jid_ in self.contacts:
233 return 247 return
234 index = 0 248 index = 0
267 281
268 def updateAvatar(self, jid_, url): 282 def updateAvatar(self, jid_, url):
269 """Update the avatar of the given contact 283 """Update the avatar of the given contact
270 284
271 @param jid_ (jid.JID): contact jid 285 @param jid_ (jid.JID): contact jid
272 @param url (str): image url 286 @param url (unicode): image url
273 """ 287 """
274 try: 288 try:
275 self.getContactBox(jid_).updateAvatar(url) 289 self.getContactBox(jid_).updateAvatar(url)
276 except TypeError: 290 except TypeError:
277 pass 291 pass
284 BaseContactsPanel.__init__(self, host, handle_click=True, handle_menu=True) 298 BaseContactsPanel.__init__(self, host, handle_click=True, handle_menu=True)
285 299
286 def setState(self, jid_, type_, state): 300 def setState(self, jid_, type_, state):
287 """Change the appearance of the contact, according to the state 301 """Change the appearance of the contact, according to the state
288 @param jid_ (jid.JID): jid.JID which need to change state 302 @param jid_ (jid.JID): jid.JID which need to change state
289 @param type_ (str): one of "availability", "messageWaiting" 303 @param type_ (unicode): one of "availability", "messageWaiting"
290 @param state: 304 @param state:
291 - for messageWaiting type: 305 - for messageWaiting type:
292 True if message are waiting 306 True if message are waiting
293 - for availability type: 307 - for availability type:
294 C.PRESENCE_UNAVAILABLE or None if not connected, else presence like RFC6121 #4.7.2.1""" 308 C.PRESENCE_UNAVAILABLE or None if not connected, else presence like RFC6121 #4.7.2.1"""
429 # self.updateContact(jid, {}, []) # we remove contact from every group 443 # self.updateContact(jid, {}, []) # we remove contact from every group
430 # self._contacts_panel.remove(jid) 444 # self._contacts_panel.remove(jid)
431 445
432 # def setConnected(self, jid_s, resource, availability, priority, statuses): 446 # def setConnected(self, jid_s, resource, availability, priority, statuses):
433 # """Set connection status 447 # """Set connection status
434 # @param jid_s (str): JID userhost as unicode 448 # @param jid_s (unicode): JID userhost as unicode
435 # """ 449 # """
436 # if availability == 'unavailable': 450 # if availability == 'unavailable':
437 # if jid_s in self.connected: 451 # if jid_s in self.connected:
438 # if resource in self.connected[jid_s]: 452 # if resource in self.connected[jid_s]:
439 # del self.connected[jid_s][resource] 453 # del self.connected[jid_s][resource]
536 contact.label.removeStyleName("selected") 550 contact.label.removeStyleName("selected")
537 551
538 def updateAvatar(self, jid_s, url): 552 def updateAvatar(self, jid_s, url):
539 """Update the avatar of the given contact 553 """Update the avatar of the given contact
540 554
541 @param jid_s (str): contact jid 555 @param jid_s (unicode): contact jid
542 @param url (str): image url 556 @param url (unicode): image url
543 """ 557 """
544 self._contacts_panel.updateAvatar(jid_s, url) 558 self._contacts_panel.updateAvatar(jid_s, url)
545 559
546 def onAvatarUpdate(self, jid_, hash_, profile): 560 def onAvatarUpdate(self, jid_, hash_, profile):
547 """Called on avatar update events 561 """Called on avatar update events
553 self._contacts_panel.updateAvatar(jid_, self.host.getAvatarURL(jid_)) 567 self._contacts_panel.updateAvatar(jid_, self.host.getAvatarURL(jid_))
554 568
555 def hasVisibleMembers(self, group): 569 def hasVisibleMembers(self, group):
556 """Tell if the given group actually has visible members 570 """Tell if the given group actually has visible members
557 571
558 @param group (str): the group to check 572 @param group (unicode): the group to check
559 @return: boolean 573 @return: boolean
560 """ 574 """
561 for jid_ in self.groups[group]: 575 for jid_ in self.groups[group]:
562 if self._contacts_panel.getContactBox(jid_).isVisible(): 576 if self._contacts_panel.getContactBox(jid_).isVisible():
563 return True 577 return True
584 self._contacts_panel.setState(entity_bare, "availability", show) 598 self._contacts_panel.setState(entity_bare, "availability", show)
585 599
586 # def updateVisibility(self, jids, groups): 600 # def updateVisibility(self, jids, groups):
587 # """Set the widgets visibility for the given contacts and groups 601 # """Set the widgets visibility for the given contacts and groups
588 602
589 # @param jids (list[str]): list of JID 603 # @param jids (list[unicode]): list of JID
590 # @param groups (list[str]): list of groups 604 # @param groups (list[unicode]): list of groups
591 # """ 605 # """
592 # for jid_s in jids: 606 # for jid_s in jids:
593 # try: 607 # try:
594 # self._contacts_panel.getContactBox(jid_s).setVisible(jid_s in self.connected or self.offlineContactsToShow()) 608 # self._contacts_panel.getContactBox(jid_s).setVisible(jid_s in self.connected or self.offlineContactsToShow())
595 # except TypeError: 609 # except TypeError: