[PythonCAD] R25 bug

Art Haas ahaas at airmail.net
Mon Jun 6 20:30:27 CEST 2005

On Fri, Jun 03, 2005 at 09:58:34AM -0500, Art Haas wrote:
> On Sat, Jun 04, 2005 at 12:01:40AM +1200, Wilbert Knol wrote:
> > On Sat, 28 May 2005 05:59, Michele Petrazzo wrote:
> > 
> > > - I draw an object (line, circle, etc..), I select move (one of the
> > > three), I select the first point to move, the second and after I select
> > > no objects then the program ask me for select an object (I click two
> > > times into the canvas). After I re-click for the distance (first and
> > > second point), but now I click over the object, and I receive this error:
> > 
> > Well spotted. I see the same thing here. First time I move an empty selection. 
> > All is well. Nothing gets moved (as expected). Now, when I try to move an 
> > object, I get the 'list index out of range' error:
> > [ ... snip backtrace ... ]
> I've duplicated this now. I believe the root of this problem is that the first
> selection doesn't return any entities. Today's challenge for me is to
> fix this.

It turned out to be _today's_ challenge instead of Friday as other
things needed doing over the weekend.

Here's a patch to try. The problem was in the Image class and the
counter used to track what actions get placed in the undo stack. In the
case above no objects were selected, so nothing moved, but the count
was incremented anyway, leading to an IndexError exception. By setting
the count variable to the length of the undo array this problem is

I suspect this bug could have been tripped in numerous other routines,
so the fix below, if it is indeed all that is needed, is a nice improvement.
Try it out and let me know if it works for you. It worked for me, so it
must be right, right? :-)


Index: PythonCAD/Generic/image.py
--- PythonCAD/Generic/image.py	(revision 1865)
+++ PythonCAD/Generic/image.py	(revision 1868)
@@ -1354,7 +1354,7 @@
         if not self.__busy:
             raise ValueError, "Image not in busy state"
         self.__busy = False
-        self.__action = self.__action + 1
+        self.__action = len(self.__undo)
     def inAction(self):
         """Test if the Image is with a startAction()/endAction() operation.

Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822

More information about the PythonCAD mailing list