Looks good, but breaks for VerticalPanel and HorizontalPanel, because they
redefine insert.
When I apply the change below also to them it works fine.
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)
>