Mercurial > libervia-web
diff src/browser/sat_browser/libervia_widget.py @ 734:26046f13e93b
browser_side: factorize retrieval of drop event data
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 17 Nov 2015 19:59:14 +0100 |
parents | b395d1309936 |
children | f8a7a046ff9c |
line wrap: on
line diff
--- a/src/browser/sat_browser/libervia_widget.py Wed Nov 11 11:49:32 2015 +0100 +++ b/src/browser/sat_browser/libervia_widget.py Tue Nov 17 19:59:14 2015 +0100 @@ -158,19 +158,7 @@ """ self.removeStyleName('dragover') DOM.eventPreventDefault(event) - dt = event.dataTransfer - # 'text', 'text/plain', and 'Text' are equivalent. - try: - item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed - if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and - item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report - # item_type = dt.getData("type") - log.debug(u"message: %s" % item) - log.debug(u"type: %s" % item_type) - except: - log.debug("no message found") - item = ' ' - item_type = None + item, item_type = eventGetData(event) if item_type == "WIDGET": if not LiberviaDragWidget.current: log.error("No widget registered in LiberviaDragWidget !") @@ -282,21 +270,7 @@ # the widget comes from the same tab, so nothing to do, we let it there return - # FIXME: quite the same stuff as in DropCell, need some factorisation - dt = event.dataTransfer - # 'text', 'text/plain', and 'Text' are equivalent. - try: - item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed - if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and - item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report - # item_type = dt.getData("type") - log.debug(u"message: %s" % item) - log.debug(u"type: %s" % item_type) - except: - log.debug("no message found") - item = ' ' - item_type = None - + item, item_type = eventGetData(event) if item_type == "WIDGET": if not LiberviaDragWidget.current: log.error("No widget registered in LiberviaDragWidget !") @@ -813,3 +787,24 @@ self.tabBar.addStyleDependentName('oneTab') self.host.resize() self.selectTab(widget_index if widget_index < widgets_count else widgets_count - 1) + + +def eventGetData(event): + """Retrieve the event data. + + @param event(EventObject) + @return tuple: (event_text, event_type) + """ + dt = event.dataTransfer + # 'text', 'text/plain', and 'Text' are equivalent. + try: + item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed + if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and + item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report + # item_type = dt.getData("type") + log.debug(u"event data: %s (type %s)" % (item, item_type)) + except: + log.debug("event data not found") + item = ' ' + item_type = None + return item, item_type