dialogs module

Wrapper functions to display modo’s built in file and message dialogs.

File Open Dialog

modo.dialogs.fileOpen(ftype, title='Open File(s)', multi=False, path=None)[source]

Display a dialog to choose a file or files for opening.

Returns:

Single file path if ‘multi’ is False, list of files paths if ‘multi’ is true or ‘None’ if the dialog is cancelled by the user.

Return type:

string or None

Parameters:
  • ftype (string) – File format type to filter on or None to show all files.
  • title (str) – Dialog title.
  • multi (Boolean) – Enable multi-select of files in the dialog.
  • path (str) – Optional path to open the dialog at.

Open dialogs use a file type to filter the load dialog. A file type is the class of data to be loaded or saved, such as an image or an object and should be one of the known file types, such as text, script, config, macro, image, and so on. Also, the name of any specific loader plug-in can also be used, such as $LWO. If no file type is set, all files will be shown.


File Save Dialog

modo.dialogs.fileSave(ftype, fformat, fspec='extension', title='Save File', path=None)[source]

Display a dialog to choose a filename to save to.

Returns:

file path or ‘None’ if dialog is cancelled by the user.

Return type:

string or None

Parameters:
  • ftype (string) – File type to save as.
  • fformat (string) – Default file format to save as
  • fspec (string) – How the file format is specified, either by ‘extension’ for file extension or ‘format’ for file format name. Defaults to ‘extension’.
  • title (string) – Dialog title.
  • path (string) – Optional default path to open the dialog at.

A save dialog is identical to an open dialog, but adds a save format to select a specific default file format within the file type to save as. This format will be selected by default when the dialog opens The file format can be set either by its default extension, which is the default behavior, or by the file format’s internal name.


Custom File Dialog

modo.dialogs.customFile(dtype, title, names, unames, patterns=None, ext=None, path=None)[source]

Displays a file open or file save dialog for one or more custom file types.

Returns:

A single file path for “fileSave’ and ‘fileOpen’ dialogs, a list of file paths for ‘fileOpenMulti’ dialogs or ‘None’ if dialog is cancelled by the user.

Return type:

string or None

Parameters:
  • dtype (string.) – Dialog type, string, one of ‘fileOpen’, ‘fileOpenMulti’ or ‘fileSave’.
  • title (string.) – Dialog title.
  • names (list or tuple of strings.) – List or tuple of file format type names. This is an internal name for use by the script, and can be read out after the dialog is dismissed by querying dialog.fileSaveFormat.
  • unames (list or tuple of strings.) – List of user names that will be displayed in the dialog for each of the types specified in ftype.
  • patterns (list or tuple of strings.) – Optional collection of semicolon-delimited string lists of file extensions that the particular file format supports. Only used for fileOpen dialogs. Each extension must include a leading asterisk and period for the filtering to work properly, such as ‘.jpg;.jpeg’.
  • ext (list or tuple of strings.) – Optional collection of save extensions, one for each of the types specified in ftype. each ext is a single file extension that will automatically be appended to the end of the filename selected in a save dialog. The period should not be entered, just the extension such as lwo, tga or txt.
  • path (string.) – Optional default path to open the dialog at.

File open examples:

# Single file format
inpath = modo.dialogs.customFile('fileOpen', 'Open File', ('text',), ('Text File',), ('*.txt',))

# Multiple file formats
inpath = modo.dialogs.customFile('fileOpen', 'Open File', ('text', 'html',),
                           ('Text File', 'HTML FIle'), ('*.txt', '*.html',))

# open multiple files
inpaths = modo.dialogs.customFile('fileOpenMulti', 'Open File', ('text',), ('Text File',), ('*.txt',))

File save examples:

# Single file format
outpath = modo.dialogs.customFile('fileSave', 'Save File', ('text',), ('Text File',), ext=('txt',))

#Multiple file formats
outpath = modo.dialogs.customFile('fileSave', 'Save File', ('text', 'html',),
                            ('Text File', 'HTML FIle'), ext=('txt', 'html',))

Directory Browser Dialog

modo.dialogs.dirBrowse(title, path=None)[source]

Display a directory dialog.

Returns:

file path or ‘None’ if dialog is cancelled by the user.

Return type:

string or None

Parameters:
  • title (string) – Dialog title string.
  • path (string) – Optional default path to open the dialog at.

Alert (message) Dialog

modo.dialogs.alert(title, message, dtype='info')[source]

A simple alert dialog. Type can be any one of ‘info’, ‘warning’ or ‘error’ depending on the value passed for ‘dtype’, defaults to ‘info’

Parameters:
  • title (string) – Dialog title.
  • dtype (string) – Dialog type. One of ‘info’, ‘warning’, ‘error’. Defaults to ‘info’
  • message (string) – Dialog message.

OK/Cancel Dialog

modo.dialogs.okCancel(title, message)[source]

A two button OK/Cancel message dialog.

Returns:

‘ok’ or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

Yes/No Dialog

modo.dialogs.yesNo(title, message)[source]

A two button Yes/No message dialog.

Returns:

‘yes’ or ‘no’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

OK to Save Dialog

modo.dialogs.saveOK(title, message)[source]

A Save OK dialog.

Returns:

‘save’, ‘no’ or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

Yes/No/Cancel Dialog

modo.dialogs.yesNoCancel(title, message)[source]

A three button Yes/No/Cancel message dialog.

Returns:

‘yes’, or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

Yes/No/No to all Dialog

modo.dialogs.yesnoToAll(title, message)[source]

A three option Yes/No/No to all dialog.

Returns:

‘yes’, ‘noall’ or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

Note

There is an issue with the underlying Python API in that ‘successful’ dismissal of message dialogs returns ‘None’ instead of a valid return code. This means that ‘ok’, ‘yes’ and ‘yes to all’ are indistinguishable results. Until this is fixed The following set of dialogs will only return either ‘ok’ or ‘yes’ on success.


Yes/Yes to All/Cancel Dialog

modo.dialogs.yesAllCancel(title, message)[source]

A three button Yes/Yes to all/Cancel dialog.

Returns:

‘yes’, ‘yesall’ or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.

Yes/No/All Dialog

modo.dialogs.yesNoAll(title, message)[source]

A four option Yes/Yes to all/No/No to all dialog.

Returns:

‘yes’, ‘yestoall’, ‘no’, ‘notoall’ or ‘cancel’

Return type:

string

Parameters:
  • title (string) – Dialog title.
  • message (string) – Dialog message.