# HG changeset patch # User Goffi # Date 1309140718 -7200 # Node ID 6c3b3254605f52010ea88950060878921cb39fc6 # Parent a8f027738c16179933f5c8ced7cd78cf4b9a771f browser side: widget removing is now managed diff -r a8f027738c16 -r 6c3b3254605f browser_side/panels.py --- a/browser_side/panels.py Mon Jun 27 03:14:37 2011 +0200 +++ b/browser_side/panels.py Mon Jun 27 04:11:58 2011 +0200 @@ -156,6 +156,7 @@ setting_button.setStyleName('widgetHeader_settingButton') close_button = Image("media/icons/misc/close.png") close_button.setStyleName('widgetHeader_closeButton') + close_button.addClickListener(getattr(self,"onClose")) button_group.add(setting_button) button_group.add(close_button) button_group_wrapper.setWidget(button_group) @@ -171,6 +172,11 @@ def onClick(self, sender): self.host.select(self) + def onClose(self, sender): + print "onClose:", sender + _widgetpanel = self.getParent().getParent() + _widgetpanel.removeWidget(self) + def setTitle(self, text): """change the title in the header of the widget @param text: text of the new title""" @@ -203,6 +209,15 @@ self.add(body_wid) self.setCellHeight(body_wid, '100%') + def doDetachChildren(self): + #We need to force the use of a panel subclass method here, + #for the same reason as doAttachChildren + VerticalPanel.doDetachChildren(self) + + def doAttachChildren(self): + #We need to force the use of a panel subclass method here, else + #the event will not propagate to children + VerticalPanel.doAttachChildren(self) class ScrollPanelWrapper(SimplePanel): """Scroll Panel like component, wich use the full available space @@ -673,7 +688,6 @@ self.flextable.setWidget(last_row, 2, RightBorderWidget(self.host)) cellFormatter.setHorizontalAlignment(last_row, 2, HasAlignment.ALIGN_RIGHT) row = last_row - last_row+=1 elif isinstance(prev_wid, LeftBorderWidget): if col!=0: @@ -695,18 +709,22 @@ _max_cols = max(self._max_cols, self.flextable.getCellCount(row)) if _max_cols != self._max_cols: - #we hage to adjust sizes self._max_cols = _max_cols - width = 100.0/max(1, self._max_cols-2) #we don't count the borders - for row_idx in range(self.flextable.getRowCount()): - for col_idx in range(self.flextable.getCellCount(row_idx)): - _widget = self.flextable.getWidget(row_idx, col_idx) - if not isinstance(_widget, BorderWidget): - td_elt = _widget.getElement().parentNode - DOM.setStyleAttribute(td_elt, "width", "%.2f%%" % width) + self._sizesAdjust() - cellFormatter.setColSpan(last_row, 0, self._max_cols) + def _sizesAdjust(self): + cellFormatter = self.flextable.getFlexCellFormatter() + width = 100.0/max(1, self._max_cols-2) #we don't count the borders + + for row_idx in xrange(self.flextable.getRowCount()): + for col_idx in xrange(self.flextable.getCellCount(row_idx)): + _widget = self.flextable.getWidget(row_idx, col_idx) + if not isinstance(_widget, BorderWidget): + td_elt = _widget.getElement().parentNode + DOM.setStyleAttribute(td_elt, "width", "%.2f%%" % width) + last_row = max(0, self.flextable.getRowCount()-1) + cellFormatter.setColSpan(last_row, 0, self._max_cols) def addWidget(self, wid): """Add a widget to a new cell on the next to last row""" @@ -714,6 +732,20 @@ print "putting widget %s at %d, %d" % (wid, last_row, 0) self.changeWidget(last_row, 0, wid) + def removeWidget(self, wid): + """Remove a widget and the cell where it is""" + _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 + self.flextable.removeRow(_row) + _max_cols = 1 + for row_idx in xrange(self.flextable.getRowCount()): + _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx)) + if _max_cols != self._max_cols: + self._max_cols = _max_cols + self._sizesAdjust() + class MainDiscussionPanel(HorizontalPanel): def __init__(self, host):