Mercurial > libervia-web
comparison browser_side/panels.py @ 361:f4efffb9627c
browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 19 Feb 2014 14:17:03 +0100 |
parents | c943fd54c90e |
children | 019e1e706e74 |
comparison
equal
deleted
inserted
replaced
360:9834136b15ed | 361:f4efffb9627c |
---|---|
168 | 168 |
169 def __init__(self, host): | 169 def __init__(self, host): |
170 MessageBox.__init__(self, host) | 170 MessageBox.__init__(self, host) |
171 #AutoCompleteTextBox.__init__(self) | 171 #AutoCompleteTextBox.__init__(self) |
172 self.setStyleName('uniBox') | 172 self.setStyleName('uniBox') |
173 self._popup = None | |
174 self._timer = Timer(notify=self._timeCb) | |
175 host.addSelectedListener(self.onSelectedChange) | 173 host.addSelectedListener(self.onSelectedChange) |
176 | 174 |
177 def addKey(self, key): | 175 def addKey(self, key): |
178 return | 176 return |
179 #self.getCompletionItems().completions.append(key) | 177 #self.getCompletionItems().completions.append(key) |
185 # and removeKey methods if they don't serve anymore. | 183 # and removeKey methods if they don't serve anymore. |
186 try: | 184 try: |
187 self.getCompletionItems().completions.remove(key) | 185 self.getCompletionItems().completions.remove(key) |
188 except KeyError: | 186 except KeyError: |
189 print "WARNING: trying to remove an unknown key" | 187 print "WARNING: trying to remove an unknown key" |
190 | |
191 def showWarning(self, target_data): | |
192 target_hook, _type, msg = target_data | |
193 if _type == "NONE": | |
194 return | |
195 if not msg: | |
196 print "WARNING: no msg set uniBox warning" | |
197 return | |
198 if _type == "PUBLIC": | |
199 style = "targetPublic" | |
200 elif _type == "GROUP": | |
201 style = "targetGroup" | |
202 elif _type == "STATUS": | |
203 msg = "This will be your new status message" | |
204 style = "targetStatus" | |
205 elif _type == "ONE2ONE": | |
206 style = "targetOne2One" | |
207 else: | |
208 print "ERROR: unknown message type" | |
209 return | |
210 contents = HTML(msg) | |
211 | |
212 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) | |
213 self._popup.target_data = target_data | |
214 self._popup.add(contents) | |
215 self._popup.setStyleName("warningPopup") | |
216 if style: | |
217 self._popup.addStyleName(style) | |
218 | |
219 left = 0 | |
220 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
221 self._popup.setPopupPosition(left, top) | |
222 self._popup.show() | |
223 | |
224 def _timeCb(self, timer): | |
225 if self._popup: | |
226 self._popup.hide() | |
227 del self._popup | |
228 self._popup = None | |
229 | 188 |
230 def _getTarget(self, txt): | 189 def _getTarget(self, txt): |
231 """ Say who will receive the messsage | 190 """ Say who will receive the messsage |
232 @return: a tuple (selected, target_type, target info) with: | 191 @return: a tuple (selected, target_type, target info) with: |
233 - 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)) | 192 - 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)) |
270 | 229 |
271 return (target_hook, _type, msg) | 230 return (target_hook, _type, msg) |
272 | 231 |
273 def onKeyPress(self, sender, keycode, modifiers): | 232 def onKeyPress(self, sender, keycode, modifiers): |
274 _txt = self.getText() | 233 _txt = self.getText() |
275 target = self._getTarget(_txt) | 234 target_hook, type_, msg = self._getTarget(_txt) |
276 if not self._popup: | 235 self.host.showWarning(type_, msg) |
277 self.showWarning(target) | |
278 elif target != self._popup.target_data: | |
279 self._timeCb(None) # we remove the popup | |
280 self.showWarning(target) | |
281 | |
282 self._timer.schedule(2000) | |
283 | 236 |
284 if keycode == KEY_ENTER: | 237 if keycode == KEY_ENTER: |
285 if _txt: | 238 if _txt: |
286 target_hook, type_, msg = target | |
287 if target_hook: | 239 if target_hook: |
288 parsed_txt, data = target_hook | 240 parsed_txt, data = target_hook |
289 self.host.send([(type_, data)], parsed_txt) | 241 self.host.send([(type_, data)], parsed_txt) |
290 self.host._updateInputHistory(_txt) | 242 self.host._updateInputHistory(_txt) |
291 self.setText('') | 243 self.setText('') |
292 self._timeCb(None) # we remove the popup | 244 self.host.showWarning(None, None) |
293 MessageBox.onKeyPress(self, sender, keycode, modifiers) | 245 MessageBox.onKeyPress(self, sender, keycode, modifiers) |
294 | 246 |
295 def getTargetAndData(self): | 247 def getTargetAndData(self): |
296 """For external use, to get information about the (hypothetical) message | 248 """For external use, to get information about the (hypothetical) message |
297 that would be sent if we press Enter right now in the unibox. | 249 that would be sent if we press Enter right now in the unibox. |
325 """def complete(self): | 277 """def complete(self): |
326 | 278 |
327 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done | 279 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
328 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | 280 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this |
329 return AutoCompleteTextBox.complete(self)""" | 281 return AutoCompleteTextBox.complete(self)""" |
282 | |
283 | |
284 class WarningPopup(): | |
285 | |
286 def __init__(self): | |
287 self._popup = None | |
288 self._timer = Timer(notify=self._timeCb) | |
289 | |
290 def showWarning(self, type_=None, msg=None): | |
291 """Display a popup information message, e.g. to notify the recipient of a message being composed. | |
292 If type_ is None, a popup being currently displayed will be hidden. | |
293 @type_: a type determining the CSS style to be applied (see __showWarning) | |
294 @msg: message to be displayed | |
295 """ | |
296 if type_ is None: | |
297 self.__removeWarning() | |
298 return | |
299 if not self._popup: | |
300 self.__showWarning(type_, msg) | |
301 elif (type_, msg) != self._popup.target_data: | |
302 self._timeCb(None) # we remove the popup | |
303 self.__showWarning(type_, msg) | |
304 | |
305 self._timer.schedule(2000) | |
306 | |
307 def __showWarning(self, type_, msg): | |
308 """Display a popup information message, e.g. to notify the recipient of a message being composed. | |
309 @type_: a type determining the CSS style to be applied. For now the defined styles are | |
310 "NONE" (will do nothing), "PUBLIC", "GROUP", "STATUS" and "ONE2ONE". | |
311 @msg: message to be displayed | |
312 """ | |
313 if type_ == "NONE": | |
314 return | |
315 if not msg: | |
316 print "WARNING: no msg set uniBox warning" | |
317 return | |
318 if type_ == "PUBLIC": | |
319 style = "targetPublic" | |
320 elif type_ == "GROUP": | |
321 style = "targetGroup" | |
322 elif type_ == "STATUS": | |
323 msg = "This will be your new status message" | |
324 style = "targetStatus" | |
325 elif type_ == "ONE2ONE": | |
326 style = "targetOne2One" | |
327 else: | |
328 print "ERROR: unknown message type" | |
329 return | |
330 contents = HTML(msg) | |
331 | |
332 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) | |
333 self._popup.target_data = (type_, msg) | |
334 self._popup.add(contents) | |
335 self._popup.setStyleName("warningPopup") | |
336 if style: | |
337 self._popup.addStyleName(style) | |
338 | |
339 left = 0 | |
340 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
341 self._popup.setPopupPosition(left, top) | |
342 self._popup.show() | |
343 | |
344 def _timeCb(self, timer): | |
345 if self._popup: | |
346 self._popup.hide() | |
347 del self._popup | |
348 self._popup = None | |
349 | |
350 def __removeWarning(self): | |
351 """Remove the popup""" | |
352 self._timeCb(None) | |
330 | 353 |
331 | 354 |
332 class MicroblogItem(): | 355 class MicroblogItem(): |
333 # XXX: should be moved in a separated module | 356 # XXX: should be moved in a separated module |
334 | 357 |