Author: remi
Date: 2009-03-28 19:11:01 +0100 (Sat, 28 Mar 2009)
New Revision: 4241
Removed:
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/SimpleGadget/
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/filters/
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/util/
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/ClipboardTranslator.py
Log:
* now uses the shared modules by the Tux Droid server.
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/ClipboardTranslator.py
===================================================================
---
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/ClipboardTranslator.py
2009-03-28 17:58:07 UTC (rev 4240)
+++
software_suite_v2/software/gadgets/tuxdroid-gadget-clipboardTranslator/trunk/executables/ClipboardTranslator.py
2009-03-28 18:11:01 UTC (rev 4241)
@@ -8,15 +8,15 @@
import os
import time
import threading
+import sys
-from SimpleGadget.SimpleGadgetConfiguration import SimpleGadgetConfiguration
-from SimpleGadget.SimpleGadget import SimpleGadget
-from util.languagefinder.LanguageFinder import LanguageFinder
-from util.textfilter.TextFilter import TextFilterContainer
-from util.clipboard.Clipboard import getClipboardText
-from util.textfilter.chardet.chardet import detect
-from util.translator.GoogleTranslate import googleTranslate
+sys.path.append(os.environ['TUXDROID_SERVER_PYTHON_UTIL'])
+from util.SimpleGadget.SimpleGadgetConfiguration import
SimpleGadgetConfiguration
+from util.SimpleGadget.SimpleGadget import SimpleGadget
+from util.system.Clipboard import Clipboard
+from util.string.String import String
+
class Configuration(SimpleGadgetConfiguration):
"""Configuration of the gadget.
"""
@@ -26,13 +26,6 @@
"""Translate the clipboard text in your language.
"""
- def __init__(self):
- SimpleGadget.__init__(self)
- self.__lastClipboard = None
- self.__textFilter = None
- self.__languageFinder = None
- self.__langCountry = None
-
def start(self):
"""Gadget entry point.
"""
@@ -52,8 +45,7 @@
self._doExecute()
def __checkClipboard(self):
- # Get the clipboard
- text = getClipboardText()
+ text = Clipboard.getText()
if text == "":
return False
if self.__lastClipboard == None:
@@ -67,46 +59,18 @@
def __clipboardPooling(self):
while True:
if self.__checkClipboard():
- text = self.__lastClipboard
- # Get the text language
- lang = self.__languageFinder.findLanguage(text)
- # Force to encode in utf-8
- encoding = detect(text)['encoding']
- text = text.decode(encoding)
- text = self.__textFilter.apply(text,
+ text = String.getTranslatedClipboardText(
self.configuration().getLanguage())
- text = text.encode('utf-8', 'replace')
- # Translate
- text = googleTranslate(lang.split("_")[0],
- self.configuration().getLanguage(), text)
- # Apply text filter
- text = text.decode("utf-8")
- text = self.__textFilter.apply(text,
- self.configuration().getLanguage())
- text = text.replace("??", " ")
- text = text.replace("? ? ?", " ")
- text = text.replace("? ?", " ")
- text = text.replace('\r', "")
- text = text.replace(u'\xa0', "")
- text = text.replace('*', ".")
- text = text.encode('latin1', 'ignore')
- while text.find(". .") != -1:
- text = text.replace(". .", ".")
if text != "":
self.throwMessage(text)
time.sleep(1.0)
def _doExecute(self):
- self.__textFilter = TextFilterContainer()
-
self.__textFilter.load_directory(os.path.join(os.path.split(__file__)[0],
- 'filters'))
- self.__languageFinder = LanguageFinder()
- self.__languageFinder.load()
+ self.__lastClipboard = None
self.__checkClipboard()
t = threading.Thread(target = self.__clipboardPooling)
t.start()
if __name__ == "__main__":
- import sys
gadget = ClipboardTranslatorGadget()
gadget.boot(sys.argv[1:], Configuration())
------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn