Mercurial > libervia-web
diff src/browser/sat_browser/base_widget.py @ 603:462d0458e679 frontends_multi_profiles
browser_side: base_widget.DropCell raises an exception if the callback doesn't return a LiberviaWidget instance
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 07 Feb 2015 12:07:12 +0100 |
parents | ed6d8f7c6026 |
children | ea27925ef2a8 |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py Sat Feb 07 19:24:38 2015 +0100 +++ b/src/browser/sat_browser/base_widget.py Sat Feb 07 12:07:12 2015 +0100 @@ -46,6 +46,10 @@ import base_menu +class NoLiberviaWidgetException(Exception): + pass + + class DragLabel(DragWidget): def __init__(self, text, type_, host=None): @@ -106,14 +110,14 @@ @classmethod def addDropKey(cls, key, cb): - """Add a association between a key and a class to create on drop + """Add a association between a key and a class to create on drop. @param key: key to be associated (e.g. "CONTACT", "CHAT") - @param cb: either a LiberviaWidget instance, or a callback which return one + @param cb: a callable (either a class or method) returning a + LiberviaWidget instance """ DropCell.drop_keys[key] = cb - def onDragEnter(self, event): if self == LiberviaDragWidget.current: return @@ -138,6 +142,10 @@ return (row.rowIndex, cell.cellIndex) def onDrop(self, event): + """ + @raise NoLiberviaWidgetException: something else than a LiberviaWidget + has been returned by the callback. + """ self.removeStyleName('dragover') DOM.eventPreventDefault(event) dt = event.dataTransfer @@ -171,6 +179,8 @@ widgets_panel.removeWidget(_new_panel) elif item_type in self.drop_keys: _new_panel = self.drop_keys[item_type](self.host, item) + if not isinstance(_new_panel, LiberviaWidget): + raise NoLiberviaWidgetException else: log.warning("unmanaged item type") return