Skip to content

Commit

Permalink
Set the window modality just before the window is shown on Wx.
Browse files Browse the repository at this point in the history
This prevents exceptions raised during initialization from blocking the
rest of the app, since Wx blocks as soon as the flag is set, instead of
when the window becomes visible.
  • Loading branch information
sccolbert committed Apr 4, 2013
1 parent a852578 commit 56a1e00
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions enaml/wx/wx_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def init_widget(self):
self.set_title(d.title)
if -1 not in d.initial_size:
self.set_initial_size(d.initial_size)
if d.modality != 'non_modal':
self.set_modality(d.modality)
if d.icon:
self.set_icon(d.icon)
self.widget.Bind(wx.EVT_CLOSE, self.on_close)
Expand Down Expand Up @@ -274,3 +272,35 @@ def set_modality(self, modality):
self.widget.MakeModal(False)
else:
self.widget.MakeModal(True)

#--------------------------------------------------------------------------
# Overrides
#--------------------------------------------------------------------------
def set_visible(self, visible):
""" Set the visibility state on the underlying widget.
This override sets the modality to false when hiding the window
and enabled it when showing the window (if requested).
"""
modality = self.declaration.modality
self.widget.MakeModal(visible and modality != 'non_modal')
self.widget.Show(visible)

def ensure_visible(self):
""" Ensure the widget is visible.
This override forwards to the 'set_visible' method so that the
window modality is handled properly.
"""
self.set_visible(True)

def ensure_hidden(self):
""" Ensure the widget is hidden.
This override forwards to the 'set_visible' method so that the
window modality is handled properly.
"""
self.set_visible(False)

0 comments on commit 56a1e00

Please sign in to comment.