← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator into lp:cairo-dock-plug-ins-extras

 

Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator into lp:cairo-dock-plug-ins-extras.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)


This applet provides a translator tool using the Google Translator service
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator/+merge/29944
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator into lp:cairo-dock-plug-ins-extras.
=== added directory 'doCkranslator'
=== added file 'doCkranslator/.languages'
--- doCkranslator/.languages	1970-01-01 00:00:00 +0000
+++ doCkranslator/.languages	2010-07-15 01:01:38 +0000
@@ -0,0 +1,57 @@
+Afrikaans af
+Albanian sq
+Arabic ar
+Armenian hy
+Azerbaijani az
+Basque eu
+Belarusian be
+Bulgarian bg
+Catalan ca
+Chinese zh-CN
+Croatian hr
+Czech cs
+Danish da
+Dutch nl
+English en
+Estonian et
+Filipino tl
+Finnish fi
+French fr
+Galician gl
+Georgian ka
+German de
+Greek el
+Haitian Creole ht
+Hebrew iw
+Hindi hi
+Hungarian hu
+Icelandic is
+Indonesian id
+Irish ga
+Italian it
+Japanese ja
+Korean ko
+Latvian lv
+Lithuanian lt
+Macedonian mk
+Malay ms
+Maltese mt
+Norwegian no
+Persian fa
+Polish pl
+Portuguese pt
+Romanian ro
+Russian ru
+Serbian sr
+Slovak sk
+Slovenian sl
+Spanish es
+Swahili sw
+Swedish sv
+Thai th
+Turkish tr
+Ukrainian uk
+Urdu ur
+Vietnamese vi
+Welsh cy
+Yiddish yi

=== added file 'doCkranslator/Changelog.txt'
--- doCkranslator/Changelog.txt	1970-01-01 00:00:00 +0000
+++ doCkranslator/Changelog.txt	2010-07-15 01:01:38 +0000
@@ -0,0 +1,1 @@
+0.0.1: (July/14/2010: doCkranslator has begun here. It translates from English to a lot of languages.

=== added file 'doCkranslator/README'
--- doCkranslator/README	1970-01-01 00:00:00 +0000
+++ doCkranslator/README	2010-07-15 01:01:38 +0000
@@ -0,0 +1,8 @@
+In order to use doCkranslator applet it is necessary to have PyGTK.
+
+# Contact me
+
+Any doubt, suggestion or anything else, except asking for some money, I would be pleased to received a message from you. :¬)
+
+Author: Eduardo Mucelli Rezende Oliveira
+E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx

=== added file 'doCkranslator/auto-load.conf'
--- doCkranslator/auto-load.conf	1970-01-01 00:00:00 +0000
+++ doCkranslator/auto-load.conf	2010-07-15 01:01:38 +0000
@@ -0,0 +1,13 @@
+[Register]
+
+# Author of the applet
+author = Eduardo Mucelli Rezende Oliveira
+
+# A short description of the applet and how to use it.
+description = This applet provides a translator tool using the Google Translator service\nAt this point, the doCkranslator translates from English to lots of languages\n    Scroll up/down over the icon to choose the source language\n    Left-click on the icon\n    Type your text and validate\n    Translated text will be shown and be available in the clipboard, just press Ctrl+v to have it
+
+# Category of the applet : 2 = accessory, 3 = Desktop, 4 = Controler
+category = 2
+
+# Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file.
+version = 0.0.1

