On Wed, Aug 24, 2011 at 9:20 PM, Manuel Quiñones <span dir="ltr"><<a href="mailto:manuq@laptop.org">manuq@laptop.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

The activity was done in Pippy.  It has unneeded functions, and svg<br>
icons embedded in the code.  I'm removing them to make Words code more<br>
consistent with the rest of the activities.<br>
<br>
Signed-off-by: Manuel Quiñones <<a href="mailto:manuq@laptop.org">manuq@laptop.org</a>><br>
---<br>
 activity.py            |   84 ------------<br>
 activity/<a href="http://activity.info" target="_blank">activity.info</a> |    2 +-<br>
 pippy_app.py           |  349 ------------------------------------------------<br>
 wordsactivity.py       |  267 ++++++++++++++++++++++++++++++++++++<br>
 4 files changed, 268 insertions(+), 434 deletions(-)<br>
 delete mode 100644 activity.py<br>
 delete mode 100644 pippy_app.py<br>
 create mode 100644 wordsactivity.py<br>
<br>
diff --git a/activity.py b/activity.py<br>
deleted file mode 100644<br>
index 061187e..0000000<br>
--- a/activity.py<br>
+++ /dev/null<br>
@@ -1,84 +0,0 @@<br>
-from sugar.activity import activity<br>
-<br>
-class ViewSourceActivity(activity.Activity):<br>
-    """Activity subclass which handles the 'view source' key."""<br>
-    def __init__(self, handle):<br>
-        super(ViewSourceActivity, self).__init__(handle)<br>
-        self.__source_object_id = None # XXX: persist this across invocations?<br>
-        self.connect('key-press-event', self._key_press_cb)<br>
-    def _key_press_cb(self, widget, event):<br>
-        import gtk<br>
-        if gtk.gdk.keyval_name(event.keyval) == 'XF86Start':<br>
-            self.view_source()<br>
-            return True<br>
-        return False<br>
-    def view_source(self):<br>
-        """Implement the 'view source' key by saving pippy_app.py to the<br>
-        datastore, and then telling the Journal to view it."""<br>
-        if self.__source_object_id is None:<br>
-            from sugar import profile<br>
-            from sugar.datastore import datastore<br>
-            from sugar.activity.activity import get_bundle_name, get_bundle_path<br>
-            from gettext import gettext as _<br>
-            import os.path<br>
-            jobject = datastore.create()<br>
-            metadata = {<br>
-                'title': _('%s Source') % get_bundle_name(),<br>
-                'title_set_by_user': '1',<br>
-                'suggested_filename': 'pippy_app.py',<br>
-                'icon-color': profile.get_color().to_string(),<br>
-                'mime_type': 'text/x-python',<br>
-                }<br>
-            for k, v in metadata.items():<br>
-                jobject.metadata[k] = v  # dict.update method is missing =(<br>
-            jobject.file_path = os.path.join(get_bundle_path(), 'pippy_app.py')<br>
-            datastore.write(jobject)<br>
-            self.__source_object_id = jobject.object_id<br>
-            jobject.destroy()<br>
-        self.journal_show_object(self.__source_object_id)<br>
-    def journal_show_object(self, object_id):<br>
-        """Invoke journal_show_object from sugar.activity.activity if it<br>
-        exists."""<br>
-        try:<br>
-            from sugar.activity.activity import show_object_in_journal<br>
-            show_object_in_journal(object_id)<br>
-        except ImportError:<br>
-            pass  # no love from sugar.<br>
-<br>
-class VteActivity(ViewSourceActivity):<br>
-    def __init__(sfelf, handle):<br>
-        import gtk, pango, vte<br>
-        super(VteActivity, self).__init__(handle)<br>
-        toolbox = activity.ActivityToolbox(self)<br>
-        self.set_toolbox(toolbox)<br>
-        toolbox.show()<br>
-<br>
-        # creates vte widget<br>
-        self._vte = vte.Terminal()<br>
-        self._vte.set_size(30, 5)<br>
-        self._vte.set_size_request(200, 300)<br>
-        font = 'Monospace 10'<br>
-        self._vte.set_font(pango.FontDescription(font))<br>
-        self._vte.set_colors(gtk.gdk.color_parse ('#000000'),<br>
-                             gtk.gdk.color_parse ('#E7E7E7'),<br>
-                             [])<br>
-        # ...and its scrollbar<br>
-        vtebox = gtk.HBox()<br>
-        vtebox.pack_start(self._vte)<br>
-        vtesb = gtk.VScrollbar(self._vte.get_adjustment())<br>
-        vtesb.show()<br>
-        vtebox.pack_start(vtesb, False, False, 0)<br>
-        self.set_canvas(vtebox)<br>
-        self.show_all()<br>
-<br>
-        # now start subprocess.<br>
-        self._vte.grab_focus()<br>
-        bundle_path = activity.get_bundle_path()<br>
-        # the 'sleep 1' works around a bug with the command dying before<br>
-        # the vte widget manages to snarf the last bits of its output<br>
-        self._pid = self._vte.fork_command \<br>
-                    (command='/bin/sh',<br>
-                     argv=['/bin/sh','-c',<br>
-                           'python %s/pippy_app.py; sleep 1' % bundle_path],<br>
-                     envv=["PYTHONPATH=%s/library" % bundle_path],<br>
-                     directory=bundle_path)<br>
diff --git a/activity/<a href="http://activity.info" target="_blank">activity.info</a> b/activity/<a href="http://activity.info" target="_blank">activity.info</a><br>
index 43fd48e..be2269c 100644<br>
--- a/activity/<a href="http://activity.info" target="_blank">activity.info</a><br>
+++ b/activity/<a href="http://activity.info" target="_blank">activity.info</a><br>
@@ -1,7 +1,7 @@<br>
 [Activity]<br>
 name = Words<br>
 bundle_id = org.laptop.Words<br>
