traitsui.file_dialog module

Defines functions and classes used to create pop-up file dialogs for opening and saving files.

class traitsui.file_dialog.CreateDirHandler

Bases: traitsui.handler.Handler

Controller for the ‘create new directory’ popup.

dir_name = Str()

The name for the new directory to be created:

handler_cancel_changed(info)

Handles the user clicking the Cancel button.

handler_ok_changed(info)

Handles the user clicking the OK button.

message = Str()

The current status message:

ok = Button("OK")

The OK and Cancel buttons:

class traitsui.file_dialog.FileExistsHandler

Bases: traitsui.handler.Handler

Controller for the ‘file already exists’ popup.

handler_cancel_changed(info)

Handles the user clicking the Cancel button.

handler_ok_changed(info)

Handles the user clicking the OK button.

message = Str()

The current status message:

ok = Button("OK")

The OK and Cancel buttons:

class traitsui.file_dialog.FileInfo

Bases: traitsui.file_dialog.MFileDialogModel

Defines a file dialog extension that display various file information.

atime = Property(depends_on="file_name")

Last file access time:

ctime = Property(depends_on="file_name")

File creation time (or last metadata change time):

mtime = Property(depends_on="file_name")

List file modification time:

size = Property(depends_on="file_name")

The size of the file:

class traitsui.file_dialog.IFileDialogExtension

Bases: traitsui.file_dialog.IFileDialogModel, traitsui.file_dialog.IFileDialogView

Defines a (convenience) union of the IFileDialogModel and IFileDialogView interfaces.

class traitsui.file_dialog.IFileDialogModel

Bases: traits.has_traits.Interface

Defines a model extension to a file dialog.

file_name = File()

The name of the currently selected file:

class traitsui.file_dialog.IFileDialogView

Bases: traits.has_traits.Interface

Defines a visual extension to a file dialog.

is_fixed = Bool()

Is the view fixed or variable width?

view = AView

The view to display:

class traitsui.file_dialog.ImageInfo

Bases: traitsui.file_dialog.MFileDialogModel

Defines a file dialog extension that display an image file’s dimensions and content.

height = Property(depends_on="image")

The height of the current image:

image = Property(depends_on="file_name")

The ImageResource object for the current file:

width = Property(depends_on="image")

The width of the current image:

class traitsui.file_dialog.MFileDialogExtension

Bases: traitsui.file_dialog.MFileDialogModel, traitsui.file_dialog.MFileDialogView

Defines a (convenience) union of the MFileDialogModel and MFileDialogView mix-in classes.

class traitsui.file_dialog.MFileDialogModel

Bases: traits.has_traits.HasPrivateTraits

file_name = File()

The name of the currently selected file:

class traitsui.file_dialog.MFileDialogView

Bases: traits.has_traits.HasPrivateTraits

Defines a visual extension to a file dialog.

is_fixed = Bool(False)

Is the view fixed or variable width?

view = AView

The view to display:

class traitsui.file_dialog.OpenFileDialog

Bases: traitsui.handler.Handler

Defines the model and handler for the open file dialog.

can_create_dir = Property(depends_on="file_name")

Can a directory be created now?

dclick = Event()

Event fired when the user double-clicks on a file name:

entries = Int(10)

Number of history entries to allow:

extension__ = None

Allow extension models to be added dynamically:

extensions = CList(IFileDialogModel)

A list of optional file dialog extensions:

file_name = File()

The starting and current file path:

filter = CList(Str)

The list of file filters to apply:

id = Str("traitsui.file_dialog.OpenFileDialog")

The Traits UI persistence id to use:

info = Instance(UIInfo)

The UIInfo object for the view:

init_info(info)

Handles the UIInfo object being initialized during view start-up.

is_save_file = Bool(False)

Is the file dialog for saving a file (or opening a file)?

is_valid_file = Property(depends_on="file_name")

Is the currently specified file name valid?

object_cancel_changed(info)

Handles the user clicking the Cancel button.

object_create_changed(info)

Handles the user clicking the create directory button.

object_ok_changed(info)

Handles the user clicking the OK button.

ok = Button("OK")

The OK, Cancel and create directory buttons:

open_file_view()

Returns the file dialog view to use.

reload = Event()

Event fired when the file tree view should be reloaded:

title = Str("Open File")

The file dialog title:

class traitsui.file_dialog.TextInfo

Bases: traitsui.file_dialog.MFileDialogModel

Defines a file dialog extension that displays a file’s contents as text.

text = Property(depends_on="file_name")

The file’s text content:

traitsui.file_dialog.open_file(**traits)

Returns a file name to open or an empty string if the user cancels the operation.

traitsui.file_dialog.save_file(**traits)

Returns a file name to save to or an empty string if the user cancels the operation. In the case where the file selected already exists, the user will be prompted if they want to overwrite the file before the selected file name is returned.