Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
278:4517978a2e7e | 279:2d6bd975a72d |
---|---|
24 from nativedom import NativeDOM | 24 from nativedom import NativeDOM |
25 from sat_frontends.tools import xml | 25 from sat_frontends.tools import xml |
26 | 26 |
27 dom = NativeDOM() | 27 dom = NativeDOM() |
28 | 28 |
29 | |
29 def html_sanitize(html): | 30 def html_sanitize(html): |
30 """Naive sanitization of HTML""" | 31 """Naive sanitization of HTML""" |
31 return html.replace('<','<').replace('>','>') | 32 return html.replace('<', '<').replace('>', '>') |
32 | 33 |
33 | 34 |
34 def inlineRoot(xhtml): | 35 def inlineRoot(xhtml): |
35 """ make root element inline """ | 36 """ make root element inline """ |
36 doc = dom.parseString(xhtml) | 37 doc = dom.parseString(xhtml) |
37 return xml.inlineRoot(doc) | 38 return xml.inlineRoot(doc) |
39 | |
38 | 40 |
39 def addURLToText(string): | 41 def addURLToText(string): |
40 """Check a text for what looks like an URL and make it clickable. Regexp | 42 """Check a text for what looks like an URL and make it clickable. Regexp |
41 from http://daringfireball.net/2010/07/improved_regex_for_matching_urls""" | 43 from http://daringfireball.net/2010/07/improved_regex_for_matching_urls""" |
42 | 44 |
47 return '<a href="%s" target="_blank" class="url">%s</a>' % (url, match.group(0)) | 49 return '<a href="%s" target="_blank" class="url">%s</a>' % (url, match.group(0)) |
48 pattern = r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))""" | 50 pattern = r"""(?i)\b((?:[a-z]{3,}://|(www|ftp)\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/|mailto:|xmpp:)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?]))""" |
49 return re.sub(pattern, repl, string) | 51 return re.sub(pattern, repl, string) |
50 | 52 |
51 | 53 |
54 def setPresenceStyle(item, state, base_style="contact"): | |
55 """ | |
56 @item: any UI element | |
57 @state: a value from ("", "chat", "away", "dnd", "xa") | |
58 """ | |
59 if not hasattr(item, 'presence_style'): | |
60 item.presence_style = None | |
61 style = '%s-%s' % (base_style, state or 'connected') | |
62 if style == item.presence_style: | |
63 return | |
64 if item.presence_style is not None: | |
65 item.removeStyleName(item.presence_style) | |
66 item.addStyleName(style) | |
67 item.presence_style = style | |
68 | |
69 | |
52 class DragLabel(DragWidget): | 70 class DragLabel(DragWidget): |
53 | 71 |
54 def __init__(self, text, _type): | 72 def __init__(self, text, _type): |
55 DragWidget.__init__(self) | 73 DragWidget.__init__(self) |
56 self._text = text | 74 self._text = text |
59 def onDragStart(self, event): | 77 def onDragStart(self, event): |
60 dt = event.dataTransfer | 78 dt = event.dataTransfer |
61 dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) | 79 dt.setData('text/plain', "%s\n%s" % (self._text, self._type)) |
62 dt.setDragImage(self.getElement(), 15, 15) | 80 dt.setDragImage(self.getElement(), 15, 15) |
63 | 81 |
82 | |
64 class LiberviaDragWidget(DragLabel): | 83 class LiberviaDragWidget(DragLabel): |
65 """ A DragLabel which keep the widget being dragged as class value """ | 84 """ A DragLabel which keep the widget being dragged as class value """ |
66 current = None # widget currently dragged | 85 current = None # widget currently dragged |
67 | 86 |
68 def __init__(self, text, _type, widget): | 87 def __init__(self, text, _type, widget): |
69 DragLabel.__init__(self, text, _type) | 88 DragLabel.__init__(self, text, _type) |
70 self.widget = widget | 89 self.widget = widget |
71 | 90 |