← 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)


Switch languages menu added, thanks to Matttbe for this suggestion. util module added.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/doCkranslator/+merge/30226
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-18 18:03:12 +0000
+++ doCkranslator/Changelog.txt	2010-07-18 23:09:44 +0000
@@ -1,3 +1,4 @@
+0.1.1:(July/18/2010): Switch languages menu added, thanks to Matttbe for this suggestion. util module added.
 0.1.0:(July/18/2010): doCkranslator now has another fast-as-hell way to translate. Press Ctrl + F8 to open the input dialog, paste some text, and press Enter. The shortcut capability requires Python-Xlib, but even if the user has not it, the applet works without this capability.
 0.0.5:(July/16/2010): Source language now can be defined by context menu. doCkranslator now has a fast way to translate, select any text and middle-click on the icon, just it.
 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.

=== modified file 'doCkranslator/auto-load.conf'
--- doCkranslator/auto-load.conf	2010-07-18 18:03:12 +0000
+++ doCkranslator/auto-load.conf	2010-07-18 23:09:44 +0000
@@ -10,4 +10,4 @@
 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.1.0
+version = 0.1.1

=== added file 'doCkranslator/data/switch.png'
Binary files doCkranslator/data/switch.png	1970-01-01 00:00:00 +0000 and doCkranslator/data/switch.png	2010-07-18 23:09:44 +0000 differ
=== modified file 'doCkranslator/doCkranslator'
--- doCkranslator/doCkranslator	2010-07-18 22:43:01 +0000
+++ doCkranslator/doCkranslator	2010-07-18 23:09:44 +0000
@@ -32,6 +32,7 @@
 from dbus import glib
 from sgmllib import SGMLParser
 from urllib import FancyURLopener
+from util import log
 
 # Mesmo que o usuario nao tenha a Python-Xlib instalada, o applet ira funcionar,
 # pois esta biblioteca eh usada apenas para fazer a linkagem entre Ctrl+F8 e
@@ -45,10 +46,10 @@
     import thread                                                                       # abrir um fluxo alternativo com a classe KeyHandler
     import time
 except ImportError:                                                                     # Nao tem a Python-Xlib instalada, msg nele
-    print "Ctrl + F8 shortcut won't work, install Python-Xlib library"
+    log ("Ctrl + F8 shortcut won't work, install Python-Xlib library")
     shortcut_available = False
 else:
-    print "Ctrl + F8 shortcut gonna work, Python-Xlib library is up and running"
+    log ("Ctrl + F8 shortcut gonna work, Python-Xlib library is up and running")
     shortcut_available = True
 
 DBusGMainLoop(set_as_default=True)
@@ -92,26 +93,31 @@
         self.root = self.disp.screen().root
         self.root.change_attributes(event_mask = X.KeyPressMask)
         self.f8_keycode = self.disp.keysym_to_keycode(XK.string_to_keysym('F8'))
-        self.root.grab_key(self.f8_keycode, X.ControlMask, 1, X.GrabModeAsync, X.GrabModeAsync)     # Pega do X quando pressionar Ctrl + F8
-        print "DEBUG: %s %s" % (self.root, self.f8_keycode)
-        # self.root.grab_key(self.f8_keycode, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync)   # Pega do X quando pressionar F8
+        self.root.grab_key(self.f8_keycode, X.ControlMask, True, X.GrabModeAsync, X.GrabModeAsync)     # Pega do X quando pressionar Ctrl + F8
+        # self.root.grab_key(self.f8_keycode, X.AnyModifier, True, X.GrabModeAsync, X.GrabModeAsync)   # Pega do X quando pressionar F8
         self.disp.set_error_handler(self.disp_error_handler)
     
     def disp_error_handler(self, error, request):
-        print "Error %s" % error
-        self.root.ungrab_key(self.f8_keycode, X.ControlMask)
+        log ("Error %s" % error)
         self.root.ungrab_key(self.f8_keycode, X.AnyModifier)
         self.running = 0
 
+    def lookup_keysym(self, keysym):
+        for name in dir(XK):
+            if name.startswith("XK_") and getattr(XK, name) == keysym:
+                return name.lstrip("XK_")
+        return "[%d]" % keysym
+
     def handle_event(self, aEvent):
         keycode = aEvent.detail
