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

Commit

Permalink
Fix FileDialog lifetime bug from issue #217
Browse files Browse the repository at this point in the history
  • Loading branch information
sccolbert committed Jan 23, 2013
1 parent 185dfa3 commit 8e354de
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion enaml/widgets/file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#------------------------------------------------------------------------------
from traits.api import Enum, Bool, Callable, List, Unicode

from enaml.application import deferred_call
from enaml.core.messenger import Messenger
from enaml.core.trait_types import EnamlEvent

Expand Down Expand Up @@ -78,7 +79,21 @@ def open(self):
content['filters'] = self.filters
content['selected_filter'] = self.selected_filter
content['native_dialog'] = self.native_dialog
self.send_action('open', content)
# A common dialog idiom is as follows:
#
# dlg = FileDialog(foo, ...)
# dlg.open()
#
# With this scenario, the dialog will not have been initialized
# by the time the `open` method is called, since the child event
# of the dialog parent is batched by the Messenger class. The
# 'open' action must therefore be deferred in order to allow the
# dialog be fully initialized and capable of sending messages.
# Otherwise, the 'open' message will be dropped.
if self.is_active:
self.send_action('open', content)
else:
deferred_call(self.send_action, 'open', content)

#--------------------------------------------------------------------------
# Message Handling
Expand Down

0 comments on commit 8e354de

Please sign in to comment.