cairo-dock-team team mailing list archive
-
cairo-dock-team team
-
Mailing list archive
-
Message #02038
[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)
Refactoring the code a lil bit. The user can define the resulting language by configuration file, so it won't change every time the plug-in reloads. doCkranslator now translates from lots of languages, and it can be defined by the configuration file. Input box now shows a label with source and destination languages.
--
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator/+merge/30144
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.
=== modified file 'doCkranslator/Changelog.txt'
--- doCkranslator/Changelog.txt 2010-07-16 00:57:38 +0000
+++ doCkranslator/Changelog.txt 2010-07-16 20:08:40 +0000
@@ -1,2 +1,4 @@
+0.0.4:(July/16/2010): doCkranslator now translates from lots of languages, and it can be defined by the configuration file. Input box now shows a label with source and destination languages.
+0.0.3:(July/16/2010): Refactoring the code a lil bit. The user can define the resulting language by configuration file, so it won't change every time the plug-in reloads.
0.0.2: (July/15/2010): Fixing a lack of UTF-8 URL encoding, and the space encoding. Creating the "To" sub-menu instead of using the default one to place the target languages. Middle-click now fills the input dialog with the clipboard content resulting in a faster way to use the applet, thanks SQP for this suggestion.
0.0.1: (July/14/2010): doCkranslator has begun here. It translates from English to a lot of languages.
=== modified file 'doCkranslator/auto-load.conf'
--- doCkranslator/auto-load.conf 2010-07-16 00:57:38 +0000
+++ doCkranslator/auto-load.conf 2010-07-16 20:08:40 +0000
@@ -4,10 +4,10 @@
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\nScroll up/down over the icon to choose the resulting language\nTo enter the text to be translated there is two ways\n(I) Left-click on the icon; type your text and validate\n(II) Middle click on the icon, the text contained in the clipboard will be automatically copied to input dialog; validate\nTranslated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
+description = doCkranslator translates from lots of languages to lots of languages\nTo choose the source language Right-click on the icon -> doCkranslator -> Configuration\nTo choose the destination language: (I) Scroll up/down over the icon\n (II) Right-click on the icon -> To -> Choose the destination language\nTo translate: (I) Left-click on the icon; type your text and validate\n (II) Copy the text, middle click on the icon, the text contained in the clipboard will be automatically copied into input dialog; validate\nTranslated text will be shown as a dialog 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.2
+version = 0.0.4
=== modified file 'doCkranslator/doCkranslator'
--- doCkranslator/doCkranslator 2010-07-16 00:57:38 +0000
+++ doCkranslator/doCkranslator 2010-07-16 20:08:40 +0000
@@ -16,14 +16,17 @@
# 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 resulting language
-# To enter the text to be translated there is two ways
+# doCkranslator translates from lots of languages to lots of languages
+# To choose the source language Right-click on the icon -> doCkranslator -> Configuration
+# To choose the destination language:
+# (I) Scroll up/down over the icon
+# (II) Right-click on the icon -> To -> Choose the destination language
+# To translate:
# (I) Left-click on the icon; type your text and validate
-# (II) Middle click on the icon, the text contained in the clipboard will be automatically copied to input dialog; validate
+# (II) Copy the text, middle click on the icon, the text contained in the clipboard will be automatically copied into input dialog; validate
# Translated text will be shown as a dialog and be available in the clipboard, just press Ctrl+v to have it
-import gobject, glib, dbus, os.path, urllib, pygtk, gtk
+import gobject, glib, dbus, os.path, urllib, pygtk, gtk, ConfigParser
from dbus.mainloop.glib import DBusGMainLoop
from sgmllib import SGMLParser
from urllib import FancyURLopener
@@ -31,6 +34,22 @@
DBusGMainLoop(set_as_default=True)
+class doCkranslator:
+ def start(self):
+ bus = dbus.SessionBus()
+ 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
+ applet_object = bus.get_object("org.cairodock.CairoDock", applet_path)
+ icon = dbus.Interface(applet_object, "org.cairodock.CairoDock.applet")
+ configuration = os.path.expanduser("~/.config/cairo-dock/current_theme/plug-ins/%s/%s.conf") % (applet_name, applet_name)
+
+ applet = Applet(icon, configuration)
+ applet.start()
+
+ loop = gobject.MainLoop()
+ loop.run()
+ sys.exit(0)
+
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'
@@ -81,43 +100,48 @@
class Applet:
- def __init__(self):
- self.icon = None
+ def __init__(self, icon, configuration):
+ self.icon = icon
+ self.configuration = configuration # configuration file
self.translated_text = ""
- self.destinies = []
- self.source = Language('English', 'en') # default source language
- self.destiny = Language('Portuguese', 'pt') # default destiny language
+ self.source = None # get it from configuration file
+ self.sources = [] # list of possible source languages
+ self.destiny = None # get it from configuration file
+ self.destinies = [] # list of possible resulting languages
self.scroll_destiny_language = 0
self.dialog_active_time = 5 # time in seconds that the dialog window will be active
- def inform_start_of_waiting_process(self):
- self.icon.SetQuickInfo("...")
-
- def inform_end_of_waiting_process(self):
- self.icon.SetQuickInfo("")
-
- def inform_current_destiny_language(self):
- self.icon.SetQuickInfo(self.destiny.name)
+ def start(self):
+ self.read_languages_file()
+ self.set_configuration_parameters()
+ self.connect_to_callbacks()
+
+ def connect_to_callbacks(self):
+ 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)
+ self.icon.connect_to_signal("on_menu_select", self.action_on_menu_select)
+ self.icon.connect_to_signal("on_middle_click", self.action_on_middle_click)
+ self.icon.connect_to_signal("on_reload_module", self.action_on_reload)
+
+ def set_configuration_parameters(self):
+ reader = ConfigParser.RawConfigParser()
+ reader.read(self.configuration)
+ slang = reader.getint('Configuration', 'source') # get the source language position in the list
+ dlang = reader.getint('Configuration', 'destiny') # get the destination language position in the list
+ self.source = self.sources[slang]
+ self.destiny = self.destinies[dlang] # first set the destination language ...
+ self.inform_current_destiny_language() # ... and show it
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() # 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 get_from_clipboard(self):
- clipboard = gtk.clipboard_get()
- return clipboard.wait_for_text()
+ name, abbrv = splited[0], splited[1]
+ self.sources.append(Language(name, abbrv)) # e.g, Language("English", "en")
+ self.destinies.append(Language(name, abbrv)) # e.g, Language("Portuguese", "pt")
def translate(self, sentence, source, destiny):
print "sentence: %s (from: %s to: %s)" % (sentence, source, destiny)
@@ -143,7 +167,8 @@
self.inform_current_destiny_language()
def ask_text(self, default=""):
- self.icon.AskText("Translate:", default) # heya user, tell me what do you wanna translate
+ label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)
+ self.icon.AskText(label, default) # heya user, tell me what do you wanna translate
def action_on_answer(self, answer):
if answer:
@@ -186,23 +211,26 @@
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)
- self.icon.connect_to_signal("on_menu_select", self.action_on_menu_select)
- self.icon.connect_to_signal("on_middle_click", self.action_on_middle_click)
+ def action_on_reload(self, config_has_changed):
+ if config_has_changed:
+ self.set_configuration_parameters()
+
+ def set_to_clipboard(self, sentence):
+ clipboard = gtk.clipboard_get() # get the clipboard
+ clipboard.set_text(sentence) # set the clipboard the translated text
+
+ def get_from_clipboard(self):
+ clipboard = gtk.clipboard_get()
+ return clipboard.wait_for_text()
+
+ def inform_start_of_waiting_process(self):
+ self.icon.SetQuickInfo("...")
+
+ def inform_end_of_waiting_process(self):
+ self.icon.SetQuickInfo("")
+
+ def inform_current_destiny_language(self):
+ self.icon.SetQuickInfo(self.destiny.name)
if __name__ == '__main__':
- Applet().start()
- loop = gobject.MainLoop()
- loop.run()
- print "doCkranslator is ending"
- sys.exit(0)
+ doCkranslator().start()
=== modified file 'doCkranslator/doCkranslator.conf'
--- doCkranslator/doCkranslator.conf 2010-07-16 00:57:38 +0000
+++ doCkranslator/doCkranslator.conf 2010-07-16 20:08:40 +0000
@@ -1,4 +1,4 @@
-#!en;0.0.2
+#!en;0.0.4
#[gtk-about]
[Icon]
@@ -90,6 +90,7 @@
#[gtk-preferences]
[Configuration]
-#h+[/usr/share/cairo-dock/gauges;gauges;gauges] Choose one of the available themes :/
-theme = Turbo-night
-
+#l[Afrikaans;Albanian;Arabic;Armenian;Azerbaijani;Basque;Belarusian;Bulgarian;Catalan;Chinese;Croatian;Czech;Danish;Dutch;English;Estonian;Filipino;Finnish;French;Galician;Georgian;German;Greek;Haitian;Hebrew;Hindi;Hungarian;Icelandic;Indonesian;Irish;Italian;Japanese;Korean;Latvian;Lithuanian;Macedonian;Malay;Maltese;Norwegian;Persian;Polish;Portuguese;Romanian;Russian;Serbian;Slovak;Slovenian;Spanish;Swahili;Swedish;Thai;Turkish;Ukrainian;Urdu;Vietnamese;Welsh;Yiddish] Translate from:
+source = 14
+#l[Afrikaans;Albanian;Arabic;Armenian;Azerbaijani;Basque;Belarusian;Bulgarian;Catalan;Chinese;Croatian;Czech;Danish;Dutch;English;Estonian;Filipino;Finnish;French;Galician;Georgian;German;Greek;Haitian;Hebrew;Hindi;Hungarian;Icelandic;Indonesian;Irish;Italian;Japanese;Korean;Latvian;Lithuanian;Macedonian;Malay;Maltese;Norwegian;Persian;Polish;Portuguese;Romanian;Russian;Serbian;Slovak;Slovenian;Spanish;Swahili;Swedish;Thai;Turkish;Ukrainian;Urdu;Vietnamese;Welsh;Yiddish]Translate to:
+destiny = 41
Follow ups