wxProgressDialog like behaviour for a wxDialog
-
06-07-2019 - |
Question
I want to create modal dialog but which shouldn't behave in a modal way i.e. control flow should continue
if i do
dlg = wx.Dialog(parent)
dlg.ShowModal()
print "xxx"
dlg.Destroy()
"xxx" will not get printed, but in case of progress dialog
dlg = wx.ProgressDialog.__init__(self,title, title, parent=parent, style=wx.PD_APP_MODAL)
print "xxx"
dlg.Destroy()
"xxx" will get printed
so basically i want to achieve wx.PD__APP__MODAL for a normal dialog?
Solution 2
It was very trivial, just using wx.PD_APP_MODAL style in wx.Dialog allows it to be modal without stopping the program flow, only user input to app is blocked, i thought PD_APP_MODAL is only for progress dialog
OTHER TIPS
Just use Show
instead of ShowModal
.
If your function (the print "xxx"
part) runs for a long time you will either have to manually call wx.SafeYield
every so often or move your work to a separate thread and send custom events to your dialog from it.
One more tip. As I understand, you want to execute some code after the modal dialog is shown, here is a little trick for a special bind to EVT_INIT_DIALOG
that accomplishes just that.
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
btn = wx.Button(self, label="Show Dialog")
btn.Bind(wx.EVT_BUTTON, self.ShowDialog)
def ShowDialog(self, event):
dlg = wx.Dialog(self)
dlg.Bind(wx.EVT_INIT_DIALOG, lambda e: wx.CallAfter(self.OnModal, e))
dlg.ShowModal()
dlg.Destroy()
def OnModal(self, event):
wx.MessageBox("Executed after ShowModal")
app = wx.PySimpleApp()
app.TopWindow = TestFrame()
app.TopWindow.Show()
app.MainLoop()