[Skencil-commits] r525 - in skencil/trunk: . Sketch/Editor test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 26 23:53:24 CET 2006


Author: bh
Date: 2006-02-26 23:53:24 +0100 (Sun, 26 Feb 2006)
New Revision: 525

Modified:
   skencil/trunk/ChangeLog
   skencil/trunk/Sketch/Editor/tools.py
   skencil/trunk/test/ChangeLog
   skencil/trunk/test/test_tools.py
Log:

* Sketch/Editor/tools.py (ZoomToolInstance.ButtonRelease): Handle
the case where the object returned by self.end_edit_object is
None.  This can happen when the user switches to the zoom tool
with the keyboard while pressing down the mouse button.

* test_tools.py (MockZoomCanvas): New helper class for the Zoom tests
(TestZoomTool): New. Tests for the ZoomTool.


Modified: skencil/trunk/ChangeLog
===================================================================
--- skencil/trunk/ChangeLog	2006-02-26 22:10:50 UTC (rev 524)
+++ skencil/trunk/ChangeLog	2006-02-26 22:53:24 UTC (rev 525)
@@ -1,5 +1,12 @@
 2006-02-26  Bernhard Herzog  <bh at intevation.de>
 
+	* Sketch/Editor/tools.py (ZoomToolInstance.ButtonRelease): Handle
+	the case where the object returned by self.end_edit_object is
+	None.  This can happen when the user switches to the zoom tool
+	with the keyboard while pressing down the mouse button.
+
+2006-02-26  Bernhard Herzog  <bh at intevation.de>
+
 	Savannah Patch #4516 by Valentin Ungureanu:
 
 	* Sketch/Editor/tools.py (TemporaryToolInstance): New. A class

Modified: skencil/trunk/Sketch/Editor/tools.py
===================================================================
--- skencil/trunk/Sketch/Editor/tools.py	2006-02-26 22:10:50 UTC (rev 524)
+++ skencil/trunk/Sketch/Editor/tools.py	2006-02-26 22:53:24 UTC (rev 525)
@@ -223,9 +223,12 @@
 
     def ButtonRelease(self, context, p, snapped, button, state):
         ToolInstance.ButtonRelease(self, context, p, snapped, button, state)
