diff browser_side/panels.py @ 239:b911f2b43fd4

browser_side: added input history in the unibox: This functionality uses a file from the sat project: use the -I parameter of pyjsbuild to add sat library to your PYJSPATH. To ease also possible to use your sat source directory instead of the library, you just need to trick pyjsbuild with a symbolic link: SAT=~/workspace/sat if [[ ! -e $SAT/sat ]]; then ln -sf $SAT/src $SAT/sat; fi This will allow you to import like that in libervia.py: from sat.tools.frontend.misc import InputHistory And then you can build with: $PYJS/bin/pyjsbuild libervia --no-compile-inplace -m -I $SAT
author souliane <souliane@mailoo.org>
date Mon, 14 Oct 2013 20:54:13 +0200
parents b304cdf13a3b
children 86055ccf69c3
line wrap: on
line diff
--- a/browser_side/panels.py	Fri Oct 11 15:40:29 2013 +0200
+++ b/browser_side/panels.py	Mon Oct 14 20:54:13 2013 +0200
@@ -33,7 +33,7 @@
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.Image import Image
 from pyjamas.ui.ClickListener import ClickHandler
-from pyjamas.ui.KeyboardListener import KEY_ENTER
+from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN
 from pyjamas.ui.MouseListener import MouseHandler
 from pyjamas.Timer import Timer
 from pyjamas import DOM
@@ -217,6 +217,10 @@
 
         self._timer.schedule(2000)
 
+        def history_cb(text):
+            self.setText(text)
+            Timer(10, lambda: self.setCursorPos(len(text)))
+
         # if keycode == KEY_ENTER and not self.visible:
         if keycode == KEY_ENTER:
             if _txt:
@@ -233,9 +237,14 @@
                         print "ERROR: Unknown target hook type"
                 else:  # we send the message to the selected target
                     self._selected_cache.onTextEntered(_txt)
+                self.host._updateInputHistory(_txt)
             self.setText('')
             self._timeCb(None)  # we remove the popup
             sender.cancelKey()
+        elif keycode == KEY_UP:
+            self.host._updateInputHistory(_txt, -1, history_cb)
+        elif keycode == KEY_DOWN:
+            self.host._updateInputHistory(_txt, +1, history_cb)
         else:
             self.__onComposing()