# HG changeset patch # User souliane # Date 1381776853 -7200 # Node ID b911f2b43fd462e0423bb2c071b9ecdf494ffceb # Parent dec76d4536ad14da8239b1b37805e0448ab47d0c 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 diff -r dec76d4536ad -r b911f2b43fd4 browser_side/panels.py --- 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() diff -r dec76d4536ad -r b911f2b43fd4 libervia.py --- a/libervia.py Fri Oct 11 15:40:29 2013 +0200 +++ b/libervia.py Mon Oct 14 20:54:13 2013 +0200 @@ -33,6 +33,7 @@ from browser_side import panels, dialog from browser_side.jid import JID from browser_side.tools import html_sanitize +from sat.tools.frontend.misc import InputHistory MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories @@ -96,15 +97,17 @@ dump(o)""" else: if isinstance(errobj['message'], dict): - print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) + print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString'])) else: - print("Error: %s" % errobj['message']) + print("Error: %s" % errobj['message']) + class RegisterCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/register_api", ["isRegistered", "isConnected", "connect"]) + class BridgeCall(LiberviaJsonProxy): def __init__(self): LiberviaJsonProxy.__init__(self, "/json_api", @@ -146,7 +149,8 @@ Timer(notify=_timerCb).schedule(self.retry_delay) self.retry_delay *= 2 -class SatWebFrontend: + +class SatWebFrontend(InputHistory): def onModuleLoad(self): print "============ onModuleLoad ==============" panels.ChatPanel.registerClass() @@ -648,6 +652,7 @@ # TODO: chat state notification for groupchat pass + if __name__ == '__main__': pyjd.setup("http://localhost:8080/libervia.html") app = SatWebFrontend()