Mercurial > libervia-web
diff browser_side/tools.py @ 279:2d6bd975a72d
browser_side: set your own presence status and display those of others
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 23 Nov 2013 14:46:03 +0100 |
parents | aebb96bfa8d1 |
children | 0eba1c4f9c6f |
line wrap: on
line diff
--- a/browser_side/tools.py Fri Nov 22 21:43:08 2013 +0100 +++ b/browser_side/tools.py Sat Nov 23 14:46:03 2013 +0100 @@ -26,9 +26,10 @@ dom = NativeDOM() + def html_sanitize(html): """Naive sanitization of HTML""" - return html.replace('<','<').replace('>','>') + return html.replace('<', '<').replace('>', '>') def inlineRoot(xhtml): @@ -36,6 +37,7 @@ doc = dom.parseString(xhtml) return xml.inlineRoot(doc) + def addURLToText(string): """Check a text for what looks like an URL and make it clickable. Regexp from http://daringfireball.net/2010/07/improved_regex_for_matching_urls""" @@ -49,6 +51,22 @@ return re.sub(pattern, repl, string) +def setPresenceStyle(item, state, base_style="contact"): + """ + @item: any UI element + @state: a value from ("", "chat", "away", "dnd", "xa") + """ + if not hasattr(item, 'presence_style'): + item.presence_style = None + style = '%s-%s' % (base_style, state or 'connected') + if style == item.presence_style: + return + if item.presence_style is not None: + item.removeStyleName(item.presence_style) + item.addStyleName(style) + item.presence_style = style + + class DragLabel(DragWidget): def __init__(self, text, _type): @@ -61,9 +79,10 @@ dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) dt.setDragImage(self.getElement(), 15, 15) + class LiberviaDragWidget(DragLabel): """ A DragLabel which keep the widget being dragged as class value """ - current = None # widget currently dragged + current = None # widget currently dragged def __init__(self, text, _type, widget): DragLabel.__init__(self, text, _type)