diff src/browser/sat_browser/base_widget.py @ 608:ea27925ef2a8 frontends_multi_profiles

merges souliane changes
author Goffi <goffi@goffi.org>
date Mon, 09 Feb 2015 21:58:49 +0100
parents 7af8f4ab3675 462d0458e679
children ec77c2bc18d3
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py	Mon Feb 09 21:56:30 2015 +0100
+++ b/src/browser/sat_browser/base_widget.py	Mon Feb 09 21:58:49 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