~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/tutorials/scipy2008/custom_tool.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from numpy import linspace, sin
3
 
 
4
 
from chaco.api import ArrayPlotData, Plot
5
 
from enable.api import BaseTool
6
 
from enable.component_editor import ComponentEditor
7
 
from traits.api import Enum, HasTraits, Instance
8
 
from traitsui.api import Item, View
9
 
 
10
 
class CustomTool(BaseTool):
11
 
 
12
 
    event_state = Enum("normal", "mousedown")
13
 
 
14
 
    def normal_mouse_move(self, event):
15
 
        print "Screen:", event.x, event.y
16
 
 
17
 
    def normal_left_down(self, event):
18
 
        self.event_state = "mousedown"
19
 
        event.handled = True
20
 
 
21
 
    def mousedown_mouse_move(self, event):
22
 
        print "Data:", self.component.map_data((event.x, event.y))
23
 
 
24
 
    def mousedown_left_up(self, event):
25
 
        self.event_state = "normal"
26
 
        event.handled = True
27
 
 
28
 
 
29
 
class ScatterPlot(HasTraits):
30
 
 
31
 
    plot = Instance(Plot)
32
 
 
33
 
    traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
34
 
                       width=800, height=600, resizable=True,
35
 
                       title="Custom Tool")
36
 
 
37
 
    def _plot_default(self):
38
 
        # Create the data and the PlotData object
39
 
        x = linspace(-14, 14, 100)
40
 
        y = sin(x) * x**3
41
 
        plotdata = ArrayPlotData(x = x, y = y)
42
 
        # Create a Plot and associate it with the PlotData
43
 
        plot = Plot(plotdata)
44
 
        # Create a scatter plot in the Plot
45
 
        plot.plot(("x", "y"), type="scatter", color="blue")
46
 
        # Add our custom tool to the plot
47
 
        plot.tools.append(CustomTool(plot))
48
 
        return plot
49
 
 
50
 
#===============================================================================
51
 
# demo object that is used by the demo.py application.
52
 
#===============================================================================
53
 
demo=ScatterPlot()
54
 
if __name__ == "__main__":
55
 
    demo.edit_traits(kind="livemodal")
56