orjanp wrote:
> I have a strange issue with Floatcanvas.

I'm cc-ing a copy of this to the floatcanvas list. It's the kind of 
thing I want in the archives there.


> I have the following code, this is not a complete example, since the
> codebase is to big to be posted here:

In the Demos section of floatcanvas SVN, there is a MicroDemo.py Perhaps 
you could add to it to make a demo of this problem. It's hard for me to 
test/debug without a running sample.

> This will give the following printout. The HitDict print should have
> two objects, but it only have the last one. Why?
> 
> If I remove the canv.ClearAll() and add canv._DrawList = [],
> canv.HitDict = None, it works just fine. The I get the second output,
> which is correct.

very odd. I have one idea, though. If you look at 
FloatCanvas.ClearAll(), you see:

     def ClearAll(self, ResetBB=True):
         """
         ClearAll(ResetBB=True)

         Removes all DrawObjects from the Canvas

         If ResetBB is set to False, the original bounding box will remain

         """
         self._DrawList = []
         self._ForeDrawList = []
         self._BackgroundDirty = True
         self.HitColorGenerator = None
         self.UseHitTest = False
         if ResetBB:
             self._ResetBoundingBox()
         self.MakeNewBuffers()
         self.HitDict = None

which tries to re-set everything back to its original state. ONe of 
those calls is:

         self.HitColorGenerator = None

which re-sets the HitColoGenerator. That is used to assign a unique 
color to each object on teh off-screen hit-test image, and it's also a 
key in HitDict.

However, in the DrawObject Bind method, there is:

         if not self.HitColor:
             if not self._Canvas.HitColorGenerator:
                 self._Canvas.HitColorGenerator = _colorGenerator()
                 self._Canvas.HitColorGenerator.next() # first call to 
prevent the background color from being used.
             self.HitColor = self._Canvas.HitColorGenerator.next()


So it's checkign to see if the object already has a HitColor, and only 
giving it a new one if it doesn't.

In this case, it looks like you are re-using objects, so they may have 
already been assigned a HitColor, but the HitColorGenerator is being 
reset, so it could be assigning the same color to one your objects that 
is already assigned to the other one -- so it gets overridden in the 
HitDict.

You can test this by adding another print or two:

                # Add all shapes to the canvas.
                for item in obj.objects:
                        print '--', item.object
                        print item.object.HitColor


then maybe that same print after the Bind() call.


If I'm right, I'm not sure of the fix -- you can kludge around it by 
clearing the HitColor yourself, but the Canvas doesn't know about all 
objects, only those that are on it at the time, so I'm having trouble 
figuring out where to fix this. I'll take suggestions!

-Chris

PS: thanks for teh bug report -- it's only through testing all these 
use-cases I didn't think of that things get fixed!

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to