Mercurial > libervia-web
diff browser_side/panels.py @ 349:f488692c4903
browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 12 Feb 2014 14:58:11 +0100 |
parents | f1ba38043d78 |
children | f1b9ec412769 |
line wrap: on
line diff
--- a/browser_side/panels.py Wed Feb 12 14:51:13 2014 +0100 +++ b/browser_side/panels.py Wed Feb 12 14:58:11 2014 +0100 @@ -40,7 +40,7 @@ from __pyjamas__ import doc from tools import html_sanitize, setPresenceStyle -from base_panels import ChatText, OccupantsList, PopupMenuPanel, LightTextEditor +from base_panels import ChatText, OccupantsList, PopupMenuPanel, BaseTextEditor, LightTextEditor from datetime import datetime from time import time from card_game import CardPanel @@ -53,8 +53,9 @@ from constants import Const from plugin_xep_0085 import ChatStateMachine +from sat_frontends.tools.strings import addURLToText from sat_frontends.tools.games import SYMBOLS -from sat_frontends.tools.strings import addURLToText +from sat.core.i18n import _ class UniBoxPanel(HorizontalPanel): @@ -899,22 +900,46 @@ class StatusPanel(LightTextEditor, ClickHandler): - EMPTY_STATUS = '<click to set a status>' + EMPTY_STATUS = '<click to set a status>' def __init__(self, host, status=''): self.host = host - self.status = status - LightTextEditor.__init__(self, self.__getStatus(), True, lambda status: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, status)) + modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, content['text']) or True + LightTextEditor.__init__(self, {'text': status}, modifiedCb, None, True) + self.edit(False) self.setStyleName('statusPanel') ClickHandler.__init__(self) self.addClickListener(self) - def __getStatus(self): - return html_sanitize(self.status or self.EMPTY_STATUS) + @property + def status(self): + return self._original_content['text'] + + def __cleanContent(self, content): + status = content['text'] + if status == self.EMPTY_STATUS or status in Const.PRESENCE.values(): + content['text'] = '' + return content + + def getContent(self): + return self.__cleanContent(LightTextEditor.getContent(self)) - def changeStatus(self, new_status): - self.status = new_status - self.setContent(self.__getStatus()) + def setContent(self, content): + content = self.__cleanContent(content) + BaseTextEditor.setContent(self, content) + + def setDisplayContent(self): + status = self._original_content['text'] + try: + presence = self.host.status_panel.presence + except AttributeError: # during initialization + presence = None + if not status: + if presence and presence in Const.PRESENCE: + status = Const.PRESENCE[presence] + else: + status = self.EMPTY_STATUS + self.setHTML(addURLToText(status)) def onClick(self, sender): self.edit(True) @@ -948,21 +973,26 @@ panel.setStyleName("marginAuto") self.add(panel) + self.status_panel.edit(False) + ClickHandler.__init__(self) self.addClickListener(self) - def getPresence(self): - return self.presence + @property + def presence(self): + return self._presence + + @property + def status(self): + return self.status_panel._original_content['text'] def setPresence(self, presence): - status = self.status_panel.status - if not status.strip() or status == " " or (self.presence in Const.PRESENCE and status == Const.PRESENCE[self.presence]): - self.changeStatus(Const.PRESENCE[presence]) - self.presence = presence - setPresenceStyle(self.presence_button, self.presence) + self._presence = presence + setPresenceStyle(self.presence_button, self._presence) - def changeStatus(self, new_status): - self.status_panel.changeStatus(new_status) + def setStatus(self, status): + self.status_panel.setContent({'text': status}) + self.status_panel.setDisplayContent() def onClick(self, sender): # As status is the default target of uniBar, we don't want to select anything if click on it