comparison src/browser/sat_browser/widget.py @ 696:c2f22ca12e23

browser and server side: remove unibox
author souliane <souliane@mailoo.org>
date Mon, 20 Apr 2015 08:51:25 +0200
parents 9877607c719a
children
comparison
equal deleted inserted replaced
695:e86490a7c76e 696:c2f22ca12e23
33 import dialog 33 import dialog
34 import libervia_widget 34 import libervia_widget
35 from constants import Const as C 35 from constants import Const as C
36 from sat_frontends.quick_frontend import quick_widgets 36 from sat_frontends.quick_frontend import quick_widgets
37 from sat_frontends.tools import host_listener 37 from sat_frontends.tools import host_listener
38
39
40 # class UniBoxPanel(HorizontalPanel):
41 # """Panel containing the UniBox"""
42 #
43 # def __init__(self, host):
44 # HorizontalPanel.__init__(self)
45 # self.host = host
46 # self.setStyleName('uniBoxPanel')
47 # self.unibox = None
48 #
49 # def refresh(self):
50 # """Enable or disable this panel. Contained widgets are created when necessary."""
51 # enable = self.host.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true'
52 # self.setVisible(enable)
53 # if enable and not self.unibox:
54 # self.button = Button('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
55 # self.button.setTitle('Open the rich text editor')
56 # self.button.addStyleName('uniBoxButton')
57 # self.add(self.button)
58 # self.unibox = UniBox(self.host)
59 # self.add(self.unibox)
60 # self.setCellWidth(self.unibox, '100%')
61 # self.button.addClickListener(self.openRichMessageEditor)
62 # self.unibox.addKey("@@: ")
63 # self.unibox.onSelectedChange(self.host.getSelected())
64 #
65 # def openRichMessageEditor(self):
66 # """Open the rich text editor."""
67 # self.button.setVisible(False)
68 # self.unibox.setVisible(False)
69 # self.setCellWidth(self.unibox, '0px')
70 # self.host.panel._contactsMove(self)
71 #
72 # def afterEditCb():
73 # Window.removeWindowResizeListener(self)
74 # self.host.panel._contactsMove(self.host.panel._hpanel)
75 # self.setCellWidth(self.unibox, '100%')
76 # self.button.setVisible(True)
77 # self.unibox.setVisible(True)
78 # self.host.resize()
79 #
80 # richtext.RichMessageEditor.getOrCreate(self.host, self, afterEditCb)
81 # Window.addWindowResizeListener(self)
82 # self.host.resize()
83 #
84 # def onWindowResized(self, width, height):
85 # right = self.host.panel.menu.getAbsoluteLeft() + self.host.panel.menu.getOffsetWidth()
86 # left = self.host.panel._contacts.getAbsoluteLeft() + self.host.panel._contacts.getOffsetWidth()
87 # ideal_width = right - left - 40
88 # self.host.richtext.setWidth("%spx" % ideal_width)
89
90
91
92 # class UniBox(MessageBox, MouseHandler): # AutoCompleteTextBox):
93 # """This text box is used as a main typing point, for message, microblog, etc"""
94 #
95 # def __init__(self, host):
96 # MessageBox.__init__(self, host)
97 # #AutoCompleteTextBox.__init__(self)
98 # self.setStyleName('uniBox')
99 # # FIXME
100 # # host.addSelectedListener(self.onSelectedChange)
101 #
102 # def addKey(self, key):
103 # return
104 # #self.getCompletionItems().completions.append(key)
105 #
106 # def removeKey(self, key):
107 # return
108 # # TODO: investigate why AutoCompleteTextBox doesn't work here,
109 # # maybe it can work on a TextBox but no TextArea. Remove addKey
110 # # and removeKey methods if they don't serve anymore.
111 # try:
112 # self.getCompletionItems().completions.remove(key)
113 # except KeyError:
114 # log.warning("trying to remove an unknown key")
115 #
116 # def _getTarget(self, txt):
117 # """ Say who will receive the messsage
118 # @return: a tuple (selected, target_type, target info) with:
119 # - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None))
120 # - target_type: one of PUBLIC, GROUP, ONE2ONE, STATUS, MISC
121 # - msg: HTML message which will appear in the privacy warning banner """
122 # target = self._selected_cache
123 #
124 # def getSelectedOrStatus():
125 # if target and target.isSelectable():
126 # _type, msg = target.getWarningData()
127 # target_hook = None # we use the selected widget, not a hook
128 # else:
129 # _type, msg = "STATUS", "This will be your new status message"
130 # target_hook = (txt, None)
131 # return (target_hook, _type, msg)
132 #
133 # if not txt.startswith('@'):
134 # target_hook, _type, msg = getSelectedOrStatus()
135 # elif txt.startswith('@@: '):
136 # _type = "PUBLIC"
137 # msg = MicroblogPanel.warning_msg_public
138 # target_hook = (txt[4:], None)
139 # elif txt.startswith('@'):
140 # _end = txt.find(': ')
141 # if _end == -1:
142 # target_hook, _type, msg = getSelectedOrStatus()
143 # else:
144 # group = txt[1:_end] # only one target group is managed for the moment
145 # if not group or not group in self.host.contact_panel.getGroups():
146 # # the group doesn't exists, we ignore the key
147 # group = None
148 # target_hook, _type, msg = getSelectedOrStatus()
149 # else:
150 # _type = "GROUP"
151 # msg = MicroblogPanel.warning_msg_group % group
152 # target_hook = (txt[_end + 2:], group)
153 # else:
154 # log.error("Unknown target")
155 # target_hook, _type, msg = getSelectedOrStatus()
156 #
157 # return (target_hook, _type, msg)
158 #
159 # def onKeyPress(self, sender, keycode, modifiers):
160 # _txt = self.getText()
161 # target_hook, type_, msg = self._getTarget(_txt)
162 #
163 # if keycode == KEY_ENTER:
164 # if _txt:
165 # if target_hook:
166 # parsed_txt, data = target_hook
167 # self.host.send([(type_, data)], parsed_txt)
168 # self.host._updateInputHistory(_txt)
169 # self.setText('')
170 # self.host.showWarning(None, None)
171 # else:
172 # self.host.showWarning(type_, msg)
173 # MessageBox.onKeyPress(self, sender, keycode, modifiers)
174 #
175 # def getTargetAndData(self):
176 # """For external use, to get information about the (hypothetical) message
177 # that would be sent if we press Enter right now in the unibox.
178 # @return a tuple (target, data) with:
179 # - data: what would be the content of the message (body)
180 # - target: JID, group with the prefix "@" or the public entity "@@"
181 # """
182 # _txt = self.getText()
183 # target_hook, _type, _msg = self._getTarget(_txt)
184 # if target_hook:
185 # data, target = target_hook
186 # if target is None:
187 # return target_hook
188 # return (data, "@%s" % (target if target != "" else "@"))
189 # if isinstance(self._selected_cache, MicroblogPanel):
190 # groups = self._selected_cache.accepted_groups
191 # target = "@%s" % (groups[0] if len(groups) > 0 else "@")
192 # if len(groups) > 1:
193 # Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
194 # # elif isinstance(self._selected_cache, ChatPanel): # FIXME
195 # # target = self._selected_cache.target
196 # else:
197 # target = None
198 # return (_txt, target)
199 #
200 # def onWidgetClosed(self, lib_wid):
201 # """Called when a libervia widget is closed"""
202 # if self._selected_cache == lib_wid:
203 # self.onSelectedChange(None)
204 #
205 # """def complete(self):
206 #
207 # #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
208 # #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
209 # return AutoCompleteTextBox.complete(self)"""
210 38
211 39
212 class WebWidget(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget): 40 class WebWidget(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget):
213 """ (mini)browser like widget """ 41 """ (mini)browser like widget """
214 42