Mercurial > libervia-web
comparison browser_side/base_panels.py @ 347:f1ba38043d78
browser_side: status panel is based on a new class LightTextEditor which uses HTML5 "editablecontent" property
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 07 Feb 2014 20:14:11 +0100 |
parents | 82f9e92379b0 |
children | f488692c4903 |
comparison
equal
deleted
inserted
replaced
346:82f9e92379b0 | 347:f1ba38043d78 |
---|---|
26 from pyjamas.ui.HTML import HTML | 26 from pyjamas.ui.HTML import HTML |
27 from pyjamas.ui.PopupPanel import PopupPanel | 27 from pyjamas.ui.PopupPanel import PopupPanel |
28 from pyjamas.ui.StackPanel import StackPanel | 28 from pyjamas.ui.StackPanel import StackPanel |
29 from pyjamas.ui.TextArea import TextArea | 29 from pyjamas.ui.TextArea import TextArea |
30 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT | 30 from pyjamas.ui.Event import BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT |
31 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler | |
32 from pyjamas.ui.FocusListener import FocusHandler | |
31 from pyjamas import DOM | 33 from pyjamas import DOM |
32 | 34 |
33 from datetime import datetime | 35 from datetime import datetime |
34 from time import time | 36 from time import time |
35 | 37 |
36 from tools import html_sanitize, inlineRoot | 38 from tools import html_sanitize, html_clean, inlineRoot |
37 | 39 |
38 from sat_frontends.tools.strings import addURLToText | 40 from sat_frontends.tools.strings import addURLToText |
39 from sat.core.i18n import _ | 41 from sat.core.i18n import _ |
40 | 42 |
41 | 43 |
283 def getText(self): | 285 def getText(self): |
284 return self.text_area.getText() | 286 return self.text_area.getText() |
285 | 287 |
286 def setText(self, text): | 288 def setText(self, text): |
287 self.text_area.setText(text) | 289 self.text_area.setText(text) |
290 | |
291 | |
292 class LightTextEditor(HTML, FocusHandler, KeyboardHandler): | |
293 | |
294 def __init__(self, content='', single_line=False, callback=None): | |
295 HTML.__init__(self) | |
296 if single_line: | |
297 FocusHandler.__init__(self) | |
298 KeyboardHandler.__init__(self) | |
299 self.__single_line = single_line | |
300 self.__callback = callback | |
301 self.setContent(content) | |
302 | |
303 def setContent(self, content=''): | |
304 self.__original_content = html_clean(content) if self.__single_line else content.strip() | |
305 self.setHTML('<div>%s</div>' % self.__original_content) | |
306 | |
307 def getContent(self): | |
308 content = DOM.getInnerHTML(self.getElement().firstChild) | |
309 return html_clean(content) if self.__single_line else content.strip() | |
310 | |
311 def modified(self, content=None): | |
312 if content is None: | |
313 content = self.getContent() | |
314 return content != self.__original_content | |
315 | |
316 def edit(self, edit): | |
317 self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') | |
318 if edit: | |
319 self.setFocus(True) | |
320 if self.__single_line: | |
321 self.addFocusListener(self) | |
322 self.addKeyboardListener(self) | |
323 else: | |
324 if self.__single_line: | |
325 self.removeFocusListener(self) | |
326 self.removeKeyboardListener(self) | |
327 content = self.getContent() | |
328 if self.modified(content) and self.__callback: | |
329 self.__callback(content) | |
330 | |
331 def setFocus(self, focus): | |
332 if focus: | |
333 self.getElement().focus() | |
334 else: | |
335 self.getElement().blur() | |
336 | |
337 def onKeyDown(self, sender, keycode, modifiers): | |
338 if keycode == KEY_ENTER: | |
339 self.setFocus(False) | |
340 | |
341 def onLostFocus(self, sender): | |
342 self.edit(False) |