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

« back to all changes in this revision

Viewing changes to examples/tutorials/scipy2008/tool_chooser.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 chaco.tools.api import PanTool, ZoomTool, DragZoom
6
 
from enable.component_editor import ComponentEditor
7
 
from traits.api import HasTraits, Instance, List
8
 
from traitsui.api import Item, View, CheckListEditor
9
 
 
10
 
class ToolChooserExample(HasTraits):
11
 
 
12
 
    plot = Instance(Plot)
13
 
    tools = List(editor=CheckListEditor(values = ["PanTool", "ZoomTool", "DragZoom"]))
14
 
    traits_view = View(Item("tools", label="Tools", style="custom"),
15
 
                       Item('plot', editor=ComponentEditor(), show_label=False),
16
 
                       width=800, height=600, resizable=True,
17
 
                       title="Tool Chooser")
18
 
 
19
 
    def __init__(self):
20
 
        # Create the data and the PlotData object
21
 
        x = linspace(-14, 14, 500)
22
 
        y = sin(x) * x**3
23
 
        plotdata = ArrayPlotData(x = x, y = y)
24
 
        # Create a Plot and associate it with the PlotData
25
 
        plot = Plot(plotdata)
26
 
        # Create a line plot in the Plot
27
 
        plot.plot(("x", "y"), type="line", color="blue")
28
 
        self.plot = plot
29
 
 
30
 
    def _tools_changed(self):
31
 
        classes = [eval(class_name) for class_name in self.tools]
32
 
 
33
 
        # Remove all tools from the plot
34
 
        plot_tools = self.plot.tools
35
 
        for tool in plot_tools:
36
 
            plot_tools.remove(tool)
37
 
 
38
 
        # Create new instances for the selected tool classes
39
 
        for cls in classes:
40
 
            self.plot.tools.append(cls(self.plot))
41
 
 
42
 
 
43
 
#===============================================================================
44
 
# demo object that is used by the demo.py application.
45
 
#===============================================================================
46
 
demo = ToolChooserExample()
47
 
 
48
 
if __name__ == "__main__":
49
 
    demo.configure_traits()
50