comparison browser_side/base_panels.py @ 362:019e1e706e74

browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
author souliane <souliane@mailoo.org>
date Wed, 19 Feb 2014 16:38:13 +0100
parents df743589bb8c
children 30d03d9f07e4
comparison
equal deleted inserted replaced
361:f4efffb9627c 362:019e1e706e74
319 return text 319 return text
320 self.strproc = strproc 320 self.strproc = strproc
321 self.__modifiedCb = modifiedCb 321 self.__modifiedCb = modifiedCb
322 self._afterEditCb = afterEditCb 322 self._afterEditCb = afterEditCb
323 self.initialized = False 323 self.initialized = False
324 self.edit_listeners = []
324 self.setContent(content) 325 self.setContent(content)
325 326
326 def setContent(self, content=None): 327 def setContent(self, content=None):
327 """Set the editable content. The displayed content, which is set from the child class, could differ. 328 """Set the editable content. The displayed content, which is set from the child class, could differ.
328 @param content: dict with at least a 'text' key 329 @param content: dict with at least a 'text' key
412 pass 413 pass
413 414
414 def abortEdition(self, content): 415 def abortEdition(self, content):
415 return True 416 return True
416 417
418 def addEditListener(self, listener):
419 """Add a method to be called whenever the text is edited.
420 @param listener: method taking two arguments: sender, keycode"""
421 self.edit_listeners.append(listener)
422
417 423
418 class LightTextEditor(BaseTextEditor, HTML, FocusHandler, KeyboardHandler): 424 class LightTextEditor(BaseTextEditor, HTML, FocusHandler, KeyboardHandler):
419 """Manage a simple text editor whith the HTML 5 "contenteditable" property.""" 425 """Manage a simple text editor whith the HTML 5 "contenteditable" property."""
420 426
421 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, single_line=False, enhance_display=True): 427 def __init__(self, content=None, modifiedCb=None, afterEditCb=None, single_line=False, enhance_display=True):
428 @param enhance_display: if True, the display text will be enhanced with addURLToText 434 @param enhance_display: if True, the display text will be enhanced with addURLToText
429 """ 435 """
430 HTML.__init__(self) 436 HTML.__init__(self)
431 if single_line: 437 if single_line:
432 FocusHandler.__init__(self) 438 FocusHandler.__init__(self)
433 KeyboardHandler.__init__(self) 439 KeyboardHandler.__init__(self)
434 self.__single_line = single_line 440 self.__single_line = single_line
435 self.__enhance_display = enhance_display 441 self.__enhance_display = enhance_display
436 strproc = lambda text: html_sanitize(html_strip(text)) if self.__single_line else html_strip(text) 442 strproc = lambda text: html_sanitize(html_strip(text)) if self.__single_line else html_strip(text)
437 BaseTextEditor.__init__(self, content, strproc, modifiedCb, afterEditCb) 443 BaseTextEditor.__init__(self, content, strproc, modifiedCb, afterEditCb)
438 444
449 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') 455 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false')
450 BaseTextEditor.edit(self, edit) 456 BaseTextEditor.edit(self, edit)
451 if edit: 457 if edit:
452 if self.__single_line: 458 if self.__single_line:
453 self.addFocusListener(self) 459 self.addFocusListener(self)
454 self.addKeyboardListener(self) 460 self.addKeyboardListener(self)
455 else: 461 else:
456 self.setDisplayContent() 462 self.setDisplayContent()
457 if self.__single_line: 463 if self.__single_line:
458 if self in self._focusListeners: 464 if self in self._focusListeners:
459 self.removeFocusListener(self) 465 self.removeFocusListener(self)
460 if self in self._keyboardListeners: 466 if self in self._keyboardListeners:
461 self.removeKeyboardListener(self) 467 self.removeKeyboardListener(self)
462 468
463 def setDisplayContent(self): 469 def setDisplayContent(self):
464 text = addURLToImage(self._original_content['text']) 470 text = addURLToImage(self._original_content['text'])
465 self.setHTML(addURLToText(text) if self.__enhance_display else text) 471 self.setHTML(addURLToText(text) if self.__enhance_display else text)
466 472
468 if focus: 474 if focus:
469 self.getElement().focus() 475 self.getElement().focus()
470 else: 476 else:
471 self.getElement().blur() 477 self.getElement().blur()
472 478
479 def onKeyDown(self, sender, keycode, modifiers):
480 for listener in self.edit_listeners:
481 listener(self, keycode)
482
473 def onKeyPress(self, sender, keycode, modifiers): 483 def onKeyPress(self, sender, keycode, modifiers):
484 if not self.__single_line:
485 return
474 if keycode == KEY_ENTER: 486 if keycode == KEY_ENTER:
475 self.setFocus(False) # finish the edition 487 self.setFocus(False) # finish the edition
476 488
477 def onLostFocus(self, sender): 489 def onLostFocus(self, sender):
478 """Finish the edition when focus is lost""" 490 """Finish the edition when focus is lost"""