comparison 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
comparison
equal deleted inserted replaced
192:cf5c83e7d515 193:f2ae8e170c49
381 self.host = host 381 self.host = host
382 self.setStyleName('uniBox') 382 self.setStyleName('uniBox')
383 self.addKeyboardListener(self) 383 self.addKeyboardListener(self)
384 MouseHandler.__init__(self) 384 MouseHandler.__init__(self)
385 self.addMouseListener(self) 385 self.addMouseListener(self)
386 386 self._selected_cache = None
387 host.addSelectedListener(self.onSelectedChange)
387 388
388 def addKey(self, key): 389 def addKey(self, key):
389 return 390 return
390 #self.getCompletionItems().completions.append(key) 391 #self.getCompletionItems().completions.append(key)
391 392
437 def _getTarget(self, txt): 438 def _getTarget(self, txt):
438 """Say who will receive the messsage 439 """Say who will receive the messsage
439 Return a tuple (target_type, target info)""" 440 Return a tuple (target_type, target info)"""
440 type = None 441 type = None
441 target = None 442 target = None
442 selected = self.host.getSelected()
443 if txt.startswith('@@: '): 443 if txt.startswith('@@: '):
444 type = "PUBLIC" 444 type = "PUBLIC"
445 elif txt.startswith('@'): 445 elif txt.startswith('@'):
446 type = "GROUP" 446 type = "GROUP"
447 _end = txt.find(': ') 447 _end = txt.find(': ')
449 type = "STATUS" 449 type = "STATUS"
450 else: 450 else:
451 target = txt[1:_end] #only one target group is managed for the moment 451 target = txt[1:_end] #only one target group is managed for the moment
452 if not target in self.host.contact_panel.getGroups(): 452 if not target in self.host.contact_panel.getGroups():
453 target = None 453 target = None
454 elif selected == None: 454 elif self._selected_cache == None:
455 type = "STATUS" 455 type = "STATUS"
456 elif isinstance(selected, ChatPanel): 456 elif isinstance(self._selected_cache, ChatPanel):
457 type = "ONE2ONE" 457 type = "ONE2ONE"
458 target = str(selected.target) 458 target = str(self._selected_cache.target)
459 else: 459 else:
460 print "Unknown selected host:",selected 460 print "Unknown selected host:",self._selected_cache
461 type = "UNKNOWN" 461 type = "UNKNOWN"
462 return (type, target) 462 return (type, target)
463 463
464 def onBrowserEvent(self, event): 464 def onBrowserEvent(self, event):
465 #XXX: woraroung a pyjamas bug: self.currentEvent is not set 465 #XXX: woraroung a pyjamas bug: self.currentEvent is not set
478 self._timeCb(None) #we remove the popup 478 self._timeCb(None) #we remove the popup
479 self.showWarning(_target) 479 self.showWarning(_target)
480 480
481 self._timer.schedule(2000) 481 self._timer.schedule(2000)
482 482
483 selected = self.host.getSelected()
484 #if keycode == KEY_ENTER and not self.visible: 483 #if keycode == KEY_ENTER and not self.visible:
485 if keycode == KEY_ENTER: 484 if keycode == KEY_ENTER:
486 if _txt: 485 if _txt:
487 if _txt.startswith('@'): 486 if _txt.startswith('@'):
488 self.host.bridge.call('sendMblog', None, self.getText()) 487 self.host.bridge.call('sendMblog', None, self.getText())
489 elif selected == None: 488 elif self._selected_cache == None:
490 self.host.bridge.call('setStatus', None, _txt) 489 self.host.bridge.call('setStatus', None, _txt)
491 elif isinstance(selected, ChatPanel): 490 elif isinstance(self._selected_cache, ChatPanel):
492 _chat = selected 491 _chat = self._selected_cache
493 mess_type = "groupchat" if _chat.type=='group' else "chat" 492 mess_type = "groupchat" if _chat.type=='group' else "chat"
494 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) 493 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type)
495 self.setText('') 494 self.setText('')
496 self._timeCb(None) #we remove the popup 495 self._timeCb(None) #we remove the popup
497 sender.cancelKey() 496 sender.cancelKey()
498 497
499 def onMouseUp(self, sender, x, y): 498 def onMouseUp(self, sender, x, y):
500 size = (self.getOffsetWidth(), self.getOffsetHeight()) 499 size = (self.getOffsetWidth(), self.getOffsetHeight())
501 if size != self.__size: 500 if size != self.__size:
502 self.__size = size 501 self.__size = size
503 self.host.resize() 502 self.host.resize()
503
504 def onSelectedChange(self, selected):
505 self._selected_cache = selected
504 506
505 """def complete(self): 507 """def complete(self):
506 508
507 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done 509 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
508 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this 510 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this