class CDialog __init__(self, parent, text) Class CDialog represents a dialog box, a window which generally has text and controls, and is used for user interaction. In general you should try to put all controls in a dialog box instead of a View since dialog boxes have special features such as control traversal with the tab key. You may not draw in a dialog box, and no OnDraw message will be sent. But you can place static controls is a dialog box, such as "label" and "message" controls. Dialog boxes can be "modal" or "modeless". Modal means that the user must dismiss the dialog box before the program will continue. When you create a modal dialog box it is essential to provide a button or other way for the user to call EndDialog(), otherwise it will be impossible to continue. Use Create() and Destroy() to create and destroy a modeless dialog, and use DoModal() and EndDialog() to create and destroy a modal dialog. Dialog boxes receive the message OnInitDialog(self) before they are displayed. This is the place to do layout and other initialization. You can construct controls in __init__ so that the dialog box size may be determined in advance of creation. Or you can create everything in OnInitDialog, set the dialog box size and then call MoveWindowSize(). The function WpyShrinkWrap() is a convenient way to size a dialog box to contain the controls in it. You must call Create() for controls in OnInitDialog. You can not call control.Create() in __init__ because the parent dialog box does not yet exist. If you set the focus to a control within OnInitDialog(), you must return 0; otherwise just return None (the default). To change the color of the window, set dialog.wpyBrush to a background brush. This is probably a bad idea under Windows. If a Python error occurs in modal dialog box code (eg, a syntax error), your app will seem to freeze. The dialog box is still active and must be dismissed before the error message can be printed. Just press the escape key. Instance Variables wpyParent, wpyText, wpyChildList, wpySizeX/Y, wpyLocX/Y wpyDefaultButton, push button object, readonly after Create() A CPushButton object which is pressed if the user types the Enter key. Default buttons only work in dialog boxes, not views. Methods __init__(self, parent, text) Return a dialog box. parent, object The parent of the dialog box, or None. text, string A title to appear at the top of the dialog box. Create(self) Make a modeless dialog box visible by calling the underlying GUI. DoModal(self, parent = None) Make a modal dialog box visible by calling the underlying GUI. Do not call Create() for a modal dialog. The return value is the "result" argument to EndDialog() if the user pressed a button. If the user dismissed the dialog box by pressing the escape key or by using the close box, the return value is None. If the user pressed the enter key and there is a default button, then that button is pressed. If there is no default button, the dialog box is not dismissed. EndDialog(self, result) End a modal dialog with the return value "result". The "result" may be any Python object, not just an integer. Complicated results may be returned as class instances for example. It is an error to call EndDialog() for a modeless dialog. Destroy(self) End a modeless dialog. If called for a modal dialog, end with result None. Messages OnInitDialog(self) Sent before the dialog is displayed. If you set the focus to a control (for example, a CEdit control) within OnInitDialog(), return 0. Otherwise just return None (the default). OnEnter(self) Sent if the user presses the Enter key. The default creates a button press message for the default button if there is one. OnEsc(self) Sent if the user presses the ESC key. The default tries to call self.OnButtonCancel(None) or self.OnButtoncancel(None) or it dismisses the dialog by calling self.Destroy(). For a modal dialog, the return value is None. Standard Dialogs There a number of predefined dialogs you can use. The standard FileOpen and FileWrite dialogs are built in to the system, and are presented as part of the related menu commands. Standard About boxes are also provided and used if you do not write your own. The normal Python "print" statement sends its output to a simple "OK" dialog box. So you can create dialog boxes just by using "print" statements. The output from "print" statements is accumulated and presented when the system is idle, so multi-line print statements work properly. The global function AfxMessageBox() will make simple dialog boxes with up to three buttons. See global.txt. For more complicated dialogs, use the class CWpyDialog. Or just make your own dialogs derived from CDialog. class CWpyDialog The class CWpyDialog makes dialog instances with any number of buttons. The return value from DoModal() is the button number 0, 1, 2, .... If the user presses the ESC key, the return value is None. __init__(self, title, text, aspect, default, *args) title, string A title to appear at the top of the dialog box. text, string A message to display in the dialog. aspect, float or None The aspect ratio of the message as width divided by height. To print as one line, use a large number (such as 99). default, int The number of the default button (0, 1, ...) or -1 for no default. *args, strings as multiple arguments, or a tuple of strings, or a list of strings. Any number of strings representing text to be placed in the buttons. class CFlashDialog This displays a modeless dialog which will destroy itself after a short delay. It is used to flash messages at the user without requiring a button press to dismiss it. __init__(self, parent, text) parent, string The parent of the dialog. text, string The message text to display in the dialog. self.delay The attribute self.delay can be changed before self.Create() is called to set the delay to the specified number of milliseconds. class CFileDialogOpen class CFileDialogSave These classes make the standard file open/save dialog boxes. The only method is DoModal(). Be sure to use os.path methods to maintain portability. __init__(self, name = None, filter = ("All Files", "*"), ext = None) name, string A default file name to put in the file selection box, or None. filter, tuple of pairs of strings A filter to control the files shown in the list box. The first string is the name of the file type, the second is a file wild card which will be expanded into a list of files to be shown in the list box. Repeated pairs of strings are supported on Windows only. ext, string A default file name extension such as ".txt". If the file name entered by the user does not contain ".", then ext is appended. Examples # Make a modal dialog box class DemoDialog(CDialog): def __init__(self): CDialog.__init__(self, None, "Dialog Demo") self.b = CPushButton(self, "OK") self.b.wpySizeX = self.b.wpySizeX * 3 self.m = CMessage(self, "This is a demonstration of dialogs" self.wpySizeX = self.m.wpySizeX * 1.2 self.wpySizeY = self.b.wpySizeY * 4 def OnInitDialog(self): rect = self.GetClientRect() self.m.WpyPlace(rect, 0.5, 0.1, "n") self.b.WpyPlace(rect, 0.5, 0.8, "center") self.m.Create() self.b.Create() def OnButtonOK(self, control): self.EndDialog("hello there") # Show a modal dialog, print the result in another dialog result = DemoDialog().DoModal() print result # Make and show a modal dialog using AfxMessageBox AfxMessageBox("Value not recognized") # Make and show a modal dialog using CWpyDialog i = CWpyDialog("Heading", "Will the moon be full tonight?", 99, -1, "Yes", "No", "Maybe").DoModal() # Request a file name name = CFileDialogOpen().DoModal(parent)