Mercurial > libervia-web
diff browser_side/panels.py @ 193:f2ae8e170c49
browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 04 Mar 2013 00:01:23 +0100 |
parents | cf5c83e7d515 |
children | 6198be95a39c |
line wrap: on
line diff
--- a/browser_side/panels.py Sun Mar 03 23:30:25 2013 +0100 +++ b/browser_side/panels.py Mon Mar 04 00:01:23 2013 +0100 @@ -383,7 +383,8 @@ self.addKeyboardListener(self) MouseHandler.__init__(self) self.addMouseListener(self) - + self._selected_cache = None + host.addSelectedListener(self.onSelectedChange) def addKey(self, key): return @@ -439,7 +440,6 @@ Return a tuple (target_type, target info)""" type = None target = None - selected = self.host.getSelected() if txt.startswith('@@: '): type = "PUBLIC" elif txt.startswith('@'): @@ -451,13 +451,13 @@ target = txt[1:_end] #only one target group is managed for the moment if not target in self.host.contact_panel.getGroups(): target = None - elif selected == None: + elif self._selected_cache == None: type = "STATUS" - elif isinstance(selected, ChatPanel): + elif isinstance(self._selected_cache, ChatPanel): type = "ONE2ONE" - target = str(selected.target) + target = str(self._selected_cache.target) else: - print "Unknown selected host:",selected + print "Unknown selected host:",self._selected_cache type = "UNKNOWN" return (type, target) @@ -480,16 +480,15 @@ self._timer.schedule(2000) - selected = self.host.getSelected() #if keycode == KEY_ENTER and not self.visible: if keycode == KEY_ENTER: if _txt: if _txt.startswith('@'): self.host.bridge.call('sendMblog', None, self.getText()) - elif selected == None: + elif self._selected_cache == None: self.host.bridge.call('setStatus', None, _txt) - elif isinstance(selected, ChatPanel): - _chat = selected + elif isinstance(self._selected_cache, ChatPanel): + _chat = self._selected_cache mess_type = "groupchat" if _chat.type=='group' else "chat" self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) self.setText('') @@ -500,7 +499,10 @@ size = (self.getOffsetWidth(), self.getOffsetHeight()) if size != self.__size: self.__size = size - self.host.resize() + self.host.resize() + + def onSelectedChange(self, selected): + self._selected_cache = selected """def complete(self):