comparison browser_side/panels.py @ 232:0ed09cc0566f

browser_side: added UIs for rich text editor and addressing to multiple recipients The rich text format is set according to a user parameter which is for now not created, so you will get a warning on the backend and no toolbar will be displayed. For testing purpose: - you can set _debug to True in RichTextEditor: that will display one toolbar per format. - you can add this parameter to any plugin (the same will be added later in XEP-0071): # DEBUG: TO BE REMOVED LATER, THIS BELONGS TO RICH TEXT EDITOR FORMATS = {"markdown": {}, "bbcode": {}, "dokuwiki": {}, "html": {}} FORMAT_PARAM_KEY = "Composition and addressing" FORMAT_PARAM_NAME = "Format for rich text message composition" # In the parameter definition: <category name="%(format_category_name)s" label="%(format_category_label)s"> <param name="%(format_param_name)s" label="%(format_param_label)s" value="%(format_param_default)s" type="list" security="0"> %(format_options)s </param> </category> # Strings for the placeholders: 'format_category_name': FORMAT_PARAM_KEY, 'format_category_label': _(FORMAT_PARAM_KEY), 'format_param_name': FORMAT_PARAM_NAME, 'format_param_label': _(FORMAT_PARAM_NAME), 'format_param_default': FORMATS.keys()[0], 'format_options': ['<option value="%s"/>' % format for format in FORMATS.keys()]
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 14:12:38 +0200
parents fab7aa366576
children b304cdf13a3b
comparison
equal deleted inserted replaced
231:fab7aa366576 232:0ed09cc0566f
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
24 from pyjamas.ui.AbsolutePanel import AbsolutePanel 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
25 from pyjamas.ui.VerticalPanel import VerticalPanel 25 from pyjamas.ui.VerticalPanel import VerticalPanel
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel 26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
27 from pyjamas.ui.DialogBox import DialogBox
27 from pyjamas.ui.HTMLPanel import HTMLPanel 28 from pyjamas.ui.HTMLPanel import HTMLPanel
28 from pyjamas.ui.Frame import Frame 29 from pyjamas.ui.Frame import Frame
29 from pyjamas.ui.TextArea import TextArea 30 from pyjamas.ui.TextArea import TextArea
30 from pyjamas.ui.Label import Label 31 from pyjamas.ui.Label import Label
31 from pyjamas.ui.Button import Button 32 from pyjamas.ui.Button import Button
43 from tools import html_sanitize, addURLToText 44 from tools import html_sanitize, addURLToText
44 from datetime import datetime 45 from datetime import datetime
45 from time import time 46 from time import time
46 import dialog 47 import dialog
47 import base_widget 48 import base_widget
49 from richtext import RichTextEditor
48 from plugin_xep_0085 import ChatStateMachine 50 from plugin_xep_0085 import ChatStateMachine
49 from pyjamas import Window 51 from pyjamas import Window
50 from __pyjamas__ import doc 52 from __pyjamas__ import doc
51 53
52 54
53 class UniBoxPanel(SimplePanel): 55 class UniBoxPanel(HorizontalPanel):
54 """Panel containing the UniBox""" 56 """Panel containing the UniBox"""
55 57
56 def __init__(self, host): 58 def __init__(self, host):
57 SimplePanel.__init__(self) 59 HorizontalPanel.__init__(self)
60 self.host = host
58 self.setStyleName('uniBoxPanel') 61 self.setStyleName('uniBoxPanel')
62
63 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
64 self.button.setTitle('Open the rich text editor')
65 self.button.addStyleName('uniBoxButton')
66 self.add(self.button)
67
59 self.unibox = UniBox(host) 68 self.unibox = UniBox(host)
60 self.unibox.setWidth('100%')
61 self.add(self.unibox) 69 self.add(self.unibox)
70 self.setCellWidth(self.unibox, '100%')
71
72 self.button.addClickListener(self.openRichTextEditor)
73 self.unibox.addDoubleClickListener(self.openRichTextEditor)
74
75 def openRichTextEditor(self):
76 """Open the rich text editor."""
77 self.button.setVisible(False)
78 self.unibox.setVisible(False)
79 self.setCellWidth(self.unibox, '0px')
80 self.host.panel._contactsMove(self)
81
82 def onCloseCallback():
83 self.host.panel._contactsMove(self.host.panel._hpanel)
84 self.setCellWidth(self.unibox, '100%')
85 self.button.setVisible(True)
86 self.unibox.setVisible(True)
87 self.host.resize()
88
89 RichTextEditor.getOrCreate(self.host, self, onCloseCallback)
90 self.host.resize()
62 91
63 92
64 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox): 93 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox):
65 """This text box is used as a main typing point, for message, microblog, etc""" 94 """This text box is used as a main typing point, for message, microblog, etc"""
66 95
846 875
847 # status bar 876 # status bar
848 status = host.status_panel 877 status = host.status_panel
849 878
850 # contacts 879 # contacts
851 _contacts = HorizontalPanel() 880 self._contacts = HorizontalPanel()
852 _contacts.addStyleName('globalLeftArea') 881 self._contacts.addStyleName('globalLeftArea')
853 contacts_switch = Button(u'«', self._contactsSwitch) 882 contacts_switch = Button(u'«', self._contactsSwitch)
854 contacts_switch.addStyleName('contactsSwitch') 883 contacts_switch.addStyleName('contactsSwitch')
855 _contacts.add(contacts_switch) 884 self._contacts.add(contacts_switch)
856 _contacts.add(self.host.contact_panel) 885 self._contacts.add(self.host.contact_panel)
857 886
858 # tabs 887 # tabs
859 self.tab_panel = base_widget.MainTabPanel(host) 888 self.tab_panel = base_widget.MainTabPanel(host)
860 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True) 889 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True)
861 self.tab_panel.add(self.discuss_panel, "Discussions") 890 self.tab_panel.add(self.discuss_panel, "Discussions")
866 header.add(unibox_panel) 895 header.add(unibox_panel)
867 header.add(status) 896 header.add(status)
868 header.setStyleName('header') 897 header.setStyleName('header')
869 self.add(header) 898 self.add(header)
870 899
871 _hpanel = HorizontalPanel() 900 self._hpanel = HorizontalPanel()
872 _hpanel.add(_contacts) 901 self._hpanel.add(self._contacts)
873 _hpanel.add(self.tab_panel) 902 self._hpanel.add(self.tab_panel)
874 self.add(_hpanel) 903 self.add(self._hpanel)
875 904
876 self.setWidth("100%") 905 self.setWidth("100%")
877 Window.addWindowResizeListener(self) 906 Window.addWindowResizeListener(self)
878 907
879 def _contactsSwitch(self, btn): 908 def _contactsSwitch(self, btn):
880 """ (Un)hide contacts panel """ 909 """ (Un)hide contacts panel """
881 cpanel = self.host.contact_panel 910 cpanel = self.host.contact_panel
882 cpanel.setVisible(not cpanel.getVisible()) 911 cpanel.setVisible(not cpanel.getVisible())
883 btn.setText(u"«" if cpanel.getVisible() else u"»") 912 btn.setText(u"«" if cpanel.getVisible() else u"»")
884 self.host.resize() 913 self.host.resize()
914
915 def _contactsMove(self, parent):
916 """Move the contacts container (containing the contact list and
917 the "hide/show" button) to another parent, but always as the
918 first child position (insert at index 0).
919 """
920 if self._contacts.getParent():
921 if self._contacts.getParent() == parent:
922 return
923 self._contacts.removeFromParent()
924 parent.insert(self._contacts, 0)
885 925
886 def onWindowResized(self, width, height): 926 def onWindowResized(self, width, height):
887 _elts = doc().getElementsByClassName('gwt-TabBar') 927 _elts = doc().getElementsByClassName('gwt-TabBar')
888 if not _elts.length: 928 if not _elts.length:
889 tab_bar_h = 0 929 tab_bar_h = 0