MeVisLab Scripting Reference
MLABFileDialog Class Reference

#include <mlabScriptWrappers.h>

Inherits QObject.

Public Types

enum  Option { ShowFilesAndDirs = 0 , ShowDirsOnly = QFileDialog::ShowDirsOnly , DontConfirmOverwrite = QFileDialog::DontConfirmOverwrite , DontUseNativeDialog = QFileDialog::DontUseNativeDialog }
 

Public Slots

FileDialog methods


QString getOpenFileName (const QString &initially, const QString &filter, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QString getOpenFileName (const QString &initially, const QString &filter, const QString &caption, const QString &browsingGroup, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QString getSaveFileName (const QString &initially, const QString &filter, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QString getSaveFileName (const QString &initially, const QString &filter, const QString &caption, const QString &browsingGroup, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QString getExistingDirectory (const QString &dir, const QString &caption, Option options=ShowDirsOnly, MLABWidgetControl *parent=nullptr)
 
QString getExistingDirectory (const QString &dir, const QString &caption, const QString &browsingGroup, Option options=ShowDirsOnly, MLABWidgetControl *parent=nullptr)
 
QStringList getOpenFileNames (const QString &filter, const QString &dir, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QStringList getOpenFileNames (const QString &filter, const QString &dir, const QString &caption, const QString &browsingGroup, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
 
QString lastFileDialogPath (const QString &browsingGroup="")
 
void setLastFileDialogPath (const QString &path, const QString &browsingGroup="")
 

Detailed Description

Global MLABFileDialog object available in all script.s.

The MLABFileDialog object can be used as follows:

file1 = MLABFileDialog.getOpenFileName(ctx.localPath(), "Def/Script files (*.def *.script)", "Open file")
if not file1 == "":
pass # ok
else:
pass # cancel
MLAB.log(file1)
file2 = MLABFileDialog.getSaveFileName(ctx.localPath() + "/test.def", "Def/Script files (*.def *.script)", "Save file")
MLAB.log(file2)
file3 = MLABFileDialog.getExistingDirectory(ctx.localPath(), "Select a Directory")
MLAB.log(file3)
filelist = MLABFileDialog.getOpenFileNames("Def/Script files (*.def *.script)", ctx.localPath(), "Select multiple files")
i = 0
for file in filelist:
ctx.log(str(i) + ": " + file
i = i + 1
Global MLABFileDialog object available in all script.s.
Definition mlabScriptWrappers.h:74
QString getSaveFileName(const QString &initially, const QString &filter, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
Saves a file with a file dialog box, returns absolute path or empty string on cancel.
Definition mlabScriptWrappers.h:144
QString getExistingDirectory(const QString &dir, const QString &caption, Option options=ShowDirsOnly, MLABWidgetControl *parent=nullptr)
Returns an existing directory, returns absolute path or empty string on cancel.
Definition mlabScriptWrappers.h:172
QString getOpenFileName(const QString &initially, const QString &filter, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
Opens a file with a file dialog box, returns absolute path or empty string on cancel.
Definition mlabScriptWrappers.h:111
QStringList getOpenFileNames(const QString &filter, const QString &dir, const QString &caption, Option options=static_cast< Option >(0), MLABWidgetControl *parent=nullptr)
Returns multiple filenames with a file dialog box, returns a list of absolute paths.
Definition mlabScriptWrappers.h:198
Access to all global functions and objects of MLAB.
Definition mlabGlobalScriptAccess.h:79
void log(const QString &text)
Logs the given text to the console.

Member Enumeration Documentation

◆ Option

enum MLABFileDialog::Option

file dialog options

Enumerator
ShowFilesAndDirs 

Show both files and directories in the file dialog. This is the default.

ShowDirsOnly 

Only show directories in the file dialog. By default both files and directories are shown.

DontConfirmOverwrite 

Don't ask for confirmation if an existing file is selected. By default confirmation is requested.

DontUseNativeDialog 

Don't use the native file dialog. By default on Windows, the native file dialog is used.

Member Function Documentation

◆ getExistingDirectory [1/2]

QString MLABFileDialog::getExistingDirectory ( const QString & dir,
const QString & caption,
const QString & browsingGroup,
Option options = ShowDirsOnly,
MLABWidgetControl * parent = nullptr )
slot

Same method with the browsingGroup parameter. (See getOpenFileName() about that.)

◆ getExistingDirectory [2/2]

QString MLABFileDialog::getExistingDirectory ( const QString & dir,
const QString & caption,
Option options = ShowDirsOnly,
MLABWidgetControl * parent = nullptr )
inlineslot

Returns an existing directory, returns absolute path or empty string on cancel.

Script Example:

file1 = MLABFileDialog.getExistingDirectory(ctx.localPath(), "Select a Directory", MLABFileDialog.ShowDirsOnly)
if not file1 == "":
pass # ok
else:
pass # cancel
@ ShowDirsOnly
Only show directories in the file dialog. By default both files and directories are shown.
Definition mlabScriptWrappers.h:81

◆ getOpenFileName [1/2]

QString MLABFileDialog::getOpenFileName ( const QString & initially,
const QString & filter,
const QString & caption,
const QString & browsingGroup,
Option options = static_cast< Option >(0),
MLABWidgetControl * parent = nullptr )
slot

Same method with the browsingGroup parameter.

Parameters
browsingGroupIf initially is empty the last used path is used as starting path. By selecting unique identifiers for browsingGroup you can have different last paths for different purposes.

◆ getOpenFileName [2/2]

QString MLABFileDialog::getOpenFileName ( const QString & initially,
const QString & filter,
const QString & caption,
Option options = static_cast<Option> (0),
MLABWidgetControl * parent = nullptr )
inlineslot

Opens a file with a file dialog box, returns absolute path or empty string on cancel.

Script Example:

file1 = MLABFileDialog.getOpenFileName(ctx.localPath(), "Def/Script files (*.def *.script)", "Open file")
if not file1 == "":
pass # ok
else:
pass # cancel
Parameters
initiallyAn path to display initially
filterSet one or more name filters - the format is that defined for QFileDialog, multiple filters must be separated by two semicolons
captionA caption to show on top of the dialog
optionsA set of options to modify the behavior of the dialog
parentA parent control which is used to place the dialog

◆ getOpenFileNames [1/2]

QStringList MLABFileDialog::getOpenFileNames ( const QString & filter,
const QString & dir,
const QString & caption,
const QString & browsingGroup,
Option options = static_cast< Option >(0),
MLABWidgetControl * parent = nullptr )
slot

Same method with the browsingGroup parameter. (See getOpenFileName() about that.)

◆ getOpenFileNames [2/2]

QStringList MLABFileDialog::getOpenFileNames ( const QString & filter,
const QString & dir,
const QString & caption,
Option options = static_cast<Option> (0),
MLABWidgetControl * parent = nullptr )
inlineslot

Returns multiple filenames with a file dialog box, returns a list of absolute paths.

Script Example:

filelist = MLABFileDialog.getOpenFileNames("Def/Script files (*.def *.script)", ctx.localPath(), "Select multiple files")
i = 0
for file in filelist:
ctx.log(str(i) + ": " + file
i = i + 1

◆ getSaveFileName [1/2]

QString MLABFileDialog::getSaveFileName ( const QString & initially,
const QString & filter,
const QString & caption,
const QString & browsingGroup,
Option options = static_cast< Option >(0),
MLABWidgetControl * parent = nullptr )
slot

Same method with the browsingGroup parameter. (See getOpenFileName() about that.)

◆ getSaveFileName [2/2]

QString MLABFileDialog::getSaveFileName ( const QString & initially,
const QString & filter,
const QString & caption,
Option options = static_cast<Option> (0),
MLABWidgetControl * parent = nullptr )
inlineslot

Saves a file with a file dialog box, returns absolute path or empty string on cancel.

Script Example:

file1 = MLABFileDialog.getSaveFileName(ctx.localPath() + "/test.def", "Def/Script files (*.def *.script)", "Save file",
if not file1 == "":
pass # ok
else:
pass # cancel
@ DontConfirmOverwrite
Don't ask for confirmation if an existing file is selected. By default confirmation is requested.
Definition mlabScriptWrappers.h:82

◆ lastFileDialogPath

QString MLABFileDialog::lastFileDialogPath ( const QString & browsingGroup = "")
slot

Return the path last used with the given browsingGroup.

◆ setLastFileDialogPath

void MLABFileDialog::setLastFileDialogPath ( const QString & path,
const QString & browsingGroup = "" )
slot

Set the path to show for the given browsingGroup when the next file dialog is opened (this is only used if no default file path is given for that dialog).

This path is persistent across runs of an application and holds the last path used in a file dialog (without cancelling).