# HG changeset patch # User souliane # Date 1388355335 -3600 # Node ID 5d11ec1f2c22c5045d5d8e2ce4fdd74cbf983353 # Parent 05e264e96a1ce00ac18b10516e00d7453135f654 browser_side: make UniBox inherit from a more basic MessageBox class diff -r 05e264e96a1c -r 5d11ec1f2c22 browser_side/panels.py --- a/browser_side/panels.py Sun Dec 29 23:07:28 2013 +0100 +++ b/browser_side/panels.py Sun Dec 29 23:15:35 2013 +0100 @@ -118,21 +118,70 @@ self.host.richtext.setWidth("%spx" % ideal_width) -class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox): - """This text box is used as a main typing point, for message, microblog, etc""" +class MessageBox(TextArea): + """A basic text area for entering messages""" def __init__(self, host): TextArea.__init__(self) - #AutoCompleteTextBox.__init__(self) + self.host = host self.__size = (0, 0) - self._popup = None - self._timer = Timer(notify=self._timeCb) - self.host = host - self.setStyleName('uniBox') + self.setStyleName('messageBox') self.addKeyboardListener(self) MouseHandler.__init__(self) self.addMouseListener(self) self._selected_cache = None + + def onBrowserEvent(self, event): + # XXX: woraroung a pyjamas bug: self.currentEvent is not set + # so the TextBox's cancelKey doens't work. This is a workaround + # FIXME: fix the bug upstream + self.currentEvent = event + TextArea.onBrowserEvent(self, event) + + def onKeyPress(self, sender, keycode, modifiers): + _txt = self.getText() + + def history_cb(text): + self.setText(text) + Timer(5, lambda: self.setCursorPos(len(text))) + + if keycode == KEY_ENTER: + if _txt: + self._selected_cache.onTextEntered(_txt) + self.host._updateInputHistory(_txt) + self.setText('') + 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() + + def __onComposing(self): + """Callback when the user is composing a text.""" + if hasattr(self._selected_cache, "target"): + self._selected_cache.state_machine._onEvent("composing") + + def onMouseUp(self, sender, x, y): + size = (self.getOffsetWidth(), self.getOffsetHeight()) + if size != self.__size: + self.__size = size + self.host.resize() + + def onSelectedChange(self, selected): + self._selected_cache = selected + + +class UniBox(MessageBox, MouseHandler): #AutoCompleteTextBox): + """This text box is used as a main typing point, for message, microblog, etc""" + + def __init__(self, host): + MessageBox.__init__(self, host) + #AutoCompleteTextBox.__init__(self) + self.setStyleName('uniBox') + self._popup = None + self._timer = Timer(notify=self._timeCb) host.addSelectedListener(self.onSelectedChange) def addKey(self, key): @@ -231,13 +280,6 @@ return (target_hook, _type, msg) - def onBrowserEvent(self, event): - # XXX: woraroung a pyjamas bug: self.currentEvent is not set - # so the TextBox's cancelKey doens't work. This is a workaround - # FIXME: fix the bug upstream - self.currentEvent = event - TextArea.onBrowserEvent(self, event) - def onKeyPress(self, sender, keycode, modifiers): _txt = self.getText() target = self._getTarget(_txt) @@ -249,29 +291,16 @@ self._timer.schedule(2000) - def history_cb(text): - self.setText(text) - Timer(5, lambda: self.setCursorPos(len(text))) - - # if keycode == KEY_ENTER and not self.visible: if keycode == KEY_ENTER: if _txt: target_hook, type_, msg = target if target_hook: parsed_txt, data = target_hook self.host.send([(type_, data)], parsed_txt) - else: # we send the message to the selected target - self._selected_cache.onTextEntered(_txt) - self.host._updateInputHistory(_txt) - self.setText('') + 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() + MessageBox.onKeyPress(self, sender, keycode, modifiers) def getTargetAndData(self): """For external use, to get information about the (hypothetical) message @@ -298,20 +327,6 @@ target = None return (_txt, target) - def __onComposing(self): - """Callback when the user is composing a text.""" - if hasattr(self._selected_cache, "target"): - self._selected_cache.state_machine._onEvent("composing") - - def onMouseUp(self, sender, x, y): - size = (self.getOffsetWidth(), self.getOffsetHeight()) - if size != self.__size: - self.__size = size - self.host.resize() - - def onSelectedChange(self, selected): - self._selected_cache = selected - def onWidgetClosed(self, lib_wid): """Called when a libervia widget is closed""" if self._selected_cache == lib_wid: diff -r 05e264e96a1c -r 5d11ec1f2c22 public/libervia.css --- a/public/libervia.css Sun Dec 29 23:07:28 2013 +0100 +++ b/public/libervia.css Sun Dec 29 23:15:35 2013 +0100 @@ -531,6 +531,20 @@ -o-transition: color 0.2s linear; } +.messageBox { + width: 100%; + padding: 5px; + border: 1px solid #bbb; + color: #444; + background: #fff url('media/libervia/unibox_2.png') top bottom no-repeat; + box-shadow:inset 0 0 10px #ddd; + -webkit-box-shadow:inset 0 0 10px #ddd; + -moz-box-shadow:inset 0 0 10px #ddd; + border-radius: 0px 0px 10px 10px; + height: 25px; + margin: 0px; +} + /* UniBox & Status */ .uniBoxPanel {