@@ -154,41 +154,34 @@ def destroy(self):
154154 def child_added (self , child : WebComponent ):
155155 """Handle the child added event from the declaration.
156156
157- This handler will insert the child toolkit widget in the correct.
158- position. Subclasses which need more control should reimplement this
159- method.
157+ This handler will insert the child into the tree at the
158+ appropriate index.
160159
161160 """
161+ w = self .widget
162+ if w is None :
163+ return
164+
162165 # Use insert to put in the correct spot
163166 d = self .declaration
164167 assert d is not None
165- i = d .children .index (child .declaration )
166- widget = self .widget
167- if widget is None :
168- return False
169- widget .insert (i , child .widget )
168+ i = d ._child_index (child .declaration )
169+ w .insert (i , child .widget )
170170
171- def child_moved (self , child : WebComponent ):
171+ def child_moved (self , child : WebComponent ) -> bool :
172172 """Handle the child moved event from the declaration.
173173
174174 This handler will pop the child and insert it in the correct position
175175 if it isn't already there.
176176
177- Subclasses which need more control should reimplement this method.
178-
179- Returns
180- -------
181- was_moved: Bool
182- Whether a move was performed or not
183-
184177 """
185- # Determine the new index
186- d = self .declaration
187- assert d is not None
188- i = d .children .index (child .declaration )
189178 w = self .widget
190179 if w is None :
191180 return False
181+ # Determine the new index
182+ d = self .declaration
183+ assert d is not None
184+ i = d ._child_index (child .declaration )
192185 j = w .index (child .widget )
193186 if j == i :
194187 return False # Already in the correct spot
0 commit comments