File: move_tool.py

package info (click to toggle)
python-chaco 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,144 kB
  • sloc: python: 35,936; ansic: 1,211; cpp: 241; makefile: 124; sh: 5
file content (41 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
""" Defines the MoveTool class.
"""
# Enthought library imports
from traits.api import Tuple
from enable.tools.drag_tool import DragTool


class MoveTool(DragTool):
    """ A tool for moving a plot component.
    """

    # The (x,y) offset of the start of the drag relative to the component.
    _offset = Tuple((0,0))

    def drag_start(self, event):
        """ Called when the drag operation starts.

        Implements DragTool.
        """
        self._offset = (event.x - self.component.x, event.y - self.component.y)
        event.handled = True

    def dragging(self, event):
        """ This method is called for every mouse_move event that the tool
        receives while the user is dragging the mouse.

        Implements DragTool. Moves the component.
        """
        c = self.component
        c.position = [event.x - self._offset[0], event.y - self._offset[1]]
        if getattr(c, "x_mapper", None):
            c.x_mapper.updated = True
        if getattr(c, "y_mapper", None):
            c.y_mapper.updated = True
        if getattr(c, "vgrid", None):
            c.vgrid.invalidate()
        if getattr(c, "hgrid", None):
            c.hgrid.invalidate()
        event.handled = True
        c.request_redraw()