comparison browser_side/panels.py @ 433:bbdbee25123a

import constants.Const as C (according to the coding rules)
author souliane <souliane@mailoo.org>
date Thu, 01 May 2014 11:29:09 +0200
parents 8ecc5a7062e4
children d52f529a6d42
comparison
equal deleted inserted replaced
432:8ecc5a7062e4 433:bbdbee25123a
51 from browser_side import dialog 51 from browser_side import dialog
52 from browser_side import base_widget 52 from browser_side import base_widget
53 from browser_side import richtext 53 from browser_side import richtext
54 from browser_side import contact 54 from browser_side import contact
55 55
56 from constants import Const 56 from constants import Const as C
57 from plugin_xep_0085 import ChatStateMachine 57 from plugin_xep_0085 import ChatStateMachine
58 from sat_frontends.tools.strings import addURLToText 58 from sat_frontends.tools.strings import addURLToText
59 from sat_frontends.tools.games import SYMBOLS 59 from sat_frontends.tools.games import SYMBOLS
60 from sat.core.i18n import _ 60 from sat.core.i18n import _
61 61
525 def __setBubble(self, edit=False): 525 def __setBubble(self, edit=False):
526 """Set the bubble displaying the initial content.""" 526 """Set the bubble displaying the initial content."""
527 content = {'text': self.content_xhtml if self.content_xhtml else self.content, 527 content = {'text': self.content_xhtml if self.content_xhtml else self.content,
528 'title': self.title_xhtml if self.title_xhtml else self.title} 528 'title': self.title_xhtml if self.title_xhtml else self.title}
529 if self.content_xhtml: 529 if self.content_xhtml:
530 content.update({'syntax': Const.SYNTAX_XHTML}) 530 content.update({'syntax': C.SYNTAX_XHTML})
531 if self.author != self._blog_panel.host.whoami.bare: 531 if self.author != self._blog_panel.host.whoami.bare:
532 options = ['read_only'] 532 options = ['read_only']
533 else: 533 else:
534 options = [] if self.empty else ['update_msg'] 534 options = [] if self.empty else ['update_msg']
535 self.bubble = richtext.RichTextEditor(self._blog_panel.host, content, self.__modifiedCb, self.__afterEditCb, options) 535 self.bubble = richtext.RichTextEditor(self._blog_panel.host, content, self.__modifiedCb, self.__afterEditCb, options)
619 def toggleContentSyntax(self): 619 def toggleContentSyntax(self):
620 """Toggle the editor between raw and rich text""" 620 """Toggle the editor between raw and rich text"""
621 original_content = self.bubble.getOriginalContent() 621 original_content = self.bubble.getOriginalContent()
622 rich = not isinstance(self.bubble, richtext.RichTextEditor) 622 rich = not isinstance(self.bubble, richtext.RichTextEditor)
623 if rich: 623 if rich:
624 original_content['syntax'] = Const.SYNTAX_XHTML 624 original_content['syntax'] = C.SYNTAX_XHTML
625 625
626 def setBubble(text): 626 def setBubble(text):
627 self.content = text 627 self.content = text
628 self.content_xhtml = text if rich else '' 628 self.content_xhtml = text if rich else ''
629 self.content_title = self.content_title_xhtml = '' 629 self.content_title = self.content_title_xhtml = ''
638 setBubble(' ') # something different than empty string is needed to initialize the rich text editor 638 setBubble(' ') # something different than empty string is needed to initialize the rich text editor
639 return 639 return
640 if not rich: 640 if not rich:
641 def confirm_cb(answer): 641 def confirm_cb(answer):
642 if answer: 642 if answer:
643 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_CURRENT, Const.SYNTAX_TEXT) 643 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_CURRENT, C.SYNTAX_TEXT)
644 dialog.ConfirmDialog(confirm_cb, text=_("Do you really want to lose the title and text formatting?")).show() 644 dialog.ConfirmDialog(confirm_cb, text=_("Do you really want to lose the title and text formatting?")).show()
645 else: 645 else:
646 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_TEXT, Const.SYNTAX_XHTML) 646 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_TEXT, C.SYNTAX_XHTML)
647 647
648 648
649 class MicroblogPanel(base_widget.LiberviaWidget): 649 class MicroblogPanel(base_widget.LiberviaWidget):
650 warning_msg_public = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" 650 warning_msg_public = "This message will be PUBLIC and everybody will be able to see it, even people you don't know"
651 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" 651 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>"
970 def status(self): 970 def status(self):
971 return self._original_content['text'] 971 return self._original_content['text']
972 972
973 def __cleanContent(self, content): 973 def __cleanContent(self, content):
974 status = content['text'] 974 status = content['text']
975 if status == self.EMPTY_STATUS or status in Const.PRESENCE.values(): 975 if status == self.EMPTY_STATUS or status in C.PRESENCE.values():
976 content['text'] = '' 976 content['text'] = ''
977 return content 977 return content
978 978
979 def getContent(self): 979 def getContent(self):
980 return self.__cleanContent(HTMLTextEditor.getContent(self)) 980 return self.__cleanContent(HTMLTextEditor.getContent(self))
988 try: 988 try:
989 presence = self.host.status_panel.presence 989 presence = self.host.status_panel.presence
990 except AttributeError: # during initialization 990 except AttributeError: # during initialization
991 presence = None 991 presence = None
992 if not status: 992 if not status:
993 if presence and presence in Const.PRESENCE: 993 if presence and presence in C.PRESENCE:
994 status = Const.PRESENCE[presence] 994 status = C.PRESENCE[presence]
995 else: 995 else:
996 status = self.EMPTY_STATUS 996 status = self.EMPTY_STATUS
997 self.display.setHTML(addURLToText(status)) 997 self.display.setHTML(addURLToText(status))
998 998
999 999
1005 self.presence_button = Label(u"◉") 1005 self.presence_button = Label(u"◉")
1006 self.presence_button.setStyleName("presence-button") 1006 self.presence_button.setStyleName("presence-button")
1007 self.status_panel = StatusPanel(host, status=status) 1007 self.status_panel = StatusPanel(host, status=status)
1008 self.setPresence(presence) 1008 self.setPresence(presence)
1009 entries = {} 1009 entries = {}
1010 for value in Const.PRESENCE.keys(): 1010 for value in C.PRESENCE.keys():
1011 entries.update({Const.PRESENCE[value]: {"value": value}}) 1011 entries.update({C.PRESENCE[value]: {"value": value}})
1012 1012
1013 def callback(sender, key): 1013 def callback(sender, key):
1014 self.setPresence(entries[key]["value"]) # order matters 1014 self.setPresence(entries[key]["value"]) # order matters
1015 self.host.send([("STATUS", None)], self.status_panel.status) 1015 self.host.send([("STATUS", None)], self.status_panel.status)
1016 1016
1251 return self.radiocol_panel 1251 return self.radiocol_panel
1252 1252
1253 def setState(self, state, nick=None): 1253 def setState(self, state, nick=None):
1254 """Set the chat state (XEP-0085) of the contact. Leave nick to None 1254 """Set the chat state (XEP-0085) of the contact. Leave nick to None
1255 to set the state for a one2one conversation, or give a nickname or 1255 to set the state for a one2one conversation, or give a nickname or
1256 Const.ALL_OCCUPANTS to set the state of a participant within a MUC. 1256 C.ALL_OCCUPANTS to set the state of a participant within a MUC.
1257 @param state: the new chat state 1257 @param state: the new chat state
1258 @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS 1258 @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS
1259 """ 1259 """
1260 if nick: 1260 if nick:
1261 assert(self.type == 'group') 1261 assert(self.type == 'group')
1262 occupants = self.occupants_list.occupants_list.keys() if nick == Const.ALL_OCCUPANTS else [nick] 1262 occupants = self.occupants_list.occupants_list.keys() if nick == C.ALL_OCCUPANTS else [nick]
1263 for occupant in occupants: 1263 for occupant in occupants:
1264 self.occupants_list.occupants_list[occupant].setState(state) 1264 self.occupants_list.occupants_list[occupant].setState(state)
1265 else: 1265 else:
1266 assert(self.type == 'one2one') 1266 assert(self.type == 'one2one')
1267 self._state = state 1267 self._state = state