traitsui.ui module

Defines the UI class used to represent an active traits-based user interface.

class traitsui.ui.Dispatcher(method, info, object, method_name)[source]

Bases: object


Dispatches the method.


Removes the dispatcher.

class traitsui.ui.UI[source]

Bases: traits.has_traits.HasPrivateTraits

Information about the user interface for a View.

add_checked(checked_when, editor)[source]

Adds a conditionally enabled (menu) Editor object to the list of monitored ‘checked_when’ objects.


Adds a Handler method to the list of methods to be called once the user interface has been constructed.

add_enabled(enabled_when, editor)[source]

Adds a conditionally enabled Editor object to the list of monitored ‘enabled_when’ objects.

add_visible(visible_when, editor)[source]

Adds a conditionally enabled Editor object to the list of monitored ‘visible_when’ objects.

context = Dict(Str, Any)

Context objects that the UI is editing

control = Any()

Panel or dialog associated with the user interface

destroyed = Bool(False)

Set to True when the UI has finished being destroyed.

disposable_traits = ['view_elements', 'info', 'handler', 'context', 'view', 'history', 'key_bindings', 'icon', 'rebuild']

List of additional traits that are discarded when a user interface is disposed.

dispose(result=None, abort=False)[source]

Disposes of the contents of a user interface.

do_undoable(action, *args, **kw)[source]

Performs an action that can be undone.

errors = Int()

The number of currently pending editor error conditions

eval_when(when, result=True)[source]

Evaluates an expression in the UI’s context and returns the result.

evaluate(function, *args, **kw_args)[source]

Evaluates a specified function in the UI’s context.


Finds the definition of the specified Include object in the current user interface building context.


Finishes disposing of a user interface.


Returns a list of editors for the given trait name.


Returns the list of editor error controls contained by the user interface.


Gets the current value of a specified extended trait name.


Gets the preferences to be saved for the user interface.


Returns a reference to the Traits UI preference database.

handler = Instance(Handler)

Handler object used for event handling

history = Any()

Undo and Redo history

icon = Image

The ImageResource of the icon, if any

id = Str()

The unique ID for this UI for persistence

info = Instance(UIInfo)

UIInfo object containing context or editor objects

key_bindings = Property(depends_on=["view._key_bindings", "context"])

The KeyBindings object (if any) for this UI:

key_handler(event, skip=True)[source]

Handles key events.

modified = Bool(False)

Have any modifications been made to UI contents?

owner = Any()

Toolkit-specific object that “owns” control

parent = Instance("UI")

The parent UI (if any) of this UI


Restores a previously pushed search stack level.


Performs all processing that occurs after the user interface is created.


Returns the current search stack level.

rebuild = Callable()

The code used to rebuild an updated user interface

recyclable_traits = ['_context', '_revert', '_defined', '_visible', '_enabled', '_checked', '_search', '_dispatchers', '_editors', '_names', '_active_group', '_undoable', '_rebuild', '_groups_cache', '_key_bindings', '_focus_control']

List of traits that are reset when a user interface is recycled (i.e. rebuilt).


Recycles the user interface prior to rebuilding it.


Resets the contents of a user interface.


Retrieves and restores any saved user preference information associated with the UI.

result = Bool(False)

Result from a modal or wizard dialog:


Routes a “hooked” event to the correct handler method.


Saves any user preference information associated with the UI.

scrollable = Bool(False)

Should the created UI have scroll bars?


Sets the values of user preferences for the UI.


Synchronize context object traits with view editor traits.

title = Str()

Title of the dialog, if any


Initializes the traits object.

ui(parent, kind)[source]

Creates a user interface from the associated View template object.

updated = Event(Bool)

Event when the user interface has changed

view = Instance("traitsui.view.View")

View template used to construct the user interface

view_elements = Instance(ViewElements)

The ViewElements object from which this UI resolves Include items