comparison 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
comparison
equal deleted inserted replaced
196:c2639c9f86ea 197:0fc32122a877
99 _new_panel = LiberviaDragWidget.current 99 _new_panel = LiberviaDragWidget.current
100 if self == _new_panel: # We can't drop on ourself 100 if self == _new_panel: # We can't drop on ourself
101 return 101 return
102 # we need to remove the widget from the panel as it will be inserted elsewhere 102 # we need to remove the widget from the panel as it will be inserted elsewhere
103 widgets_panel = _new_panel.getWidgetsPanel() 103 widgets_panel = _new_panel.getWidgetsPanel()
104 if widgets_panel.getLiberviaWidgetsCount() == 1: 104 wid_row = widgets_panel.getWidgetCoords(_new_panel)[0]
105 # the dropped widget is the only one in the panel, 105 row_wids = widgets_panel.getLiberviaRowWidgets(wid_row)
106 # we don't do anything 106 if len(row_wids) == 1 and wid_row == widgets_panel.getWidgetCoords(self)[0]:
107 # the dropped widget is the only one in the same row
108 # as the target widget (self), we don't do anything
107 self.removeStyleName('dragover') 109 self.removeStyleName('dragover')
108 return 110 return
109 widgets_panel.removeWidget(_new_panel) 111 widgets_panel.removeWidget(_new_panel)
110 elif item_type in self.drop_keys: 112 elif item_type in self.drop_keys:
111 _new_panel = self.drop_keys[item_type](self.host,item) 113 _new_panel = self.drop_keys[item_type](self.host,item)
458 def removeWidget(self, wid): 460 def removeWidget(self, wid):
459 """Remove a widget and the cell where it is""" 461 """Remove a widget and the cell where it is"""
460 _row, _col = self.flextable.getIndex(wid) 462 _row, _col = self.flextable.getIndex(wid)
461 self.flextable.remove(wid) 463 self.flextable.remove(wid)
462 self.flextable.removeCell(_row, _col) 464 self.flextable.removeCell(_row, _col)
463 if self.flextable.getCellCount(_row) == 2: #we have only the borders left, we remove the row 465 if not self.getLiberviaRowWidgets(_row): #we have no more widgets, we remove the row
464 self.flextable.removeRow(_row) 466 self.flextable.removeRow(_row)
465 _max_cols = 1 467 _max_cols = 1
466 for row_idx in xrange(self.flextable.getRowCount()): 468 for row_idx in xrange(self.flextable.getRowCount()):
467 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx)) 469 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx))
468 if _max_cols != self._max_cols: 470 if _max_cols != self._max_cols:
479 current.onWidgetPanelRemove(self) 481 current.onWidgetPanelRemove(self)
480 return 482 return
481 current = current.getParent() 483 current = current.getParent()
482 print "Error: no MainTabPanel found !" 484 print "Error: no MainTabPanel found !"
483 485
486 def getWidgetCoords(self, wid):
487 return self.flextable.getIndex(wid)
488
489 def getLiberviaRowWidgets(self, row):
490 """ Return all the LiberviaWidget in the row """
491 return [wid for wid in self.getRowWidgets(row) if isinstance(wid, LiberviaWidget)]
492
493 def getRowWidgets(self, row):
494 """ Return all the widgets in the row """
495 widgets = []
496 cols = self.flextable.getCellCount(row)
497 for col in xrange(cols):
498 widgets.append(self.flextable.getWidget(row, col))
499 return widgets
500
484 def getLiberviaWidgetsCount(self): 501 def getLiberviaWidgetsCount(self):
485 """ Get count of contained widgets """ 502 """ Get count of contained widgets """
486 return len([wid for wid in self.flextable if isinstance(wid, LiberviaWidget)]) 503 return len([wid for wid in self.flextable if isinstance(wid, LiberviaWidget)])
487 504
488 def getIndex(self, wid): 505 def getIndex(self, wid):