=== added file 'doCkranslator/doCkranslator'
--- doCkranslator/doCkranslator	1970-01-01 00:00:00 +0000
+++ doCkranslator/doCkranslator	2010-07-15 01:01:38 +0000
@@ -0,0 +1,182 @@
+#!/usr/bin/python
+
+# This is a part of the external doCkranslator applet for Cairo-Dock
+#
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+
+# This applet provides a translator tool using the Google Translator service
+#    At this point, the doCkranslator translates from English to lots of languages
+#    Scroll up/down over the icon to choose the source language
+#    Left-click on the icon
+#    Type your text and validate
+#    Translated text will be shown and be available in the clipboard, just press Ctrl+v to have it
+
+import gobject
+import glib
+import dbus
+import os.path
+from dbus.mainloop.glib import DBusGMainLoop
+from sgmllib import SGMLParser
+import urllib
+from urllib import FancyURLopener
+import csv
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+DBusGMainLoop(set_as_default=True)
+
+class AgentOpener(FancyURLopener):
+    """Masked user-agent otherwise the access would be forbidden"""
+    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
+
+class TranslatorParser(SGMLParser):
+    def reset(self):                              
+        SGMLParser.reset(self)
+        self.translated_content = ""
+        self.inside_a_element = 0
+
+    def start_span(self, attrs):                  
+        for name, value in attrs:
+            if name == "id" and value == "result_box":
+                self.inside_a_element = 1
+    
+    def end_span(self):
+        self.inside_a_element = 0
+
+    def handle_data(self, text):
+        if self.inside_a_element:
+            self.translated_content = text
+
+    def parse(self, page):
+        self.feed(page)
+        self.close()
+
+class Interface:
+    """ Create a interface between the Applet and Parser
+        This module receives, from the Applet's user, the text to be translated and
+        access the parser to get the context of the Google Translator for this text"""
+    def __init__(self, text_to_be_translated):
+        self.text_to_be_translated = text_to_be_translated
+        
+    def translate_it(self, source, destiny):
+        parser = TranslatorParser()                                                     # create the parser
+        opener = AgentOpener()                                                          # opens the web connection with masked user-agent
+        url = "http://translate.google.com/?hl=en&layout=1&eotf=0&sl=%s&tl=%s&q=%s"; % (source, destiny, urllib.quote(self.text_to_be_translated))
+        page = opener.open(url)                                                         # get the HTML
+        parser.parse(page.read())                                                       # feed the parser to get the specific content: translated text
+        page.close()                                                                    # lets close the page connection
+        self.text_to_be_translated = parser.translated_content                          # from the parser, we get the translated content
+        return self.text_to_be_translated
+
+class Language:
+    def __init__(self, name, abbrv):
+        self.name = name
+        self.abbrv = abbrv
+
+class Applet:
+
+    def __init__(self):
+        self.icon = None
+        self.translated_text = ""
+        self.destinies = []
+        self.source = Language('English', 'en')                                         # default source language
+        self.destiny = Language('Portuguese', 'pt')                                     # default destiny language
+        self.scroll_destiny_language = 0
+        self.dialog_active_time = 5                                                     # time in seconds that the dialog window will be active
+
+    def inform_current_destiny_language(self, current):
+        self.icon.SetQuickInfo(current)
+
+    def read_languages_file(self):
+        """Read the languages file formated as Name<space>Abbreviation, e.g, Portuguese pt"""
+        f = open('.languages', "rb")
+        for line in f:
+            splited = line.split()                                                      # split the line by space token
+            self.destinies.append(Language(splited[0], splited[1]))                     # e.g, Language("Portuguese", "pt")
+
+    def start(self):
+        self.read_languages_file()
+        self.connect_to_dock()
+        self.inform_current_destiny_language(self.destiny.name)                         # necessary to connect to the dock first!
+
+    def set_to_clipboard(self, sentence):
+        clipboard = gtk.clipboard_get()                                                 # get the clipboard
+        clipboard.set_text(sentence)                                                    # set the clipboard the translated text
+
+    def translate(self, sentence, source, destiny):
+        print "sentence: %s (from: %s to: %s)" % (sentence, source, destiny)
+        interface = Interface(sentence)
+        translated = interface.translate_it(source, destiny)
+        self.icon.ShowDialog(translated, self.dialog_active_time)
+        self.set_to_clipboard(translated)
+        print "translated: " + translated
+
+    def switch_destiny_language(self, index):
+        max_index = len(self.destinies) - 1
+        if index < 0:
+            index = 0									            					# keep the lower limit
+        if index > max_index:
+    		index = max_index - 1
+        self.destiny = self.destinies[index]
+        self.inform_current_destiny_language(self.destiny.name)
+
+    def action_on_answer(self, answer):
+    	self.translate(answer, self.source.abbrv, self.destiny.abbrv)                   # what to be translated, the source and destination languages
+
+    def action_on_click(self, param):
+        self.icon.AskText("Translate:", "")                                             # heya user, tell me what do you wanna translate
+
+    def action_on_scroll(self, scroll_up):
+        if scroll_up:
+            self.scroll_destiny_language -= 1
+            self.switch_destiny_language (self.scroll_destiny_language)
+        else:
+            self.scroll_destiny_language += 1
+            self.switch_destiny_language (self.scroll_destiny_language)
+	    
+    def action_on_build_menu(self):
+        items = []
+        index = 0
+        for language in self.destinies:
+            item = {}
+            item['type'] = 0
+            item['label'] = language.name
+            item['menu'] = 1
+            item['id'] = index
+            index += 1
+            items.append(item)
+        try:
+            self.icon.AddMenuItems(items)
+        except TypeError:
+            print "AddMenuItems method is not available"
+
+    def connect_to_dock(self):
+        applet_name = os.path.basename(os.path.abspath("."))                            # name of the applet must the same as the folder
+        applet_path = "/org/cairodock/CairoDock/%s" % applet_name                       # path where our object is stored on the bus
+        bus = dbus.SessionBus()
+        applet_object = bus.get_object("org.cairodock.CairoDock", applet_path)
+        self.icon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet")     # representes the applet, icon inside the dock or a desklet
+
+        self.icon.connect_to_signal("on_click", self.action_on_click)
+        self.icon.connect_to_signal("on_answer", self.action_on_answer)
+        self.icon.connect_to_signal("on_build_menu", self.action_on_build_menu)
+        self.icon.connect_to_signal("on_scroll", self.action_on_scroll)
+
+if __name__ == '__main__':
+    Applet().start()
+    loop = gobject.MainLoop()
+    loop.run()
+    print "doCkranslator is ending"
+    sys.exit(0)

