2
from numpy import linspace, sin
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
10
class ToolChooserExample(HasTraits):
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,
20
# Create the data and the PlotData object
21
x = linspace(-14, 14, 500)
23
plotdata = ArrayPlotData(x = x, y = y)
24
# Create a Plot and associate it with the PlotData
26
# Create a line plot in the Plot
27
plot.plot(("x", "y"), type="line", color="blue")
30
def _tools_changed(self):
31
classes = [eval(class_name) for class_name in self.tools]
33
# Remove all tools from the plot
34
plot_tools = self.plot.tools
35
for tool in plot_tools:
36
plot_tools.remove(tool)
38
# Create new instances for the selected tool classes
40
self.plot.tools.append(cls(self.plot))
43
#===============================================================================
44
# demo object that is used by the demo.py application.
45
#===============================================================================
46
demo = ToolChooserExample()
48
if __name__ == "__main__":
49
demo.configure_traits()