enable.tools.value_drag_tool module

Value Drag Tools

This module contains tools to handle simple dragging interactions where the drag operation has a direct effect on some underlying value. This can potentially be used as the basis for many different interactions,

class enable.tools.value_drag_tool.AttributeDragTool(component=None, **traits)[source]

Bases: enable.tools.value_drag_tool.ValueDragTool

Tool which modifies a model’s attributes as it drags

This is designed to cover the simplest of drag cases where the drag is modifying one or two numerical attributes on an underlying model. To use, simply provide the model object and the attributes that you want to be changed by the drag. If only one attribute is required, the other can be left as an empty string.

get_value()[source]

Get the current value of the attributes

Returns a 2-tuple of (x, y) values. If either x_attr or y_attr is the empty string, then the corresponding component of the tuple is None.

model = Any

the model object which has the attributes we are modifying

set_delta(value, delta_x, delta_y)[source]

Set the current value of the attributes

Set the underlying attribute values based upon the starting value and the provided deltas. The values are simply set to the sum of the appropriate coordinate and the delta. If either x_attr or y_attr is the empty string, then the corresponding component of is ignored.

Note that setting x and y are two separate operations, and so will fire two trait notification events.

x_attr = Str

the name of the attributes that is modified by horizontal motion

x_bounds = Tuple(Either(Float, Str, None), Either(Float, Str, None))

max and min values for x value

y_attr = Str

the name of the attributes that is modified by vertical motion

y_bounds = Tuple(Either(Float, Str, None), Either(Float, Str, None))

max and min values for y value

class enable.tools.value_drag_tool.IdentityMapper[source]

Bases: object

map_data(screen)[source]
map_screen(data)[source]
class enable.tools.value_drag_tool.ValueDragTool(component=None, **traits)[source]

Bases: enable.tools.drag_tool.DragTool

Abstract tool for modifying a value as the mouse is dragged

The tool allows the use of an x_mapper and y_mapper to map between screen coordinates and more abstract data coordinates. These mappers must be objects with a map_data() method that maps a component-space coordinate to a data-space coordinate. Chaco mappers satisfy the required API, and the tool will look for ‘x_mapper’ and ‘y_mapper’ attributes on the component to use as the defaults, facilitating interoperability with Chaco plots. Failing that, a simple identity mapper is provided which does nothing. Coordinates are given relative to the component.

Subclasses of this tool need to supply get_value() and set_delta() methods. The get_value method returns the current underlying value, while the set_delta method takes the current mapped x and y deltas from the original position, and sets the underlying value appropriately. The object stores the original value at the start of the operation as the original_value attribute.

drag_end(event)[source]

Called when a mouse event causes the drag operation to end.

A drag is ended when a user releases the mouse, or by receiving a mouse_leave event when on_drag_leave is ‘end’.

drag_start(event)[source]

Called when the drag operation starts.

The event parameter is the mouse event that established the drag operation; its x and y attributes correspond to the current location of the mouse, and not to the position of the mouse when the initial left_down or right_down event happened.

dragging(event)[source]

This method is called for every mouse_move event that the tool receives while the user is dragging the mouse.

It is recommended that subclasses do most of their work in this method.

get_value()[source]

Return the current value that is being modified

modifier_keys = Set(Enum(*keys))

set of modifier keys that must be down to invoke the tool

new_value = Event(Dict)

new_value event for inspector overlay

original_data_point = Tuple(Any, Any)

start point of the drag in data coordinates

original_screen_point = Tuple(Float, Float)

start point of the drag in component coordinates

original_value = Any

initial underlying value

set_delta(value, delta_x, delta_y)[source]

Set the value that is being modified

This function should modify the underlying value based on the provided delta_x and delta_y in data coordinates. These deltas are total displacement from the original location, not incremental. The value parameter is the original value at the point where the drag started.

visible = Bool(False)

visibility for inspector overlay

x_mapper = Any

mapper that maps from horizontal screen coordinate to data coordinate

y_mapper = Any

mapper that maps from vertical screen coordinate to data coordinate