-        object = self.end_edit_object(context, p, button, state)
-        context.zoom_area(object.bounding_rect,
-                          out = state & const.ZoomOutMask)
+        obj = self.end_edit_object(context, p, button, state)
+        # obj may be None if e.g. the user switches to the zoom tool with the
+        # keyboard while pressing down the mouse button.
+        if obj is not None:
+            context.zoom_area(obj.bounding_rect,
+                              out = state & const.ZoomOutMask)
 
     def ButtonClick(self, context, p, snapped, button, state, handle = None):
         ToolInstance.ButtonClick(self, context, p, snapped, button, state,

Modified: skencil/trunk/test/ChangeLog
===================================================================
--- skencil/trunk/test/ChangeLog	2006-02-26 22:10:50 UTC (rev 524)
+++ skencil/trunk/test/ChangeLog	2006-02-26 22:53:24 UTC (rev 525)
@@ -1,5 +1,11 @@
 2006-02-26  Bernhard Herzog  <bh at intevation.de>
 
+	* test_tools.py (MockZoomCanvas): New helper class for the Zoom
+	tests
+	(TestZoomTool): New. Tests for the ZoomTool.
+
+2006-02-26  Bernhard Herzog  <bh at intevation.de>
+
 	Savannah Patch #4516 by Valentin Ungureanu:
 
 	* test_tools.py: New.  Tests for temporary tools.  Tests for other

Modified: skencil/trunk/test/test_tools.py
===================================================================
--- skencil/trunk/test/test_tools.py	2006-02-26 22:10:50 UTC (rev 524)
+++ skencil/trunk/test/test_tools.py	2006-02-26 22:53:24 UTC (rev 525)
@@ -27,11 +27,11 @@
 support.add_sketch_dir_to_path()
 
 import Sketch
-from Sketch import Point, CreatePath
+from Sketch import Point, CreatePath, Rect
 from Sketch.Base.const import TOOL
 from Sketch.Graphics import PolyBezier
 from Sketch.Editor import EditorWithSelection, InteractiveDocument, Context, \
-     Button1Mask, toolmap, Button1
+     Button1Mask, ZoomOutMask, toolmap, Button1
 from Sketch.Editor.selectiontool import SelectionRectangle
 from Sketch.Editor.tools import ToolInfo, TemporaryToolInstance
 
@@ -345,6 +345,78 @@
         self.assertToolMessages([('SelectionTool',)])
 
 
+class MockZoomCanvas(MockCanvas):
+
+    def __init__(self):
+        self.called_methods = []
+
+    def zoom_area(self, rect, out):
+        self.called_methods.append(("zoom_area", rect, out))
+
+
+class TestZoomTool(unittest.TestCase):
+
+    def setUp(self):
+        self.document = InteractiveDocument(create_layer = 1)
+        self.editor = EditorWithSelection(self.document)
+        self.context = Context(None)
+        self.context.set_editor(self.editor)
+        self.canvas = MockZoomCanvas()
+
+        # Make sure snapping is off
+        self.failIf(self.editor.IsSnappingToGrid())
+        self.failIf(self.editor.IsSnappingToGuides())
+        self.failIf(self.editor.IsSnappingToObjects())
+
+    def tearDown(self):
+        if self.editor is not None:
+            self.editor.Destroy()
+        self.editor = self.document = self.canvas = self.context = None
+
+    def test_area_zoom_in(self):
+        """Test an area zoom that zooms in"""
+        self.editor.SetTool("ZoomTool")
+        self.editor.ButtonPress(self.canvas, Point(123, 47), Button1, 0)
+        self.editor.PointerMotion(self.canvas, Point(130.5, 51.7), Button1Mask)
+        self.editor.ButtonRelease(self.canvas, Point(150, 60), Button1,
+                                  Button1Mask)
+
+        # zoom_area must have been called with out set to a false value
+        self.assertEquals(self.canvas.called_methods,
+                          [("zoom_area", Rect(123, 47, 150, 60),  0)])
+
+    def test_area_zoom_out(self):
+        """Test an area zoom that zooms out"""
+        self.editor.SetTool("ZoomTool")
+        self.editor.ButtonPress(self.canvas, Point(123, 47), Button1, 0)
+        self.editor.PointerMotion(self.canvas, Point(130.5, 51.7), Button1Mask)
+        self.editor.ButtonRelease(self.canvas, Point(150, 60), Button1,
+                                  ZoomOutMask|Button1Mask)
+
+        # zoom_area must have been called with out set to a true value.
+        # Ideally it should be True, but the actual implementation uses
+        # ZoomOutMask currently.
+        self.assertEquals(self.canvas.called_methods,
+                          [("zoom_area", Rect(123, 47, 150, 60),  ZoomOutMask)])
+
+    def test_activating_zoom_during_drag(self):
+        """Test activating the zoom tool during a drag
+
+        When the zoom tool is activated during a drag, it's
+        ButtonRelease method will be called when the mouse button is
+        released, but it cannot zoom because the action started with the
+        previous tool has been implicitly cancelled.
+        """
+        self.editor.ButtonPress(self.canvas, Point(123, 47), Button1, 0)
+        self.editor.PointerMotion(self.canvas, Point(130.5, 51.7), Button1Mask)
+        self.editor.SetTool("ZoomTool")
+        self.editor.ButtonRelease(self.canvas, Point(150, 60), Button1,
+                                  Button1Mask)
+        # The zoom_area method must not have been called.
+        self.assertEquals(self.canvas.called_methods, [])
+
+
+
 if __name__ == "__main__":
     unittest.main()
 



More information about the Skencil-commits mailing list