-class = pippy_app.WordsActivity<br>
+class = wordsactivity.WordsActivity<br>
 icon = activity-icon<br>
 activity_version = 10<br>
 show_launcher = yes<br>
diff --git a/pippy_app.py b/pippy_app.py<br>
deleted file mode 100644<br>
index 52750c2..0000000<br>
--- a/pippy_app.py<br>
+++ /dev/null<br>
@@ -1,349 +0,0 @@<br>
-# Copyright 2008 Chris Ball.<br>
-#<br>
-# This program is free software; you can redistribute it and/or modify<br>
-# it under the terms of the GNU General Public License as published by<br>
-# the Free Software Foundation, either version 2 of the License, or<br>
-# (at your option) any later version.<br>
-#<br>
-# This program is distributed in the hope that it will be useful,<br>
-# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
-# GNU General Public License for more details.<br>
-#<br>
-# You should have received a copy of the GNU General Public License<br>
-# along with this program; if not, write to the Free Software<br>
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br>
-<br>
-"""Words Activity: A multi-lingual dictionary with speech synthesis."""<br>
-"""Actividad Palabras: Un diccionario multi-lengua con sintesis de habla"""<br>
-<br>
-import gtk<br>
-import logging<br>
-import pango<br>
-import re<br>
-import os<br>
-import os.path<br>
-import subprocess<br>
-<br>
-from gettext import gettext as _<br>
-from dbus.service import method, signal<br>
-<br>
-from activity import ViewSourceActivity<br>
-from sugar.activity.activity import ActivityToolbox, \<br>
-     get_bundle_path, get_bundle_name<br>
-<br>
-from sugar.graphics.toolbutton import ToolButton<br>
-<br>
-# logging<br>
-logger = logging.getLogger('Words')<br>
-<br>
-SERVICE = "org.laptop.Words"<br>
-IFACE = SERVICE<br>
-PATH = "/org/laptop/Words"<br>
-<br>
-class WordsActivity(ViewSourceActivity):<br>
-    """Words Activity as specified in <a href="http://activity.info" target="_blank">activity.info</a>"""<br>
-    def __init__(self, handle):<br>
-        """Set up the Words activity."""<br>
-        super(WordsActivity, self).__init__(handle)<br>
-        self._logger = logging.getLogger('words-activity')<br>
-<br>
-        from sugar.graphics.menuitem import MenuItem<br>
-        from sugar.graphics.icon import Icon<br>
-<br>
-        # Instantiate a language model.<br>
-        # FIXME: We should ask the language model what langs it supports.<br>
-        self.langs = ["French", "German", "Italian", "Portuguese", "Spanish"]<br>
-        # Initial values.<br>
-        self.fromlang = "English"<br>
-        self.tolang   = "Spanish"<br>
-        import LanguageModel<br>
-        self.languagemodel = LanguageModel.LanguageModel()<br>
-<br>
-        # We do not have collaboration features<br>
-        # make the share option insensitive<br>
-        self.max_participants = 1<br>
-<br>
-        # Main layout.<br>
-        hbox = gtk.HBox(homogeneous=True, spacing=8)<br>
-        vbox = gtk.VBox(spacing=16)<br>
-        vbox.set_border_width(16)<br>
-<br>
-        # Toolbar (compatibility with old-toolbars).<br>
-        try:<br>
-            from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton<br>
-            from sugar.activity.widgets import ActivityButton, StopButton, \<br>
-                                                ShareButton, KeepButton, TitleEntry<br>
-<br>
-            toolbar_box = ToolbarBox()<br>
-            activity_button = ActivityButton(self)<br>
-            toolbar_box.toolbar.insert(activity_button, 0)<br>
-            activity_button.show()<br>
-<br>
-            title_entry = TitleEntry(self)<br>
-            toolbar_box.toolbar.insert(title_entry, -1)<br>
-            title_entry.show()<br>
-<br>
-            share_button = ShareButton(self)<br>
-            toolbar_box.toolbar.insert(share_button, -1)<br>
-            share_button.show()<br>
-<br>
-            separator = gtk.SeparatorToolItem()<br>
-            separator.props.draw = False<br>
-            separator.set_expand(True)<br>
-            toolbar_box.toolbar.insert(separator, -1)<br>
-            separator.show()<br>
-<br>
-            stop_button = StopButton(self)<br>
-            toolbar_box.toolbar.insert(stop_button, -1)<br>
-            stop_button.show()<br>
-<br>
-            self.set_toolbox(toolbar_box)<br>
-            toolbar_box.show()<br>
-        except ImportError:<br>
-            toolbox = ActivityToolbox(self)<br>
-            self.set_toolbox(toolbox)<br>
-            toolbox.show()<br>
-<br>
-        # transbox: <label> - <text entry> - <speak button><br>
-        transbox = gtk.Table()<br>
-        transbox.resize(2, 3)<br>
-        transbox.set_row_spacings(8)<br>
-        transbox.set_col_spacings(12)<br>
-<br>
-        # Labels.<br>
-        label1 = gtk.Label(_("Word") + ':')<br>
-        label1.set_alignment(xalign=0.0, yalign=0.5)<br>
-        label2 = gtk.Label(_("Translation") + ':')<br>
-        label2.set_alignment(xalign=0.0, yalign=0.5)<br>
-<br>
-        # Text entry box to enter word to be translated.<br>
-        self.totranslate = gtk.Entry(max=50)<br>
-        self.totranslate.connect("changed", self.totranslate_cb)<br>
-        self.totranslate.modify_font(pango.FontDescription("Sans 14"))<br>
-<br>
-        # Text entry box to receive word translated.<br>
-        self.translated = gtk.Entry(max=50)<br>
-        self.translated.set_property('editable', False)<br>
-        self.translated.modify_font(pango.FontDescription("Sans 14"))<br>
-<br>
-        # Speak buttons.<br>
-        speak1 = gtk.ToolButton()<br>
-        speak_icon1 = Icon(icon_name='microphone')<br>
-        speak1.set_icon_widget(speak_icon1)<br>
-        speak1.connect("clicked", self.speak1_cb)<br>
-        speak2 = gtk.ToolButton()<br>
-        speak_icon2 = Icon(icon_name='microphone')<br>
-        speak2.set_icon_widget(speak_icon2)<br>
-        speak2.connect("clicked", self.speak2_cb)<br>
-<br>
-        transbox.attach(label1, 0, 1, 0, 1, xoptions=gtk.FILL)<br>
-        transbox.attach(self.totranslate, 1, 2, 0, 1, xoptions=gtk.FILL|gtk.EXPAND)<br>
-        transbox.attach(speak1, 2, 3, 0, 1, xoptions=gtk.FILL)<br>
-<br>
-        transbox.attach(label2, 0, 1, 1, 2, xoptions=gtk.FILL)<br>
-        transbox.attach(self.translated, 1, 2, 1, 2, xoptions=gtk.FILL|gtk.EXPAND)<br>
-        transbox.attach(speak2, 2, 3, 1, 2, xoptions=gtk.FILL)<br>
-<br>
-        vbox.pack_start(transbox, expand=False)<br>
-<br>
-        # The language choice combo boxes.<br>
-        self.lang1combo = gtk.combo_box_new_text()<br>
-        self.lang1combo.append_text("English")<br>
-        self.lang1combo.connect("changed", self.lang1combo_cb)<br>
-        self.lang1combo.set_active(0)<br>
-<br>
-        self.lang2combo = gtk.combo_box_new_text()<br>
-        for x in self.langs:<br>
-            self.lang2combo.append_text(x)<br>
-        self.lang2combo.connect("changed", self.lang2combo_cb)<br>
-        self.lang2combo.set_active(4)<br>
-<br>
-        self.lang1combo.set_size_request(600,50)<br>
-        self.lang2combo.set_size_request(600,50)<br>
-<br>
-        # The "lang1" treeview box<br>
-        self.lang1model = gtk.ListStore(str)<br>
-        lang1view = gtk.TreeView(self.lang1model)<br>
-        lang1view.set_headers_visible(False)<br>
-        lang1cell = gtk.CellRendererText()<br>
-        lang1treecol = gtk.TreeViewColumn("", lang1cell, text=0)<br>
-        lang1view.get_selection().connect("changed", self.lang1sel_cb)<br>
-        lang1view.append_column(lang1treecol)<br>
-        lang1scroll = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)<br>
-        lang1scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)<br>
-        lang1scroll.add(lang1view)<br>
-<br>
-        # The "lang2" box<br>
-        self.lang2model = gtk.ListStore(str)<br>
-        lang2view = gtk.TreeView(self.lang2model)<br>
-        lang2view.set_headers_visible(False)<br>
-        lang2cell = gtk.CellRendererText()<br>
-        lang2treecol = gtk.TreeViewColumn("", lang2cell, text=0)<br>
-        lang2view.get_selection().connect("changed", self.lang2sel_cb)<br>
-        lang2view.append_column(lang2treecol)<br>
-        lang2scroll = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)<br>
-        lang2scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)<br>
-        lang2scroll.add(lang2view)<br>
-<br>
-        lang1_vbox = gtk.VBox(spacing=8)<br>
-        lang1_vbox.pack_start(self.lang1combo, expand=False)<br>
-        lang1_vbox.pack_start(lang1scroll)<br>
-<br>
-        lang2_vbox = gtk.VBox(spacing=8)<br>
-        lang2_vbox.pack_start(self.lang2combo, expand=False)<br>
-        lang2_vbox.pack_start(lang2scroll)<br>
-<br>
-        hbox.pack_start(lang1_vbox)<br>
-        hbox.pack_start(lang2_vbox)<br>
-<br>
-        vbox.pack_start(hbox)<br>
-        self.set_canvas(vbox)<br>
-        self.totranslate.grab_focus()<br>
-        self.show_all()<br>
-<br>
-    def say(self, text, lang):<br>
-        # No Portuguese accent yet.<br>
-        if lang == "portuguese":<br>
-            lang = "spanish"<br>
-        tmpfile = "/tmp/something.wav"<br>
-        subprocess.call(["espeak", text, "-w", tmpfile, "-v", lang])<br>
-        subprocess.call(["aplay", tmpfile])<br>
-        os.unlink(tmpfile)<br>
-<br>
-    def lang1combo_cb(self, combo):<br>
-        pass<br>
-<br>
-    def lang2combo_cb(self, combo):<br>
-        self.languagemodel.SetLanguages("English", self.langs[combo.get_active()])<br>
-<br>
-    def lang1sel_cb(self, column):<br>
-        # FIXME: Complete the text entry box<br>
-        model, _iter = column.get_selected()<br>
-        value = model.get_value(_iter,0)<br>
-        translations = self.languagemodel.GetTranslations(0, value)<br>
-        self.translated.set_text(",".join(translations))<br>
-<br>
-    def lang2sel_cb(self, column):<br>
-        model, _iter = column.get_selected()<br>
-        value = model.get_value(_iter,0)<br>
-        translations = self.languagemodel.GetTranslations(1, value)<br>
-        self.translated.set_text(",".join(translations))<br>
-<br>
-    def speak1_cb(self, button):<br>
-        text = self.totranslate.get_text()<br>
-        lang = self.fromlang.lower()<br>
-        self.say(text, lang)<br>
-<br>
-    def speak2_cb(self, button):<br>
-        text = self.translated.get_text()<br>
-        lang = self.tolang.lower()<br>
-        self.say(text, lang)<br>
-<br>
-    def totranslate_cb(self, totranslate):<br>
-        entry = totranslate.get_text()<br>
-        # Ask for completion suggestions<br>
-        if not entry:<br>
-            return<br>
-<br>
-        (list1, list2) = self.languagemodel.GetSuggestions(entry)<br>
-        self.lang1model.clear()<br>
-        self.lang2model.clear()<br>
-        for x in list1:<br>
-            self.lang1model.append([x])<br>
-        for x in list2:<br>
-            self.lang2model.append([x])<br>
-<br>
-        # If we think we know what the word will be, translate it.<br>
-        if entry in list1 or len(list1) == 1 and len(list2) == 0:<br>
-            langiter = self.lang2combo.get_active()<br>
-            lang = self.langs[langiter].lower()<br>
-            self.fromlang = "English"<br>
-            self.tolang   = lang<br>
-            translations = self.languagemodel.GetTranslations(0, list1[0])<br>
-            self.translated.set_text(",".join(translations))<br>
-<br>
-        elif entry in list2 or len(list1) == 0 and len(list2) == 1:<br>
-            langiter = self.lang2combo.get_active()<br>
-            lang = self.langs[langiter].lower()<br>
-            self.fromlang = lang<br>
-            self.tolang   = "English"<br>
-            translations = self.languagemodel.GetTranslations(1, list2[0])<br>
-            self.translated.set_text(",".join(translations))<br>
-<br>
-############# TEMPLATES AND INLINE FILES ##############<br>
-ACTIVITY_INFO_TEMPLATE = """<br>
-[Activity]<br>
-name = %(title)s<br>
-bundle_id = %(bundle_id)s<br>
-service_name = %(bundle_id)s<br>
-class = %(class)s<br>
-icon = activity-icon<br>
-activity_version = %(version)d<br>
-mime_types = %(mime_types)s<br>
-show_launcher = yes<br>
-%(extra_info)s<br>
-"""<br>
-<br>
-PIPPY_ICON = \<br>
-"""<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  '<a href="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" target="_blank">http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd</a>' [<br>


-       <!ENTITY stroke_color "#010101"><br>
-       <!ENTITY fill_color "#FFFFFF"><br>
-]><svg enable-background="new 0 0 55 55" height="55px" version="1.1" viewBox="0 0 55 55" width="55px" x="0px" xml:space="preserve" xmlns="<a href="http://www.w3.org/2000/svg" target="_blank">http://www.w3.org/2000/svg</a>" xmlns:xlink="<a href="http://www.w3.org/1999/xlink" target="_blank">http://www.w3.org/1999/xlink</a>" y="0px"><g display="block" id="activity-pippy"><br>


-       <path d="M28.497,48.507   c5.988,0,14.88-2.838,14.88-11.185c0-9.285-7.743-10.143-10.954-11.083c-3.549-0.799-5.913-1.914-6.055-3.455   c-0.243-2.642,1.158-3.671,3.946-3.671c0,0,6.632,3.664,12.266,0.74c1.588-0.823,4.432-4.668,4.432-7.32   c0-2.653-9.181-5.719-11.967-5.719c-2.788,0-5.159,3.847-5.159,3.847c-5.574,0-11.149,5.306-11.149,10.612   c0,5.305,5.333,9.455,11.707,10.612c2.963,0.469,5.441,2.22,4.878,5.438c-0.457,2.613-2.995,5.306-8.361,5.306   c-4.252,0-13.3-0.219-14.745-4.079c-0.929-2.486,0.168-5.205,1.562-5.205l-0.027-0.16c-1.42-0.158-5.548,0.16-5.548,5.465   C8.202,45.452,17.347,48.507,28.497,48.507z" fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5"/><br>


-       <path d="M42.579,19.854c-2.623-0.287-6.611-2-7.467-5.022" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-width="3"/><br>
-       <circle cx="35.805" cy="10.96" fill="&stroke_color;" r="1.676"/><br>
-</g></svg><!-- " --><br>
-"""<br>
-<br>
-PIPPY_DEFAULT_ICON = \<br>
-"""<?xml version="1.0" ?><!DOCTYPE svg  PUBLIC '-//W3C//DTD SVG 1.1//EN'  '<a href="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" target="_blank">http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd</a>' [<br>


-       <!ENTITY stroke_color "#010101"><br>
-       <!ENTITY fill_color "#FFFFFF"><br>
-]><svg enable-background="new 0 0 55 55" height="55px" version="1.1"<br>
-     viewBox="0 0 55 55" width="55px" x="0px" y="0px" xml:space="preserve"<br>
-     xmlns="<a href="http://www.w3.org/2000/svg" target="_blank">http://www.w3.org/2000/svg</a>"<br>
-     xmlns:xlink="<a href="http://www.w3.org/1999/xlink" target="_blank">http://www.w3.org/1999/xlink</a>"<br>
-><g display="block" id="activity-icon"><path<br>
-       d="M 28.497,48.507 C 34.485,48.507 43.377,<a href="tel:45.669%2043.377" value="+14566943377">45.669 43.377</a>,37.322 C 43.377,32.6795 41.44125,30.14375 39.104125,28.651125 C 36.767,27.1585 38.482419,26.816027 39.758087,25.662766 C 39.42248,24.275242 37.206195,22.826987 36.262179,21.037968 C 34.005473,20.582994 27.526,19.113 30.314,19.113 C 30.314,19.113 36.946,22.777 42.58,19.853 C 44.168,19.03 47.012,15.185 47.012,12.533 C 47.012,9.88 37.831,6.814 35.045,6.814 C 32.257,6.814 29.886,10.661 29.886,10.661 C 24.312,10.661 12.043878,16.258005 12.043878,21.564005 C 12.043878,24.216505 16.585399,30.069973 19.144694,33.736352 C 22.438716,38.455279 27.257,31.3065 30.444,31.885 C 33.407,<a href="tel:32.354%2035.885" value="+13235435885">32.354 35.885</a>,34.105 35.322,37.323 C 34.865,39.936 32.327,42.629 26.961,42.629 C 22.709,42.629 13.661,42.41 12.216,38.55 C 11.287,36.064 12.384,33.345 13.778,33.345 L 13.751,33.185 C 12.331,33.027 8.203,33.345 8.203,38.65 C 8.202,45.452 17.347,48.507 28.497,48.507 z "<br>


- fill="&fill_color;" stroke="&stroke_color;" stroke-linecap="round" stroke-linejoin="round" stroke-width="3.5" /><br>
-       <path d="M42.579,19.854c-2.623-0.287-6.611-2-7.467-5.022" fill="none" stroke="&stroke_color;" stroke-linecap="round" stroke-width="3"/><br>
-       <circle cx="35.805" cy="10.96" fill="&stroke_color;" r="1.676"/><br>
-</g></svg><!-- " --><br>
-"""<br>
-<br>
-############# ACTIVITY META-INFORMATION ###############<br>
-# this is used by Words to generate a bundle for itself.<br>
-<br>
-def pippy_activity_version():<br>
-    """Returns the version number of the generated activity bundle."""<br>
-    return 1<br>
-def pippy_activity_extra_files():<br>
-    """Returns a map of 'extra' files which should be included in the<br>
-    generated activity bundle."""<br>
-    # Cheat here and generate the map from the fs contents.<br>
-    extra = {}<br>
-    bp = get_bundle_path()<br>
-    for d in [ 'po', 'data' ]: # everybody gets library already<br>
-        for root, dirs, files in os.walk(os.path.join(bp, d)):<br>
-            for name in files:<br>
-                fn = os.path.join(root, name).replace(bp+'/', '')<br>
-                extra[fn] = open(os.path.join(root, name), 'r').read()<br>
-    extra['activity/activity-default.svg'] = PIPPY_DEFAULT_ICON<br>
-    return extra<br>
-def pippy_activity_news():<br>
-    """Return the NEWS file for this activity."""<br>
-    # Cheat again.<br>
-    return open(os.path.join(get_bundle_path(), 'NEWS')).read()<br>
-def pippy_activity_icon():<br>
-    """Return an SVG document specifying the icon for this activity."""<br>
-    return PIPPY_ICON<br>
-def pippy_activity_class():<br>
-    """Return the class which should be started to run this activity."""<br>
-    return 'pippy_app.WordsActivity'<br>
-def pippy_activity_bundle_id():<br>
-    """Return the bundle_id for the generated activity."""<br>
-    return 'org.laptop.Words'<br>
-def pippy_activity_mime_types():<br>
-    """Return the mime types handled by the generated activity, as a list."""<br>
-    return 'text/x-python'<br>
diff --git a/wordsactivity.py b/wordsactivity.py<br>
new file mode 100644<br>
index 0000000..afa7369<br>
--- /dev/null<br>
+++ b/wordsactivity.py<br>
@@ -0,0 +1,267 @@<br>
+# Copyright 2008 Chris Ball.<br>
+#<br>
+# This program is free software; you can redistribute it and/or modify<br>
+# it under the terms of the GNU General Public License as published by<br>
+# the Free Software Foundation, either version 2 of the License, or<br>
+# (at your option) any later version.<br>
+#<br>
+# This program is distributed in the hope that it will be useful,<br>
+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
+# GNU General Public License for more details.<br>
+#<br>
+# You should have received a copy of the GNU General Public License<br>
+# along with this program; if not, write to the Free Software<br>
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br>
+<br>
+"""Words Activity: A multi-lingual dictionary with speech synthesis."""<br>
+"""Actividad Palabras: Un diccionario multi-lengua con sintesis de habla"""<br>
+<br>
+import gtk<br>
+import logging<br>
+import pango<br>
+import os<br>
+import subprocess<br>
+<br>
+from gettext import gettext as _<br>
+<br>
+from sugar.activity import activity<br>
+from sugar.activity.activity import ActivityToolbox, \<br>
+     get_bundle_path, get_bundle_name<br>
+<br>
+from sugar.graphics.icon import Icon<br>
+OLD_TOOLBARS = False<br>
+try:<br>
+    from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton<br>
+    from sugar.activity.widgets import ActivityButton, StopButton, \<br>
+                                        ShareButton, KeepButton, TitleEntry<br>
+except ImportError:<br>
+    OLD_TOOLBARS = True<br>
+<br>
+# logging<br>
+logger = logging.getLogger('Words')<br>
+<br>
+<br>
+class WordsActivity(activity.Activity):<br>
+    """Words Activity as specified in <a href="http://activity.info" target="_blank">activity.info</a>"""<br>
+<br>
+    def __init__(self, handle):<br>
+        """Set up the Words activity."""<br>
+        super(WordsActivity, self).__init__(handle)<br>
+        self._logger = logging.getLogger('words-activity')<br>
+<br>
+        # Instantiate a language model.<br>
+        # FIXME: We should ask the language model what langs it supports.<br>
+        self.langs = ["French", "German", "Italian", "Portuguese", "Spanish"]<br>
+        # Initial values.<br>
+        self.fromlang = "English"<br>
+        self.tolang   = "Spanish"<br>
+        import LanguageModel<br>
+        self.languagemodel = LanguageModel.LanguageModel()<br>
+<br>
+        # We do not have collaboration features<br>
+        # make the share option insensitive<br>
+        self.max_participants = 1<br>
+<br>
+        # Main layout.<br>
+        hbox = gtk.HBox(homogeneous=True, spacing=8)<br>
+        vbox = gtk.VBox(spacing=16)<br>
+        vbox.set_border_width(16)<br>
+<br>
+        # Toolbar (compatibility with old-toolbars).<br>
+        if not OLD_TOOLBARS:<br>
+            toolbar_box = ToolbarBox()<br>
+            activity_button = ActivityButton(self)<br>
+            toolbar_box.toolbar.insert(activity_button, 0)<br>
+            activity_button.show()<br>
+<br>
+            title_entry = TitleEntry(self)<br>
+            toolbar_box.toolbar.insert(title_entry, -1)<br>
+            title_entry.show()<br>
+<br>
+            share_button = ShareButton(self)<br>
+            toolbar_box.toolbar.insert(share_button, -1)<br>
+            share_button.show()<br>
+<br>
+            separator = gtk.SeparatorToolItem()<br>
+            separator.props.draw = False<br>
+            separator.set_expand(True)<br>
+            toolbar_box.toolbar.insert(separator, -1)<br>
+            separator.show()<br>
+<br>
+            stop_button = StopButton(self)<br>
+            toolbar_box.toolbar.insert(stop_button, -1)<br>
+            stop_button.show()<br>
+<br>
+            self.set_toolbox(toolbar_box)<br>
+            toolbar_box.show()<br>
+        else:<br>
+            toolbox = ActivityToolbox(self)<br>
+            self.set_toolbox(toolbox)<br>
+            toolbox.show()<br>
+<br>
+        # transbox: <label> - <text entry> - <speak button><br>
+        transbox = gtk.Table()<br>
+        transbox.resize(2, 3)<br>
+        transbox.set_row_spacings(8)<br>
+        transbox.set_col_spacings(12)<br>
+<br>
+        # Labels.<br>
+        label1 = gtk.Label(_("Word") + ':')<br>
+        label1.set_alignment(xalign=0.0, yalign=0.5)<br>
+        label2 = gtk.Label(_("Translation") + ':')<br>
+        label2.set_alignment(xalign=0.0, yalign=0.5)<br>
+<br>
+        # Text entry box to enter word to be translated.<br>
+        self.totranslate = gtk.Entry(max=50)<br>
+        self.totranslate.connect("changed", self.totranslate_cb)<br>
+        self.totranslate.modify_font(pango.FontDescription("Sans 14"))<br>
+<br>
+        # Text entry box to receive word translated.<br>
+        self.translated = gtk.Entry(max=50)<br>
+        self.translated.set_property('editable', False)<br>
+        self.translated.modify_font(pango.FontDescription("Sans 14"))<br>
+<br>
+        # Speak buttons.<br>
+        speak1 = gtk.ToolButton()<br>
+        speak_icon1 = Icon(icon_name='microphone')<br>
+        speak1.set_icon_widget(speak_icon1)<br>
+        speak1.connect("clicked", self.speak1_cb)<br>
+        speak2 = gtk.ToolButton()<br>
+        speak_icon2 = Icon(icon_name='microphone')<br>
+        speak2.set_icon_widget(speak_icon2)<br>
+        speak2.connect("clicked", self.speak2_cb)<br>
+<br>
+        transbox.attach(label1, 0, 1, 0, 1, xoptions=gtk.FILL)<br>
+        transbox.attach(self.totranslate, 1, 2, 0, 1, xoptions=gtk.FILL|gtk.EXPAND)<br>
+        transbox.attach(speak1, 2, 3, 0, 1, xoptions=gtk.FILL)<br>
+<br>
+        transbox.attach(label2, 0, 1, 1, 2, xoptions=gtk.FILL)<br>
+        transbox.attach(self.translated, 1, 2, 1, 2, xoptions=gtk.FILL|gtk.EXPAND)<br>
+        transbox.attach(speak2, 2, 3, 1, 2, xoptions=gtk.FILL)<br>
+<br>
+        vbox.pack_start(transbox, expand=False)<br>
+<br>
+        # The language choice combo boxes.<br>
+        self.lang1combo = gtk.combo_box_new_text()<br>
+        self.lang1combo.append_text("English")<br>
+        self.lang1combo.connect("changed", self.lang1combo_cb)<br>
+        self.lang1combo.set_active(0)<br>
+<br>
+        self.lang2combo = gtk.combo_box_new_text()<br>
+        for x in self.langs:<br>
+            self.lang2combo.append_text(x)<br>
+        self.lang2combo.connect("changed", self.lang2combo_cb)<br>
+        self.lang2combo.set_active(4)<br>
+<br>
+        self.lang1combo.set_size_request(600,50)<br>
+        self.lang2combo.set_size_request(600,50)<br>
+<br>
+        # The "lang1" treeview box<br>
+        self.lang1model = gtk.ListStore(str)<br>
+        lang1view = gtk.TreeView(self.lang1model)<br>
+        lang1view.set_headers_visible(False)<br>
+        lang1cell = gtk.CellRendererText()<br>
+        lang1treecol = gtk.TreeViewColumn("", lang1cell, text=0)<br>
+        lang1view.get_selection().connect("changed", self.lang1sel_cb)<br>
+        lang1view.append_column(lang1treecol)<br>
+        lang1scroll = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)<br>
+        lang1scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)<br>
+        lang1scroll.add(lang1view)<br>
+<br>
+        # The "lang2" box<br>
+        self.lang2model = gtk.ListStore(str)<br>
+        lang2view = gtk.TreeView(self.lang2model)<br>
+        lang2view.set_headers_visible(False)<br>
+        lang2cell = gtk.CellRendererText()<br>
+        lang2treecol = gtk.TreeViewColumn("", lang2cell, text=0)<br>
+        lang2view.get_selection().connect("changed", self.lang2sel_cb)<br>
+        lang2view.append_column(lang2treecol)<br>
+        lang2scroll = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)<br>
+        lang2scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)<br>
+        lang2scroll.add(lang2view)<br>
+<br>
+        lang1_vbox = gtk.VBox(spacing=8)<br>
+        lang1_vbox.pack_start(self.lang1combo, expand=False)<br>
+        lang1_vbox.pack_start(lang1scroll)<br>
+<br>
+        lang2_vbox = gtk.VBox(spacing=8)<br>
+        lang2_vbox.pack_start(self.lang2combo, expand=False)<br>
+        lang2_vbox.pack_start(lang2scroll)<br>
+<br>
+        hbox.pack_start(lang1_vbox)<br>
+        hbox.pack_start(lang2_vbox)<br>
+<br>
+        vbox.pack_start(hbox)<br>
+        self.set_canvas(vbox)<br>
+        self.totranslate.grab_focus()<br>
+        self.show_all()<br>
+<br>
+    def say(self, text, lang):<br>
+        # No Portuguese accent yet.<br>
+        if lang == "portuguese":<br>
+            lang = "spanish"<br>
+        tmpfile = "/tmp/something.wav"<br>
+        subprocess.call(["espeak", text, "-w", tmpfile, "-v", lang])<br>
+        subprocess.call(["aplay", tmpfile])<br>
+        os.unlink(tmpfile)<br>
+<br>
+    def lang1combo_cb(self, combo):<br>
+        pass<br>
+<br>
+    def lang2combo_cb(self, combo):<br>
+        self.languagemodel.SetLanguages("English", self.langs[combo.get_active()])<br>
+<br>
+    def lang1sel_cb(self, column):<br>
+        # FIXME: Complete the text entry box<br>
+        model, _iter = column.get_selected()<br>
+        value = model.get_value(_iter,0)<br>
+        translations = self.languagemodel.GetTranslations(0, value)<br>
+        self.translated.set_text(",".join(translations))<br>
+<br>
+    def lang2sel_cb(self, column):<br>
+        model, _iter = column.get_selected()<br>
+        value = model.get_value(_iter,0)<br>
+        translations = self.languagemodel.GetTranslations(1, value)<br>
+        self.translated.set_text(",".join(translations))<br>
+<br>
+    def speak1_cb(self, button):<br>
+        text = self.totranslate.get_text()<br>
+        lang = self.fromlang.lower()<br>
+        self.say(text, lang)<br>
+<br>
+    def speak2_cb(self, button):<br>
+        text = self.translated.get_text()<br>
+        lang = self.tolang.lower()<br>
+        self.say(text, lang)<br>
+<br>
+    def totranslate_cb(self, totranslate):<br>
+        entry = totranslate.get_text()<br>
+        # Ask for completion suggestions<br>
+        if not entry:<br>
+            return<br>
+<br>
+        (list1, list2) = self.languagemodel.GetSuggestions(entry)<br>
+        self.lang1model.clear()<br>
+        self.lang2model.clear()<br>
+        for x in list1:<br>
+            self.lang1model.append([x])<br>
+        for x in list2:<br>
+            self.lang2model.append([x])<br>
+<br>
+        # If we think we know what the word will be, translate it.<br>
+        if entry in list1 or len(list1) == 1 and len(list2) == 0:<br>
+            langiter = self.lang2combo.get_active()<br>
+            lang = self.langs[langiter].lower()<br>
+            self.fromlang = "English"<br>
+            self.tolang   = lang<br>
+            translations = self.languagemodel.GetTranslations(0, list1[0])<br>
+            self.translated.set_text(",".join(translations))<br>
+<br>
+        elif entry in list2 or len(list1) == 0 and len(list2) == 1:<br>
+            langiter = self.lang2combo.get_active()<br>
+            lang = self.langs[langiter].lower()<br>
+            self.fromlang = lang<br>
+            self.tolang   = "English"<br>
+            translations = self.languagemodel.GetTranslations(1, list2[0])<br>
+            self.translated.set_text(",".join(translations))<br>
<font color="#888888">--<br>
1.7.4.4<br>
<br>
</font></blockquote></div><br><div>Thanks..applied as</div><div><br></div><div><a href="http://git.sugarlabs.org/words-activity/words-activity/commit/95d72bf197c0196b690a821f21f4ce37e79fe088">http://git.sugarlabs.org/words-activity/words-activity/commit/95d72bf197c0196b690a821f21f4ce37e79fe088</a></div>

<div><br></div><div><br></div>