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

« back to all changes in this revision

Viewing changes to enthought/chaco/tools/tracking_pan_tool.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
 
""" Defines the TrackingPanTool class.
2
 
"""
3
 
# Chaco imports
4
 
from enthought.chaco.tools.api import PanTool
5
 
 
6
 
class TrackingPanTool(PanTool):
7
 
    """ Allows the user to pan around a plot.
8
 
    
9
 
    The user clicks a mouse button and drags to pan; the tool then returns to
10
 
    a tracking state. 
11
 
    """
12
 
    
13
 
    def _end_pan(self, event):
14
 
        plot = self.component
15
 
        xrange = plot.x_mapper.range
16
 
        yrange = plot.y_mapper.range
17
 
       
18
 
        if not self.constrain or self.constrain_direction == "x":
19
 
            high = xrange.high
20
 
            low = xrange.low
21
 
            if xrange.default_state == 'low_track':
22
 
                hi_val = max([source.get_bounds()[1] for source in xrange.sources])
23
 
                if hi_val >= low and hi_val <= high:
24
 
                    xrange.set_bounds('track','auto')
25
 
            elif xrange.default_state == 'high_track':
26
 
                lo_val = min([source.get_bounds()[0] for source in xrange.sources])
27
 
                if lo_val >= low and lo_val <= high:
28
 
                    xrange.set_bounds('auto','track')
29
 
            
30
 
        if not self.constrain or self.constrain_direction == "y":
31
 
            high = yrange.high
32
 
            low = yrange.low
33
 
            if yrange.default_state == 'low_track':
34
 
                hi_val = max([source.get_bounds()[1] for source in yrange.sources])
35
 
                if hi_val >= low and hi_val <= high:
36
 
                    yrange.set_bounds('track','auto')
37
 
            elif yrange.default_state == 'high_track':
38
 
                lo_val = min([source.get_bounds()[0] for source in yrange.sources])
39
 
                if lo_val >= low and lo_val <= high:
40
 
                    yrange.set_bounds('auto','track')
41
 
           
42
 
        if self._auto_constrain:
43
 
            self.constrain = False
44
 
            self.constrain_direction = None
45
 
        self.event_state = "normal"
46
 
        event.window.set_pointer("arrow")
47
 
        if event.window.mouse_owner == self:
48
 
            event.window.set_mouse_owner(None)
49
 
 
50
 
            
51
 
        event.handled = True
52
 
        return
53
 
 
54
 
# EOF