traitsui.extras.saving module

Provides a lightweight framework that removes some of the drudge work involved with implementing user-friendly saving behavior in a Traits UI application.

class traitsui.extras.saving.CanSaveMixin

Bases: traits.has_traits.HasTraits

A mixin-class for objects that wish to support GUI saving via a SaveHandler. It is the responsiblity of the child class to manage its dirty flag, which describes whether its information has changed since its last save.


Saves the object to the path specified by its ‘filepath’ trait. This method should also reset the dirty flag on this object.


Returns whether the information in the object is valid to be saved in tuple form. The first item is the validation state (boolean) and the second item is the message to display if the object did not validate.

By default, an object always validates.

class traitsui.extras.saving.SaveHandler

Bases: traitsui.handler.Handler

A Handler that facilates adding saving to a Traits UI application.

close(info, is_ok)

Called when the user requests to close the interface. Returns a boolean indicating whether the window should be allowed to close.

closed(info, is_ok)

Called after the window is destroyed. Makes sure that the autosave timer is stopped.


Closes the UI unless a save prompt is cancelled. Provided for convenience to be used with a Menu action.


Set the default save object (the object being handled). Also, perform a questionable hack by which we remove the handled object from the keybinding’s controllers. This means that a keybinding to ‘save’ only calls this object, not the object being edited as well. (For reasons unclear, the KeyBinding handler API is radically different from the Action API, which is the reason that this problem exists. Keybindings are a UI concept–they should not call the model by default.)

promptForSave(info, cancel=True)

Prompts the user to save the object, if appropriate. Returns whether the user canceled the action that invoked this prompt.


Saves the object to its current filepath. If this is not specified, opens a dialog to select this path. Returns whether the save actually occurred.


Saves the object to a new path, and sets this as the ‘filepath’ on the object. Returns whether the save actually occurred.

Previous topic

traitsui.extras.progress_column module

Next topic

traitsui.image package

This Page