5.7 Common dialog boxes

The ABAQUS GUI Toolkit provides some pre-built dialog boxes for handling common operations. This section provides details on how to use these dialog boxes. The following topics are covered:


5.7.1 File/Directory selector

The File Selector dialog box is used to gather a file or directory name from the user. It has the following characteristics:

  • The title bar can be set.

  • The file filters can be set.

  • The following error checking is provided:

    • Check to see if the file exists.

    • Check for proper permissions.

    • Check to see if the selection is a file.

  • Allows read-only access.

  • Accepts keywords and a target.

The file selection dialog box has the following prototypes:

AFXFileSelectorDialog(form, title, fileNameKw, 
    readOnlyKw, opts, patterns, patternIndexTgt)
AFXFileSelectorDialog(parent, title, fileNameKw, 
    readOnlyKw, opts, patterns, patternIndexTgt)

You use the first constructor when you have a form associated with the dialog box that issues a command; for example, the dialog box that appears when you click FileOpen Database. You use the second constructor when the dialog box collects input from the user to be used in another dialog box. For example, when printing to a file from the Print dialog box, the user is presented with a text field to enter a file name and a Select button. The Select button posts a file selection dialog box that returns the selected file to the Print dialog box but does not issue any command.

You must create the fileNameKw argument using the AFXStringKeyword method. Similarly, you must create the readOnlyKw argument using the AFXBoolKeyword method. If the user clicks OK, the file selection dialog box automatically updates the fileNameKw and readOnlyKw arguments. In addition, when the dialog box is posted, it will set the current directory based on the path of the fileNameKw argument. This means that the dialog box remembers the last directory visited by the user when the application posts the dialog box again.

The following flags are available for the opts argument:

AFXSELECTFILE_EXISTING

Allows the selection of an existing file only.

AFXSELECTFILE_MULTIPLE

Allows the selection of multiple existing files only.

AFXSELECTFILE_DIRECTORY

Allows the selection of an existing directory only.

AFXSELECTFILE_REMOTE_HOST

Allows the opening of files on a remote host.

You specify the patterns argument as a series of patterns separated by \n. The value of the target specified by the patternIndexTgt argument determines which pattern is initially shown when the dialog box is posted.

The following is an example of how a file selection dialog box can be posted from a form:

def getFirstDialog(self):

    patterns = 'Output Database (*.odb)\nAll Files (*.*)'
    db = AFXFileSelectorDialog(self, 'Open ODB', 
        self.nameKw, self.readOnlyKw, AFXSELECTFILE_EXISTING, 
        patterns, self.patternIndexTgt)
    db.setReadOnlyPatterns('*.odb')
    self.setModal(TRUE)
    return db

The following is an example of how a directory selection dialog box can be posted from another dialog box:

def onCmdDirectory(self, sender, sel, ptr):
    
    if not self.dirDb:
        self.dirDb = AFXFileSelectorDialog(self, 
            'Select a Directory',self.form.dirNameKw, 
            None, AFXSELECTFILE_DIRECTORY)
        self.dirDb.create()
    self.dirDb.showModal()
    return 1


5.7.2 Print dialog box

The Print dialog box provides standard printing functionality. To post the Print dialog box from a button in your dialog box, you first access the print form mode by using the getPrintForm method of the FileToolsetGui class. This can be done by storing a pointer to the form as shown in the following example:

from sessionGui import FileToolsetGui

class MyMainWindow(AFXMainWindow):

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def __init__(self, app, windowTitle=''):

    ... 
    fileToolset = FileToolsetGui()
    self.printForm = fileToolset.getPrintForm()
    self.registerToolset(fileToolset, 
        GUI_IN_MENUBAR|GUI_IN_TOOLBAR)
    ...

Then you can use the print form in your dialog box class, as shown below:

printForm = getAFXApp().getAFXMainWindow().printForm
FXButton(parent, 'Print...', None, printForm, 
    AFXMode.ID_ACTIVATE)

To access the print form, you must construct and register the file toolset. However, you cannot access the print form from within a plug-in. As a result, you can only use the approach described here in a customized application.


5.7.3 Color selector dialog box

The AFXColorSelector widget provides the ability to choose a color from a predefined palette of colors. This dialog box is posted by an AFXColorButton. For more information, see Color buttons, Section 3.1.10.