|
From: Kevin A. <al...@se...> - 2001-12-28 20:20:12
|
Normally, I don't go into the details of a bug fix, but this is starting to
look like a big one that is going to impact more than the resourceEditor, so
I'm going to detail it here.
Almost since the first version of the resourceEditor was created there has
been a strange bug that caused the sizing handles to be positioned
incorrectly but not all the time. I noticed today that the problem could
definitely be reproduced for some widgets if the View Attributes menu was
used and I traced the problem to the widgetAttributes method:
size = getattr(aWidget, 'size')
if aWidget.__class__.__name__ != 'BitmapCanvas':
bestWidth, bestHeight = aWidget._delegate.GetBestSize()
if bestWidth == size[0]:
size[0] = -1
if bestHeight == size[1]:
size[1] = -1
if size != (-1, -1):
dStr += " 'size':%s, \n" % size
The problem is that size should be a tuple such as (10, 10) but it isn't and
in addition the line:
size = getattr(aWidget, 'size')
means that size isn't really a local variable copy of the widget size, but
instead points to the same memory because size is a list, so any changes to
size also change the widget size as a side-effect. And that was what was
causing the problem. If size was a tuple, then something like:
size[0] = -1
would generate a runtime error. What misled me is that wxSize apparently
returns a representation so that when you print a wxSize it looks like a
tuple, even though it isn't.
Here's the corrected version in cvs:
# try and determine default sizes
width, height = aWidget.size
if aWidget.__class__.__name__ != 'BitmapCanvas':
bestWidth, bestHeight = aWidget._delegate.GetBestSize()
if bestWidth == width:
width = -1
if bestHeight == height:
height = -1
if width != -1 or height != -1:
dStr += " 'size':(%d, %d), \n" % (width, height)
That fixes that bug in the resourceEditor sample, but there could be
problems in more of the samples, basically any place that the size of a
widget is manipulated as a list instead of a tuple. The real culprits are
the _setSize and _getSize methods of the Widget class which are invoked when
you use something like:
print self.components.btn1.size
def _setSize(self, aSize):
self._delegate.SetSize(aSize)
# get the actual size, not (-1, -1)
self._size = self._delegate.GetSize()
def _getSize(self):
return self._size
When I went back to read the wxPython docs it became apparent that I should
have been using GetSizeTuple(). Doh!
I don't remember why we decided to cache the _size attribute, it was lost in
the shuffle to dot notation, but I'm going to leave it until I can go
through all the samples and widget classes and make sure we don't need _size
before changing it so that _getSize just does:
def _getSize(self):
return self._delegate.GetSizeTuple()
In conclusion, the resourceEditor has another fix and I'm currently chasing
down widget size issues in the samples.
ka
ps. I wonder how many email filters will catch "nasty" and "exposed" above
and filter this email ;-)
|