diff browser_side/base_widget.py @ 197:0fc32122a877

browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit. Widgets are now (hopefuly) safely movable
author Goffi <goffi@goffi.org>
date Wed, 06 Mar 2013 22:36:21 +0100
parents c2639c9f86ea
children ab239b3b67b3
line wrap: on
line diff
--- a/browser_side/base_widget.py	Tue Mar 05 01:20:59 2013 +0100
+++ b/browser_side/base_widget.py	Wed Mar 06 22:36:21 2013 +0100
@@ -101,9 +101,11 @@
                 return
             # we need to remove the widget from the panel as it will be inserted elsewhere
             widgets_panel = _new_panel.getWidgetsPanel()
-            if widgets_panel.getLiberviaWidgetsCount() == 1:
-                # the dropped widget is the only one in the panel,
-                # we don't do anything
+            wid_row = widgets_panel.getWidgetCoords(_new_panel)[0]
+            row_wids = widgets_panel.getLiberviaRowWidgets(wid_row)
+            if len(row_wids) == 1 and wid_row == widgets_panel.getWidgetCoords(self)[0]:
+                # the dropped widget is the only one in the same row
+                # as the target widget (self), we don't do anything
                 self.removeStyleName('dragover')
                 return
             widgets_panel.removeWidget(_new_panel)
@@ -460,7 +462,7 @@
         _row, _col = self.flextable.getIndex(wid)
         self.flextable.remove(wid)
         self.flextable.removeCell(_row, _col)
-        if self.flextable.getCellCount(_row) == 2: #we have only the borders left, we remove the row
+        if not self.getLiberviaRowWidgets(_row): #we have no more widgets, we remove the row
             self.flextable.removeRow(_row)
         _max_cols = 1
         for row_idx in xrange(self.flextable.getRowCount()):
@@ -481,6 +483,21 @@
                 current = current.getParent()
             print "Error: no MainTabPanel found !"
 
+    def getWidgetCoords(self, wid):
+        return self.flextable.getIndex(wid)
+
+    def getLiberviaRowWidgets(self, row):
+        """ Return all the LiberviaWidget in the row """
+        return [wid for wid in self.getRowWidgets(row) if isinstance(wid, LiberviaWidget)]
+
+    def getRowWidgets(self, row):
+        """ Return all the widgets in the row """
+        widgets = []
+        cols = self.flextable.getCellCount(row)
+        for col in xrange(cols):
+            widgets.append(self.flextable.getWidget(row, col))
+        return widgets
+
     def getLiberviaWidgetsCount(self):
         """ Get count of contained widgets """
         return len([wid for wid in self.flextable if isinstance(wid, LiberviaWidget)])