On Mon, Mar 5, 2012 at 5:34 PM, Janjaap Bos <[email protected]> wrote: > Looks good, but breaks for VerticalPanel and HorizontalPanel, because they > redefine insert. > When I apply the change below also to them it works fine.
ok waitwait.... err... what you have there is something which ignores the container argument (if it's set). what i'll do is slightly modify this so that if it's not set, it picks up self.getBody() rather than self.getElement() in the case of the Vert Panel and self.tableRow in the Horiz case. l. > diff --git a/library/pyjamas/ui/ComplexPanel.py > b/library/pyjamas/ui/ComplexPanel.py > index 190b747..8cfbf99 100644 > --- a/library/pyjamas/ui/ComplexPanel.py > +++ b/library/pyjamas/ui/ComplexPanel.py > @@ -27,7 +27,20 @@ class ComplexPanel(Panel): > else: > self.insert(widget, self.getWidgetCount()) > > - def insert(self, widget, container, beforeIndex): > + def insert(self, widget, container, beforeIndex=None): > + """ has two modes of operation: > + widget, beforeIndex > + widget, container, beforeIndex. > + if beforeIndex argument is not given, the 1st mode is assumed. > + this technique is less costly than using *args. > + """ > + if widget.getParent() == self: > + return > + > + if beforeIndex is None: > + beforeIndex = container > + container = self.getElement() > + > if widget.getParent() == self: > return > > diff --git a/library/pyjamas/ui/HorizontalPanel.py > b/library/pyjamas/ui/HorizontalPanel.py > index 0f33618..941e04e 100644 > --- a/library/pyjamas/ui/HorizontalPanel.py > +++ b/library/pyjamas/ui/HorizontalPanel.py > @@ -27,7 +27,23 @@ class HorizontalPanel(CellPanel): > self.tableRow = DOM.createTR() > DOM.appendChild(self.getBody(), self.tableRow) > > - def insert(self, widget, beforeIndex): > + def insert(self, widget, container, beforeIndex=None): > + """ has two modes of operation: > + widget, beforeIndex > + widget, container, beforeIndex. > + if beforeIndex argument is not given, the 1st mode is assumed. > + this technique is less costly than using *args. > + """ > + if widget.getParent() == self: > + return > + > + if beforeIndex is None: > + beforeIndex = container > + container = self.getElement() > + > + if widget.getParent() == self: > + return > + > widget.removeFromParent() > > td = DOM.createTD() > diff --git a/library/pyjamas/ui/VerticalPanel.py > b/library/pyjamas/ui/VerticalPanel.py > index 9b122b6..f33f729 100644 > --- a/library/pyjamas/ui/VerticalPanel.py > +++ b/library/pyjamas/ui/VerticalPanel.py > @@ -21,7 +21,23 @@ from pyjamas.ui import HasVerticalAlignment > > class VerticalPanel(CellPanel): > > - def insert(self, widget, beforeIndex): > + def insert(self, widget, container, beforeIndex=None): > + """ has two modes of operation: > + widget, beforeIndex > + widget, container, beforeIndex. > + if beforeIndex argument is not given, the 1st mode is assumed. > + this technique is less costly than using *args. > + """ > + if widget.getParent() == self: > + return > + > + if beforeIndex is None: > + beforeIndex = container > + container = self.getElement() > + > + if widget.getParent() == self: > + return > + > widget.removeFromParent() > > tr = DOM.createTR() > > > > -Janjaap > > > > 2012/3/5 lkcl luke <[email protected]> >> >> the bug's actually in ComplexPanel. let me know if this works. tests >> required to make sure nothing breaks because of this! >> >> l. >> >> lkcl@teenymac:~/pyjamas/library/pyjamas/ui$ git diff >> diff --git a/library/pyjamas/ui/ComplexPanel.py >> b/library/pyjamas/ui/ComplexPane >> index 190b747..4bc4cf2 100644 >> --- a/library/pyjamas/ui/ComplexPanel.py >> +++ b/library/pyjamas/ui/ComplexPanel.py >> @@ -27,10 +27,20 @@ class ComplexPanel(Panel): >> else: >> self.insert(widget, self.getWidgetCount()) >> >> - def insert(self, widget, container, beforeIndex): >> + def insert(self, widget, container, beforeIndex=None): >> + """ has two modes of operation: >> + widget, beforeIndex >> + widget, container, beforeIndex. >> + if beforeIndex argument is not given, the 1st mode is >> assumed. >> + this technique is less costly than using *args. >> + """ >> if widget.getParent() == self: >> return >> >> + if beforeIndex is None: >> + beforeIndex = container >> + container = self.getElement() >> + >> self.adopt(widget, container) >> self.children.insert(beforeIndex, widget) > >

