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

« back to all changes in this revision

Viewing changes to enthought/chaco/tools/range_selection_overlay.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-06 19:03:54 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110406190354-rwd55l2ezjecfo41
Tags: 3.4.0-2
d/rules: fix pyshared directory path (Closes: #621116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
""" Defines the RangeSelectionOverlay class.
2
2
"""
 
3
from __future__ import with_statement
 
4
 
3
5
# Major library imports
4
6
from numpy import arange, array
5
7
 
75
77
            upper_right[axis_ndx] = end - start
76
78
            upper_right[1-axis_ndx] = component.bounds[1-axis_ndx]
77
79
        
78
 
            gc.save_state()
79
 
            try:
 
80
            with gc:
 
81
                gc.clip_to_rect(component.x, component.y, component.width, component.height)
80
82
                gc.set_alpha(self.alpha)
81
83
                gc.set_fill_color(self.fill_color_)
82
84
                gc.set_stroke_color(self.border_color_)
85
87
                gc.rect(lower_left[0], lower_left[1], 
86
88
                        upper_right[0], upper_right[1])
87
89
                gc.draw_path()
88
 
            finally:
89
 
                gc.restore_state()
90
 
 
91
90
 
92
91
    #------------------------------------------------------------------------
93
92
    # Private methods
97
96
        """ Returns a tuple of (x1, x2) screen space coordinates of the start
98
97
        and end selection points.  
99
98
        
100
 
        If there is no current selection, then returns None.
 
99
        If there is no current selection, then returns an empty list.
101
100
        """
102
101
        ds = getattr(self.plot, self.axis)
103
 
        selection = ds.metadata[self.metadata_name]
 
102
        selection = ds.metadata.get(self.metadata_name, None)
 
103
        if selection is None:
 
104
            return []
 
105
 
104
106
        # "selections" metadata must be a tuple
105
 
        if self.metadata_name == "selections":
 
107
        if self.metadata_name == "selections" or \
 
108
                (selection is not None and isinstance(selection, tuple)):
106
109
            if selection is not None and len(selection) == 2:
107
110
                return [self.mapper.map_screen(array(selection))]
108
111
            else: