/[ascend]/branches/adrian/pygtk/canvas/panzoom.py
ViewVC logotype

Diff of /branches/adrian/pygtk/canvas/panzoom.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2890 by adrian, Wed Apr 1 10:57:31 2015 UTC revision 2891 by adrian, Fri Apr 10 19:32:37 2015 UTC
# Line 1  Line 1 
1  # Pan and Zoom tools for Gaphas by John Pye, 4 Nov 2008.  # Pan and Zoom tools for Gaphas by John Pye, 4 Nov 2008.
2    
3  import gtk  from gi.repository import Gtk, Gdk
 import gtk.gdk as gdk  
4    
5  from gaphas.tool import Tool  from gaphas.tool import Tool
6    
7  ZOOM_MASK = gdk.CONTROL_MASK | gdk.SHIFT_MASK | gdk.MOD1_MASK  ZOOM_MASK = Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD1_MASK
8  ZOOM_VALUE =gdk.CONTROL_MASK  ZOOM_VALUE =Gdk.ModifierType.CONTROL_MASK
9    
10  class ZoomTool(Tool):  class ZoomTool(Tool):
11      """      """
# Line 25  class ZoomTool(Tool): Line 24  class ZoomTool(Tool):
24    
25      def on_button_press(self, context, event):      def on_button_press(self, context, event):
26          if event.button == 2 \          if event.button == 2 \
27                  and event.state & ZOOM_MASK == ZOOM_VALUE:                  and event.get_state() & ZOOM_MASK == ZOOM_VALUE:
28              context.grab()              context.grab()
29              self.x0 = event.x              self.x0 = event.x
30              self.y0 = event.y              self.y0 = event.y
# Line 38  class ZoomTool(Tool): Line 37  class ZoomTool(Tool):
37          return True          return True
38    
39      def on_motion_notify(self, context, event):      def on_motion_notify(self, context, event):
40          if event.state & ZOOM_MASK == ZOOM_VALUE:          if event.get_state() & ZOOM_MASK == ZOOM_VALUE:
41              view = context.view              view = context.view
42              dy = event.y - self.y0              dy = event.y - self.y0
43    
# Line 65  class ZoomTool(Tool): Line 64  class ZoomTool(Tool):
64              return True              return True
65    
66      def on_scroll(self, context, event):      def on_scroll(self, context, event):
67          if event.state & gtk.gdk.CONTROL_MASK:          if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
68              view = context.view              view = context.view
69              context.grab()              context.grab()
70              sx = view._matrix[0]              sx = view._matrix[0]
# Line 73  class ZoomTool(Tool): Line 72  class ZoomTool(Tool):
72              ox = (view._matrix[4] - event.x) / sx              ox = (view._matrix[4] - event.x) / sx
73              oy = (view._matrix[5] - event.y) / sy              oy = (view._matrix[5] - event.y) / sy
74              factor = 0.9              factor = 0.9
75              if event.direction == gtk.gdk.SCROLL_UP:                  if event.direction == Gdk.ScrollDirection.UP:  
76                  factor = 1. / factor                  factor = 1. / factor
77              view._matrix.translate(-ox, -oy)              view._matrix.translate(-ox, -oy)
78              view._matrix.scale(factor, factor)              view._matrix.scale(factor, factor)
# Line 107  class PanTool(Tool): Line 106  class PanTool(Tool):
106          return True          return True
107    
108      def on_motion_notify(self, context, event):      def on_motion_notify(self, context, event):
109          if event.state & gtk.gdk.BUTTON2_MASK:          if event.get_state() & Gdk.ModifierType.BUTTON2_MASK:
110              view = context.view              view = context.view
111              self.x1, self.y1 = event.x, event.y              self.x1, self.y1 = event.x, event.y
112              dx = self.x1 - self.x0              dx = self.x1 - self.x0

Legend:
Removed from v.2890  
changed lines
  Added in v.2891

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22