~ubuntu-branches/ubuntu/trusty/python-chaco/trusty

« back to all changes in this revision

Viewing changes to examples/status_overlay.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 20:38:02 UTC
  • mfrom: (7.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110708203802-5t32e0ldv441yh90
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Depend on python-traitsui (Closes: #633604)
  - Bump Standards-Version to 3.9.2
* Update debian/watch file
* Remove debian/patches/* -- no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
import numpy
3
 
 
4
 
from enthought.chaco.api import Plot, ArrayPlotData
5
 
from enthought.chaco.layers.api import ErrorLayer, WarningLayer, StatusLayer
6
 
from enthought.enable.component_editor import ComponentEditor
7
 
from enthought.traits.api import HasTraits, Instance, Button
8
 
from enthought.traits.ui.api import Item, View, HGroup
9
 
 
10
 
class MyPlot(HasTraits):
11
 
    """ Displays a plot with a few buttons to control which overlay
12
 
        to display
13
 
    """
14
 
    plot = Instance(Plot)
15
 
    status_overlay = Instance(StatusLayer)
16
 
 
17
 
    error_button = Button('Error')
18
 
    warn_button = Button('Warning')
19
 
    no_problem_button = Button('No problem')
20
 
 
21
 
    traits_view = View( HGroup(Item('error_button', show_label=False),
22
 
                               Item('warn_button', show_label=False),
23
 
                               Item('no_problem_button', show_label=False)),
24
 
                        Item('plot', editor=ComponentEditor(), show_label=False),
25
 
                        resizable=True)
26
 
 
27
 
    def __init__(self, index, data_series, **kw):
28
 
        super(MyPlot, self).__init__(**kw)
29
 
 
30
 
        plot_data = ArrayPlotData(index=index)
31
 
        plot_data.set_data('data_series', data_series)
32
 
        self.plot = Plot(plot_data)
33
 
        self.plot.plot(('index', 'data_series'))
34
 
 
35
 
    def _error_button_fired(self, event):
36
 
        """ removes the old overlay and replaces it with
37
 
            an error overlay
38
 
        """
39
 
        self.clear_status()
40
 
 
41
 
        self.status_overlay = ErrorLayer(component=self.plot,
42
 
                                            align='ul', scale_factor=0.25)
43
 
        self.plot.overlays.append(self.status_overlay)
44
 
 
45
 
        self.plot.request_redraw()
46
 
 
47
 
    def _warn_button_fired(self, event):
48
 
        """ removes the old overlay and replaces it with
49
 
            an warning overlay
50
 
        """
51
 
        self.clear_status()
52
 
 
53
 
        self.status_overlay = WarningLayer(component=self.plot,
54
 
                                            align='ur', scale_factor=0.25)
55
 
        self.plot.overlays.append(self.status_overlay)
56
 
 
57
 
        self.plot.request_redraw()
58
 
 
59
 
    def _no_problem_button_fired(self, event):
60
 
        """ removes the old overlay
61
 
        """
62
 
        self.clear_status()
63
 
        self.plot.request_redraw()
64
 
 
65
 
    def clear_status(self):
66
 
        if self.status_overlay in self.plot.overlays:
67
 
            # fade_out will remove the overlay when its done
68
 
            self.status_overlay.fade_out()
69
 
    
70
 
index = numpy.array([1,2,3,4,5])
71
 
data_series = index**2
72
 
 
73
 
my_plot = MyPlot(index, data_series)
74
 
my_plot.configure_traits()