WxPython in Action chap 9 notes
1. Modal Dialog (mode Dialog box)
A modal dialog blocks other widgets from processing user events until it is closed;
In other words, it places the user in dialog mode for the duration of its existence.
The Mode dialog box blocks other widgets from receiving user events until the mode dialog box is closed.
Strictly speaking, there is no difference in the appearance of the dialog and frame, but the way to handle events is different.
Generally, dialog is slightly simpler in appearance, so wx. Panel is rarely used.
Wx. Dialog has the property of wx. Panel. widgets is generally directly added to wx. Dialog.
2. Display and close the Dialog
The usage of Modal Dialog is slightly different from that of a normal Frame.
The simplest example code is as follows:
import wxclass SubclassDialog(wx.Dialog): def __init__(self): wx.Dialog.__init__(self, None, -1, 'Dialog Subclass', size=(300, 100)) okButton = wx.Button(self, wx.ID_OK, "OK", pos=(15, 15)) okButton.SetDefault() cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel", pos=(115, 15))if __name__ == '__main__': app = wx.PySimpleApp() dialog = SubclassDialog() result = dialog.ShowModal() if result == wx.ID_OK: print "OK" else: print "Cancel" dialog.Destroy()
2.1 display Dialog
Display that the Dialog uses ShowModal (). The program waits until the ShowModal () Execution ends and obtains the returned value.
In this case, Dialog is the only component of the wxPython application that accepts user events. Other applications are not affected.
2.2 end Dialog Mode
Call the EndModal (retCode) method to disable (close) Dialog Mode. The retCode is an int value and is returned by ShowModal.
At this point, the Dialog Mode is ended and the Dialog Mode is not destroyed. This Dialog can be displayed elsewhere.
EndModal () is usually called in the event handler ().
2.3 destroy Dialog
Call the Destroy () method
2.4 typical usage
dialog == result ==
2.5 handler of the Custom event, which generally needs to call EndModal ()
For example, the handler implementation used to connect to the database is as follows:
OnConnect(self, event==== %, wx.OK | wx.ICON_ERROR)