Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/chat/smilies.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-01-05 13:52:31 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-01-09 12:38:25 (GMT)
commita26e85289000903cf1d8dd98c4d26fc9fe529ee3 (patch)
tree369ecc504a7d40b0fa5daf29618c87b7c6ba4286 /chat/smilies.py
parent15f3fc574eefc5553f5d1b63dd06daab451ccc62 (diff)
Use a textview to display messages - v2
The textview is used to display text, smilies and url. The palette for the url use MouseSpeedDetector to have the standard behaviour. This patch is v2 and solve issues in the previous patch and should be appiled after "Remove use of hippo (1)" Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'chat/smilies.py')
-rw-r--r--chat/smilies.py39
1 files changed, 8 insertions, 31 deletions
diff --git a/chat/smilies.py b/chat/smilies.py
index 7248ed6..dfb608a 100644
--- a/chat/smilies.py
+++ b/chat/smilies.py
@@ -25,7 +25,6 @@ import cairo
from sugar.graphics import style
from sugar.activity.activity import get_activity_root, get_bundle_path
-
THEME = [
# TRANS: A smiley (http://en.wikipedia.org/wiki/Smiley) explanation
# TRANS: ASCII-art equivalents are :-) and :)
@@ -97,6 +96,14 @@ SMILIES_SIZE = int(style.STANDARD_ICON_SIZE * 0.75)
_catalog = None
+def get_pixbuf(word):
+ """Return a pixbuf associated to a smile, or None if not available"""
+ for (name, hint, codes) in THEME:
+ if word in codes:
+ return gtk.gdk.pixbuf_new_from_file(name)
+ return None
+
+
def init():
"""Initialise smilies data."""
global _catalog
@@ -125,36 +132,6 @@ def init():
pixbuf.save(png_path, 'png')
-def parse(text):
- """Initialise smilies data.
-
- :param text:
- string to parse for smilies
- :returns:
- array of string parts and ciaro surfaces
-
- """
- result = [text]
-
- for smiley in sorted(_catalog.keys(), lambda x, y: cmp(len(y), len(x))):
- smiley_surface = cairo.ImageSurface.create_from_png(_catalog[smiley])
- new_result = []
-
- for word in result:
- if isinstance(word, cairo.ImageSurface):
- new_result.append(word)
- else:
- parts = word.split(smiley)
- for i in parts[:-1]:
- new_result.append(i)
- new_result.append(smiley_surface)
- new_result.append(parts[-1])
-
- result = new_result
-
- return result
-
-
def _from_svg_at_size(filename=None, width=None, height=None, handle=None,
keep_ratio=True):
"""Scale and load SVG into pixbuf."""