Defines the LineSegmentTool class.

class, **kwtraits)

Bases: chaco.abstract_overlay.AbstractOverlay

The base class for tools that allow the user to draw a series of points connected by lines.


Given a screen-space point (x,y), adds the corresponding data space point to the list for this tool.

component = Instance(Component)

The component that this tool overlays

delete_cursor = Pointer("bullseye")

Cursor shape for deleting points.


Draws the polygon in the ‘dragging’ state.


Handles a key being pressed in the ‘dragging’ state.

If the key is “Esc”, the drag operation is canceled.


Handles the left mouse coming up in the ‘dragging’ state.

Switches to ‘normal’ state.


Handles the mouse leaving the tool area in the ‘dragging’ state.

The drag is canceled and the cursor changes to an arrow.


Handles the user moving the mouse while in the ‘dragging’ state.

The screen is updated to show the new mouse position as the end of the line segment being drawn.

event_state = Enum("normal", "selecting", "dragging")

The event states are:


The user may have selected points, and is moving the cursor around.


The user has clicked down but hasn’t let go of the button yet, and can still drag the point around.


The user has clicked on an existing point and is dragging it around. When the user releases the mouse button, the tool returns to the “normal” state


Retrieves the indexed point and returns its screen space value.

line = Instance(Line, args=())

The current line segment being drawn.

mouse_position = Optional(Tuple)

The data (index, value) position of the mouse cursor; this is used by various draw() routines.

move_cursor = Pointer("sizing")

Cursor shape for moving points.

normal_cursor = Pointer("pencil")

Cursor shape for drawing.


Draws the line.


Handles the user pressing a key in the ‘normal’ state.

If the user presses the Enter key, the tool is reset.


Handles the left mouse button being pressed while the tool is in the ‘normal’ state.

For an existing point, if the user is pressing the Control key, the point is deleted. Otherwise, the user can drag the point.

For a new point, the point is added, and the user can drag it.


Handles the user moving the cursor away from the tool area.


Handles the user moving the mouse in the ‘normal’ state.

When the user moves the cursor over an existing point, if the Control key is pressed, the cursor changes to the delete_cursor, indicating that the point can be deleted. Otherwise, the cursor changes to the move_cursor, indicating that the point can be moved.

When the user moves the cursor over any other point, the cursor changes to (or stays) the normal_cursor.

original_cursor = Pointer("arrow")

Cursor shape for non-tool use.

overlay(component, gc, view_bounds, mode='normal')

Draws this component overlaid on another component.

Implements AbstractOverlay.

points = List

A list of the points in data space as (index,value)

proximity_distance = Int(4)

The pixel distance from a vertex that is considered ‘on’ the vertex.


Removes the point for a given index from this tool’s list of points.


Requests that the component redraw itself.

Overrides Enable Component.


Resets the tool, throwing away any points, and making the tool invisible.

set_point(index, point)

Sets the data-space index for a screen-space point.

visible = Bool(False)

The tool is initially invisible, because there is nothing to draw.