traitsui.key_bindings module

Defines KeyBinding and KeyBindings classes, which manage the mapping of keystroke events into method calls on controller objects that are supplied by the application.

class traitsui.key_bindings.KeyBinding

Bases: traits.has_traits.HasStrictTraits

Binds one or two keystrokes to a method.

binding1 = Binding

First key binding

binding2 = Binding

Second key binding

description = Str()

Description of what application function the method performs

method_name = Str()

Name of controller method the key is bound to

owner = Instance("KeyBindings")

KeyBindings object that “owns” the KeyBinding

class traitsui.key_bindings.KeyBindings(*bindings, **traits)

Bases: traits.has_traits.HasPrivateTraits

A set of key bindings.

binding_modified = Event(KeyBinding)

Event fired when one of the contained KeyBinding objects is changed

bindings = List(KeyBinding)

Set of defined key bindings (redefined dynamically)

children = List(transient=True)

The child KeyBindings of this object (if any):


Returns a clone of the KeyBindings object.

controllers = List(transient=True)

The (optional) list of controllers associated with this KeyBindings object. The controllers may also be provided with the ‘do’ method:


Dispose of the object.

do(event, controllers=[], *args, **kw)

Processes a keyboard event.


Edits a possibly hierarchical set of KeyBindings.

focus_owner = Any(transient=True)

Control that currently has the focus (if any)

key_binding_for(binding, key_name)

Returns the current binding for a specified key (if any).


Merges another set of key bindings into this set.

parent = Instance("KeyBindings", transient=True)

The ‘parent’ KeyBindings object of this one (if any):

prefix = Str()

Optional prefix to add to each method name

root = Property(depends_on="parent")

The root of the KeyBindings tree this object is part of:

suffix = Str()

Optional suffix to add to each method name