~ubuntu-branches/ubuntu/precise/python-chaco/precise

« back to all changes in this revision

Viewing changes to examples/canvas/mp_viewport_pan_tool.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-12-29 02:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20081229023405-x7i4kp9mdxzmdnvu
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from enthought.traits.api import Int, Tuple
 
3
from enthought.enable.tools.api import ViewportPanTool
 
4
 
 
5
class MPViewportPanTool(ViewportPanTool):
 
6
 
 
7
    cur_bid = Int(-1)
 
8
 
 
9
    _last_blob_pos = Tuple
 
10
 
 
11
    def normal_blob_down(self, event):
 
12
        if self.cur_bid == -1 and self.is_draggable(event.x, event.y):
 
13
            self.cur_bid = event.bid
 
14
            self.drag_start(event)
 
15
    
 
16
    def dragging_blob_up(self, event):
 
17
        if event.bid == self.cur_bid:
 
18
            self.cur_bid = -1
 
19
            self.drag_end(event)
 
20
 
 
21
    def dragging_blob_move(self, event):
 
22
        if event.bid == self.cur_bid:
 
23
            self._last_blob_pos = (event.x, event.y)
 
24
            self.dragging(event)
 
25
 
 
26
    def drag_start(self, event):
 
27
        if self.component:
 
28
            self.original_padding = self.component.padding
 
29
            if hasattr(event, "bid"):
 
30
                event.window.capture_blob(self, event.bid,
 
31
                                          event.net_transform())
 
32
            else:
 
33
                event.window.set_mouse_owner(self, event.net_transform())
 
34
            self._last_blob_pos = (event.x, event.y)
 
35
            self.mouse_down_position = (event.x,event.y)
 
36
            self.event_state = "dragging"
 
37
            event.handled = True
 
38
            ViewportPanTool.drag_start(self, event)
 
39
        return
 
40
 
 
41
    def drag_end(self, event):
 
42
        event.x, event.y = self._last_blob_pos
 
43
        if hasattr(event, "bid"):
 
44
            event.window.release_blob(event.bid)
 
45
        self.event_state = "normal"
 
46
        ViewportPanTool.drag_end(self, event)
 
47