Fix a bunch of Python 3.10 issues with pure-Python classes and demos

In Python 3.10, a change[1] was implemented where extension functions
that take integer arguments will no longer silently accept non-integer
arguments (e.g., floats) that can only be converted to integers with a
loss of precision.  This PR fixes most of these issues in the pure-Python
classes and demos by explicitly converting the parameters to int before
passing them to wxWidgets.  There is loss of precision, but this was
happening before (automatically) anyway as most wxWidgets DeviceContext
functions operate using integers.

Additionally, the PR fixes a few sizing issues, mostly with SpinCtrls being
too small on GTK3.

This is an example of the relevant exception:
Traceback (most recent call last):
  File "/usr/lib64/python3.10/site-packages/wx/lib/agw/pygauge.py", line 355, in OnPaint
    r.width = w
TypeError: 'float' object cannot be interpreted as an integer

Fixes #2038.

[1] https://bugs.python.org/issue37999
This commit is contained in:
Scott Talbert
2021-12-01 14:19:00 -05:00
parent 9a8a9b019c
commit 173d079681
71 changed files with 410 additions and 397 deletions

View File

@@ -296,7 +296,7 @@ class DrawObject:
else:
self.Pen = self.PenList.setdefault(
(LineColor, LineStyle, LineWidth),
wx.Pen(LineColor, LineWidth, self.LineStyleList[LineStyle]))
wx.Pen(LineColor, int(LineWidth), self.LineStyleList[LineStyle]))
def SetHitBrush(self, HitColor):
"""
@@ -1202,14 +1202,14 @@ class SquarePoint(XYObjectMixin, ColorOnlyMixin, DrawObject):
x = xc - Size/2.0
y = yc - Size/2.0
dc.SetBrush(self.Brush)
dc.DrawRectangle(x, y, Size, Size)
dc.DrawRectangle(int(x), int(y), Size, Size)
if HTdc and self.HitAble:
HTdc.SetPen(self.HitPen)
if self.Size <= 1:
HTdc.DrawPoint(xc, xc)
else:
HTdc.SetBrush(self.HitBrush)
HTdc.DrawRectangle(x, y, Size, Size)
HTdc.DrawRectangle(int(x), int(y), Size, Size)
class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject):
"""A RectEllipse draw object."""
@@ -2161,7 +2161,7 @@ class ScaledBitmap(TextObjectMixin, DrawObject):
W = H * (self.bmpWidth / self.bmpHeight)
if (self.ScaledBitmap is None) or (H != self.ScaledHeight) :
self.ScaledHeight = H
Img = self.Image.Scale(W, H)
Img = self.Image.Scale(int(W), int(H))
self.ScaledBitmap = wx.Bitmap(Img)
XY = self.ShiftFun(XY[0], XY[1], W, H)