File: dataprinter.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 (43 lines) | stat: -rw-r--r-- 1,274 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
42
43
""" Defines the DataPrinter tool class.
"""
# Enthought library imports
from traits.api import Str
from enable.api import BaseTool

# Chaco imports
from chaco.api import BaseXYPlot


class DataPrinter(BaseTool):
    """ Simple listener tool that prints the (x,y) data space position of the
    point under the cursor.
    """

    # This tool is a listener, and does not display anything (overrides BaseTool).
    visible = False

    # Turn off drawing, because the tool prints to stdout.
    draw_mode = "none"

    # The string to format the (x,y) value in data space.
    format = Str("(%.3f, %.3f)")

    def normal_mouse_move(self, event):
        """ Handles the mouse being moved in the 'normal' state.

        Prints the data space position of the current mouse position.
        """
        plot = self.component
        if plot is not None:
            if isinstance(plot, BaseXYPlot):
                ndx = plot.map_index((event.x, event.y), index_only = True)
                x = plot.index.get_data()[ndx]
                y = plot.value.get_data()[ndx]
                print self.format % (x,y)
            else:
                print "dataprinter: don't know how to handle plots of type",
                print plot.__class__.__name__
        return


# EOF