There are times when a program has to work and needs to block the user, or at least warn the user, that no actions should be taken. A simple way to do this is wx.BusyInfo.
Here is a very simple application:
1 """BusyInfo Test
2 Hold the user at bay for a while.
3 """
4 import wx
5 import time
6 class TestPanel(wx.Panel):
7
8 def __init__(self, *args, **kwds):
9 wx.Panel.__init__(self, *args, **kwds)
10 self.BusyButton = wx.Button(self, wx.ID_ANY, label="Get Busy")
11 self.BusyButton.Bind(wx.EVT_BUTTON, self.OnGetBusy)
12
13 sizer = wx.BoxSizer(wx.VERTICAL)
14 sizer.Add(self.BusyButton, 0, wx.ALL, 20)
15 self.SetSizerAndFit(sizer)
16 self.Layout()
17
18 def OnGetBusy(self, event):
19 bi = wx.BusyInfo("Working, please wait", self)
20 time.sleep(5)
21 bi.Destroy()
22
23 class TestFrame(wx.Frame):
24 def __init__(self,*args,**kwds):
25 wx.Frame.__init__(self,*args,**kwds)
26
27 panel = TestPanel(self,wx.ID_ANY)
28 sizer=wx.BoxSizer(wx.VERTICAL)
29 sizer.Add(panel,1,wx.EXPAND)
30 self.SetSizerAndFit(sizer)
31 self.Layout()
32 self.CenterOnScreen()
33
34 class TestApp(wx.App):
35 def OnInit(self):
36 mainFrame = TestFrame(None, wx.ID_ANY, "BusyInfo Test")
37 self.SetTopWindow(mainFrame)
38 mainFrame.Show()
39 return 1
40
41 app = TestApp(0)
42 app.MainLoop()
BusyInfo does not block events. In this case, the BusyInfo window doesn't block the frame's title bar, so the bar can be moved or closed while the BusyInfo shows, and these events are processed after the BusyInfo is destroyed.