+        log ("Pressed key %s" % self.lookup_keysym(self.disp.keycode_to_keysym(keycode,0)))
         if aEvent.type == X.KeyPress:
             if keycode == self.f8_keycode:
                 print "Ok, 'Ctrl + F8' pressed"
                 self.applet.ask_text()                                                  # Abrir o caixa de dialogo para o texto a ser traduzido
 
     def start(self, name, sleeptime):
-        print "KeyHandler start"
+        log ("KeyHandler start")
         while self.running:                                                             # Faz o polling ateh que o evento seja recebido
             event = self.root.display.next_event()                                      # busca o evento que tiver
             self.handle_event(event)                                                    # lanca o metodo de tratamento do evento
@@ -179,7 +185,7 @@
         self.dialog_active_time = 5                                                     # time in seconds that the dialog window will be active
 
     def start(self):
-        print "Applet start"
+        log ("Applet start")
         self.read_languages_file()
         self.set_configuration_parameters()
         self.connect_to_callbacks()
@@ -212,7 +218,7 @@
             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)
+        log ("sentence: %s (from: %s to: %s)" % (sentence, source, destiny))
         self.inform_start_of_waiting_process()
 
         interface = Interface(sentence)
@@ -222,7 +228,7 @@
 
         self.inform_end_of_waiting_process()
         self.inform_current_destiny_language()
-        print "translated: %s" % translated
+        log ("translated: %s" % translated)
 
     def ask_text(self, default=""):
         label = "Translate from %s to %s:" % (self.source.name, self.destiny.name)
@@ -246,7 +252,10 @@
         if selected_menu < len(self.destinies):
             self.switch_destiny_language(selected_menu)
         else:
-            self.switch_source_language(selected_menu)
+            if selected_menu < len(self.destinies) + len(self.sources):
+                self.switch_source_language(selected_menu)
+            else:
+                self.switch_languages()
 
     def action_on_scroll(self, scroll_up):
         if scroll_up:
@@ -263,20 +272,26 @@
         if index > max_index:
     		index = max_index - 1
         self.destiny = self.destinies[index]
-        print "Switched destiny from menu: %s" % self.destiny.name
+        log ("Switched destiny from menu: %s" % self.destiny.name)
+        self.inform_current_destiny_language()
+
+    def switch_languages(self):
+        self.source, self.destiny = self.destiny, self.source
+        log ("Switched languages from self.source.namemenu: source [%s] destiny [%s]" % (self.source.name, self.destiny.name))
         self.inform_current_destiny_language()
 
     def switch_source_language(self, index):
         shifted_position = index - len(self.destinies)
         self.source = self.sources[shifted_position]
-        print "Switched source from menu: %s" % self.source.name
+        log ("Switched source from menu: %s" % self.source.name)
 
     def action_on_build_menu(self):
         try:
             self.icon.AddMenuItems(self.build_menu_for_source_languages())
             self.icon.AddMenuItems(self.build_menu_for_destiny_languages())
+            self.icon.AddMenuItems(self.build_menu_for_switch_languages())
         except TypeError:
-            print "AddMenuItems method is not available"
+            log ("AddMenuItems method is not available")
 
     def build_menu_for_destiny_languages(self):
         destiny_sub_menu_icon = os.path.abspath("./data/to.png")
@@ -312,6 +327,12 @@
             source_sub_menu.append(item)
         return source_sub_menu
 
+    def build_menu_for_switch_languages(self):
+        index = len(self.sources) + len(self.destinies)
+        switch_menu_icon = os.path.abspath("./data/switch.png")
+        tooltip = "%s to %s" % (self.destiny.name, self.source.name)
+        return [{'type':0, 'label':'Switch languages', 'menu':0, 'id':index, 'icon':switch_menu_icon, 'tooltip':tooltip}]
+
     def action_on_reload(self, config_has_changed):
 	    if config_has_changed:
 		    self.set_configuration_parameters()

=== modified file 'doCkranslator/doCkranslator.conf'
--- doCkranslator/doCkranslator.conf	2010-07-18 18:03:12 +0000
+++ doCkranslator/doCkranslator.conf	2010-07-18 23:09:44 +0000
@@ -1,4 +1,4 @@
-#!en;0.1.0
+#!en;0.1.1
 
 #[gtk-about]
 [Icon]

=== added file 'doCkranslator/util.py'
--- doCkranslator/util.py	1970-01-01 00:00:00 +0000
+++ doCkranslator/util.py	2010-07-18 23:09:44 +0000
@@ -0,0 +1,9 @@
+#!/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
+
+def log (string):
+    print "[+] doCkranslator: %s" % string


Follow ups