1+ from sciapp .action import ImageTool
2+
3+ class MoveTool (ImageTool ):
4+ title = 'Move And Scale'
5+ def __init__ (self ):
6+ self .oldxy = None
7+
8+ def mouse_down (self , obj , x , y , btn , ** key ):
9+ if btn == 1 : self .oldxy = key ['px' ], key ['py' ]
10+ if btn == 3 : key ['canvas' ].fit ()
11+
12+ def mouse_up (self , obj , x , y , btn , ** key ):
13+ self .oldxy = None
14+
15+ def mouse_move (self , obj , x , y , btn , ** key ):
16+ if self .oldxy is None : return
17+ ox , oy = self .oldxy
18+ up = (1 ,- 1 )[key ['canvas' ].up ]
19+ key ['canvas' ].move (key ['px' ]- ox , (key ['py' ]- oy )* up )
20+ self .oldxy = key ['px' ], key ['py' ]
21+
22+ def mouse_wheel (self , obj , x , y , d , ** key ):
23+ if d > 0 : key ['canvas' ].zoomout (x , y , coord = 'data' )
24+ if d < 0 : key ['canvas' ].zoomin (x , y , coord = 'data' )
25+
26+ class ScaleTool (ImageTool ):
27+ title = 'Scope'
28+ def __init__ (self ):
29+ self .ox , self .oy = 0 , 0
30+
31+ def mouse_down (self , ips , x , y , btn , ** key ):
32+ if btn == 2 :
33+ self .ox , self .oy = key ['canvas' ].to_panel_coor (x ,y )
34+ print (self .ox , self .oy )
35+ #print 'down', self.ox, self.oy
36+ if btn == 1 : key ['canvas' ].zoomout (x , y , 'data' )
37+ if btn == 3 : key ['canvas' ].zoomin (x , y , 'data' )
38+ ips .update ()
39+
40+ def mouse_up (self , ips , x , y , btn , ** key ):
41+ pass
42+
43+ def mouse_move (self , ips , x , y , btn , ** key ):
44+ if btn == 2 :
45+ x ,y = key ['canvas' ].to_panel_coor (x ,y )
46+ #print 'x,y',x,y
47+ #print 'dx,dy:', x-self.ox, y-self.oy
48+ key ['canvas' ].move (x - self .ox , y - self .oy )
49+ ips .update ()
50+ self .ox , self .oy = x ,y
51+
52+ def mouse_wheel (self , ips , x , y , d , ** key ):
53+ if d > 0 :key ['canvas' ].zoomout (x , y , 'data' )
54+ if d < 0 :key ['canvas' ].zoomin (x , y , 'data' )
55+ ips .update ()
0 commit comments