=== added file 'doCkranslator/doCkranslator.conf'
--- doCkranslator/doCkranslator.conf	1970-01-01 00:00:00 +0000
+++ doCkranslator/doCkranslator.conf	2010-07-15 01:01:38 +0000
@@ -0,0 +1,95 @@
+#!en;0.0.1
+
+#[gtk-about]
+[Icon]
+#j+[0;128] Desired icon size for this applet
+#{Set to 0 to use the default applet size}
+icon size = 0;0
+
+#s Name of the icon as it will appear in its label in the dock :
+name = doCkranslator
+
+#S+ Image's filename :
+#{Let empty to use the default one.}
+icon = 
+
+#d Name of the dock it belongs to:
+dock name = 
+
+order=
+
+#F[Applet's Handbook]
+frame_hand=
+#A
+handbook=doCkranslator
+
+#[gtk-convert]
+[Desklet]
+
+#j+[48;512] Desklet's dimension (width x height) :
+#{Depending on your WindowManager, you can resize it with ALT + middle_click or ALT + left_click for exemple.}
+size = 164;96
+
+#i[-2048;2048] Desklet's position (x ; y) :
+#{Depending on your WindowManager, you can move it with ALT + left_click}
+x position=0
+#i[-2048;2048] ...
+y position=0
+
+#b Is detached from the dock ?
+initially detached=false
+#l[Normal;Keep above;Keep below;On Widget Layer;Reserve space] Accessibility :
+#{for CompizFusion's "widget layer", set behaviour in Compiz to: (class=Cairo-dock & type=utility)}
+accessibility=0
+#b Should be visible on all desktops ?
+sticky=true
+
+#b Lock position ?
+#{If locked, the desklet can't be moved by simply dragging it with the left mouse button. Of course you can still move it with ALT + left_click.}
+locked = false
+
+#I[-180;180] Rotation :
+#{in degrees.}
+rotation = 0
+
+use size=
+
+#F[Decorations;gtk-orientation-portrait]
+frame_deco=
+
+#o+ Choose a decoration theme for this desklet :
+#{Choose the 'personnal' one to define your own decorations below.}
+decorations = default
+
+#v
+sep_deco =
+
+#S+ Background image :
+#{It's an image that will be displayed below the drawings, like a frame for exemple. Let empty to not use any.}
+bg desklet =
+#e+[0;1] Background tansparency :
+bg alpha = 1
+#i+[0;256] Left offset :
+#{in pixels. Use this to adjust the left position of the drawings.}
+left offset = 0
+#i+[0;256] Top offset :
+#{in pixels. Use this to adjust the top position of the drawings.}
+top offset = 0
+#i+[0;256] Right offset :
+#{in pixels. Use this to adjust the right position of the drawings.}
+right offset = 0
+#i+[0;256] Bottom offset :
+#{in pixels. Use this to adjust the bottom position of the drawings.}
+bottom offset = 0
+#S+ Foreground image :
+#{It's an image that will be displayed above the drawings, like a reflect for exemple. Let empty to not use any.}
+fg desklet =
+#e+[0;1] Foreground tansparency :
+fg alpha = 1
+
+#[gtk-preferences]
+[Configuration]
+
+#h+[/usr/share/cairo-dock/gauges;gauges;gauges] Choose one of the available themes :/
+theme = Turbo-night
+

=== added file 'doCkranslator/icon'
Binary files doCkranslator/icon	1970-01-01 00:00:00 +0000 and doCkranslator/icon	2010-07-15 01:01:38 +0000 differ
=== added file 'doCkranslator/preview'
Binary files doCkranslator/preview	1970-01-01 00:00:00 +0000 and doCkranslator/preview	2010-07-15 01:01:38 +0000 differ

Follow ups