■ Dialogs are used to handle interaction with the user in cases where there is a specific set of information to be obtained, and the interaction is usually over quickly. In wxPython, you can use the generic wx.Dialog class to create your own dialogs, or you can use one of several predefined dialogs. In many cases, commonly used dialogs also have convenience functions that make the use of the dialog easier.
■ Dialogs can be displayed modally, meaning that all other user input within the application is blocked while the dialog is visible. A modal dialog is invoked by using the ShowModal() method, which returns a value based on whether the user pressed OK or Cancel to the dialog. Closing a modal dialog does not destroy it, and the same dialog instance can be used again.
■ There are three generic simple dialogs available in wxPython. wx.Message-Dialog displays an alert box or a yes/no question. wx.TextEntryDialog allows the user to enter text, and wx.SingleChoiceDialog gives the user a choice based on a list of items.
■ When performing a long background task, you can use wx.ProgressDialog to display progress information to the user. The user can pick a file using the standard file dialog by using the wx.FileDialog class. There is a standard tree view which allows the user to pick a directory that is created using the wx.DirDialog class.
■ You can access the standard font picker using wx.FontDialog and the standard color picker using wx.ColorDialog. In both cases, the dialog behavior and user response are controlled by a separate data class.
■ To browse thumbnail images, use the wxPython-specific class wx.lib.image-browser.ImageDialog. This class allows the user to walk through her file system and select an image.
■ You can create a wizard by using the wx.wizard.Wizard class to tie together a group of related dialog forms. The dialog forms are instances of either the class wx.wizard.WizardSimplePage or wx.wizard.WizardPage. The difference is that the page to page path for a simple page needs to be laid out before the wizard is displayed, while the standard page allows you to manage that logic at runtime.
■ Startup tips can easily be displayed using the functions wx.CreateFileTip-Provider and wx.ShowTip.
■ Validators are powerful objects that can automatically prevent a dialog from closing if the data entered is incorrect. They can also automatically transfer data between a dialog display and an external object, and can verify data entry on the fly.
Was this article helpful?