Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Dispatch the child added/removed immediately when possible.
Browse files Browse the repository at this point in the history
Dispatch the destroy action to a later time if the object is not
yet initialized.
  • Loading branch information
sccolbert committed Nov 16, 2012
1 parent 1e91a54 commit e869f71
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions enaml/qt/qt_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,12 @@ def set_parent(self, parent):
The parent of this object, or None if it has no parent.
"""
# Note: The added/removed events must be executed on the next
# cycle of the event loop. It's possible that this method is
# being called from the `construct` class method and the child
# of the widget will not yet exist. This means that child event
# handlers that rely on the child widget existing will fail.
# Note: If this object is not yet fully intialized, then the
# added/removed events must be executed on the next cycle of
# the event loop. It's possible that this method is being called
# from the `construct` class method and the toolkit widget will
# not yet exist. This means that child event handlers that rely
# on the child toolkit widget existing will fail.
curr = self._parent
if curr is parent or parent is self:
return
Expand All @@ -465,12 +466,18 @@ def set_parent(self, parent):
if self in curr._children:
curr._children.remove(self)
if curr._initialized:
QtObject.deferred_call(curr.child_removed, self)
if self._initialized:
curr.child_removed(self)
else:
QtObject.deferred_call(curr.child_removed, self)

if parent is not None:
parent._children.append(self)
if parent._initialized:
QtObject.deferred_call(parent.child_added, self)
if self._initialized:
parent.child_added(self)
else:
QtObject.deferred_call(parent.child_added, self)

def child_removed(self, child):
""" Called when a child is removed from this object.
Expand Down Expand Up @@ -628,5 +635,8 @@ def on_action_destroy(self, content):
This method will call the `destroy` method on the object.
"""
self.destroy()
if self._initialized:
self.destroy()
else:
QtObject.deferred_call(self.destroy)

0 comments on commit e869f71

Please sign in to comment.