enable.base_tool module

Defines the base class for all Chaco tools. See docs/event_handling.txt for an overview of how event handling works in Chaco.

class enable.base_tool.BaseTool(component=None, **traits)[source]

Bases: enable.interactor.Interactor

The base class for Chaco tools.

Tools are not Enable components, but they can draw. They do not participate in layout, but are instead attached to a Component, which dispatches methods to the tool and calls the tools’ draw() method.

See docs/event_handling.txt for more information on how tools are structured.

deactivate(component=None)[source]

Handles this component no longer being the active tool.

dispatch(event, suffix)[source]

Dispatches a mouse event based on the current event state.

Overrides enable.Interactor.

draw(gc, view_bounds=None)[source]

Draws this tool on a graphics context.

It is assumed that the graphics context has a coordinate transform that matches the origin of its component. (For containers, this is just the origin; for components, it is the origin of their containers.)

class enable.base_tool.KeySpec(key, *modifiers, **kwmods)[source]

Bases: object

Creates a key specification to facilitate tools interacting with the keyboard. A tool can declare either a class attribute:

magic_key = KeySpec("Right", "control", ignore=['shift'])

or a trait:

magic_key = Instance(KeySpec, args=("Right", "control"),
                     kw={'ignore': ['shift']})

and then check to see if the key was pressed by calling:

if self.magic_key.match(event):
    # do stuff...

The names of the keys come from Enable, so both examples above are specifying the user pressing Ctrl + Right_arrow with Alt not pressed and Shift either pressed or not.

classmethod from_string(s)[source]

Create a KeySpec from a string joined by ‘+’ characters.

match(event)[source]

Returns True if the given Enable key_pressed event matches this key specification.