[PythonCAD] zooming with mouse wheel

Russ Nelson nelson at crynwr.com
Mon Jun 12 22:57:31 CEST 2006

This patch allows you to zoom in and out using the mouse wheel.  I
think it has three problems:
  1) the scroll increment is too large for a wheel.
  2) it's a little hackish to be calling a menu item (but I wanted the
     patch to be short).
  3) The scrolling should also pan at the same time so that the object
     you're pointing at remains underneath the pointer.

Anyway, if people try this patch and think this is useful, I'll keep
working on it.  Any suggestions beyond the three above?

Index: PythonCAD/Interface/Gtk/gtkimage.py
--- PythonCAD/Interface/Gtk/gtkimage.py (revision 2387)
+++ PythonCAD/Interface/Gtk/gtkimage.py (working copy)
@@ -107,6 +107,14 @@
         return _entry.event(event)
     return False
+def window_scroll_event(widget, event, gtkimage):
+    from PythonCAD.Interface.Gtk.gtkmenus import zoom_in_cb
+    from PythonCAD.Interface.Gtk.gtkmenus import zoom_out_cb
+    if event.direction == gtk.gdk.SCROLL_UP:
+        zoom_in_cb(widget, gtkimage)
+    elif event.direction == gtk.gdk.SCROLL_DOWN:
+        zoom_out_cb(widget, gtkimage)
 def window_general_event(widget, event, gtkimage):
     _type = event.type
     debug_print("window_general_event: Event type: %d" % _type)
@@ -316,6 +324,7 @@
         self.__window.connect("destroy", close_image, self)
         self.__window.connect("event", window_general_event, self)
         self.__window.connect("key_press_event", window_key_press_event, self)
+        self.__window.connect("scroll_event", window_scroll_event, self)
         _width = min(1024, int(0.8 * float(gtk.gdk.screen_width())))
         _height = min(768, int(0.8 * float(gtk.gdk.screen_height())))
         self.__window.set_default_size(_width, _height)

--my blog is at    http://blog.russnelson.com   | When immigration is
Crynwr sells support for free software  | PGPok | outlawed, only criminals
521 Pleasant Valley Rd. | +1 315-323-1241       | will immigrate.  Illegal
Potsdam, NY 13676-3213  |     Sheepdog          | immigration causes crime.

More information about the PythonCAD mailing list