comparison 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
comparison
equal deleted inserted replaced
348:83454ba70a9c 349:f488692c4903
38 from pyjamas import DOM 38 from pyjamas import DOM
39 from pyjamas import Window 39 from pyjamas import Window
40 from __pyjamas__ import doc 40 from __pyjamas__ import doc
41 41
42 from tools import html_sanitize, setPresenceStyle 42 from tools import html_sanitize, setPresenceStyle
43 from base_panels import ChatText, OccupantsList, PopupMenuPanel, LightTextEditor 43 from base_panels import ChatText, OccupantsList, PopupMenuPanel, BaseTextEditor, LightTextEditor
44 from datetime import datetime 44 from datetime import datetime
45 from time import time 45 from time import time
46 from card_game import CardPanel 46 from card_game import CardPanel
47 from radiocol import RadioColPanel 47 from radiocol import RadioColPanel
48 from menu import Menu 48 from menu import Menu
51 import base_widget 51 import base_widget
52 import richtext 52 import richtext
53 53
54 from constants import Const 54 from constants import Const
55 from plugin_xep_0085 import ChatStateMachine 55 from plugin_xep_0085 import ChatStateMachine
56 from sat_frontends.tools.strings import addURLToText
56 from sat_frontends.tools.games import SYMBOLS 57 from sat_frontends.tools.games import SYMBOLS
57 from sat_frontends.tools.strings import addURLToText 58 from sat.core.i18n import _
58 59
59 60
60 class UniBoxPanel(HorizontalPanel): 61 class UniBoxPanel(HorizontalPanel):
61 """Panel containing the UniBox""" 62 """Panel containing the UniBox"""
62 63
897 return False 898 return False
898 899
899 900
900 class StatusPanel(LightTextEditor, ClickHandler): 901 class StatusPanel(LightTextEditor, ClickHandler):
901 902
902 EMPTY_STATUS = '<click to set a status>' 903 EMPTY_STATUS = '&lt;click to set a status&gt;'
903 904
904 def __init__(self, host, status=''): 905 def __init__(self, host, status=''):
905 self.host = host 906 self.host = host
906 self.status = status 907 modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, content['text']) or True
907 LightTextEditor.__init__(self, self.__getStatus(), True, lambda status: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, status)) 908 LightTextEditor.__init__(self, {'text': status}, modifiedCb, None, True)
909 self.edit(False)
908 self.setStyleName('statusPanel') 910 self.setStyleName('statusPanel')
909 ClickHandler.__init__(self) 911 ClickHandler.__init__(self)
910 self.addClickListener(self) 912 self.addClickListener(self)
911 913
912 def __getStatus(self): 914 @property
913 return html_sanitize(self.status or self.EMPTY_STATUS) 915 def status(self):
914 916 return self._original_content['text']
915 def changeStatus(self, new_status): 917
916 self.status = new_status 918 def __cleanContent(self, content):
917 self.setContent(self.__getStatus()) 919 status = content['text']
920 if status == self.EMPTY_STATUS or status in Const.PRESENCE.values():
921 content['text'] = ''
922 return content
923
924 def getContent(self):
925 return self.__cleanContent(LightTextEditor.getContent(self))
926
927 def setContent(self, content):
928 content = self.__cleanContent(content)
929 BaseTextEditor.setContent(self, content)
930
931 def setDisplayContent(self):
932 status = self._original_content['text']
933 try:
934 presence = self.host.status_panel.presence
935 except AttributeError: # during initialization
936 presence = None
937 if not status:
938 if presence and presence in Const.PRESENCE:
939 status = Const.PRESENCE[presence]
940 else:
941 status = self.EMPTY_STATUS
942 self.setHTML(addURLToText(status))
918 943
919 def onClick(self, sender): 944 def onClick(self, sender):
920 self.edit(True) 945 self.edit(True)
921 946
922 947
946 panel.setCellVerticalAlignment(self.presence_button, 'baseline') 971 panel.setCellVerticalAlignment(self.presence_button, 'baseline')
947 panel.setCellVerticalAlignment(self.status_panel, 'baseline') 972 panel.setCellVerticalAlignment(self.status_panel, 'baseline')
948 panel.setStyleName("marginAuto") 973 panel.setStyleName("marginAuto")
949 self.add(panel) 974 self.add(panel)
950 975
976 self.status_panel.edit(False)
977
951 ClickHandler.__init__(self) 978 ClickHandler.__init__(self)
952 self.addClickListener(self) 979 self.addClickListener(self)
953 980
954 def getPresence(self): 981 @property
955 return self.presence 982 def presence(self):
983 return self._presence
984
985 @property
986 def status(self):
987 return self.status_panel._original_content['text']
956 988
957 def setPresence(self, presence): 989 def setPresence(self, presence):
958 status = self.status_panel.status 990 self._presence = presence
959 if not status.strip() or status == "&nbsp;" or (self.presence in Const.PRESENCE and status == Const.PRESENCE[self.presence]): 991 setPresenceStyle(self.presence_button, self._presence)
960 self.changeStatus(Const.PRESENCE[presence]) 992
961 self.presence = presence 993 def setStatus(self, status):
962 setPresenceStyle(self.presence_button, self.presence) 994 self.status_panel.setContent({'text': status})
963 995 self.status_panel.setDisplayContent()
964 def changeStatus(self, new_status):
965 self.status_panel.changeStatus(new_status)
966 996
967 def onClick(self, sender): 997 def onClick(self, sender):
968 # As status is the default target of uniBar, we don't want to select anything if click on it 998 # As status is the default target of uniBar, we don't want to select anything if click on it
969 self.host.setSelected(None) 999 self.host.setSelected(None)
970 1000