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

@@ -453,7 +453,7 @@ class GenButton(wx.Control):
tw, th = dc.GetTextExtent(label)
if not self.up:
dx = dy = self.labelDelta
dc.DrawText(label, (width-tw)/2+dx, (height-th)/2+dy)
dc.DrawText(label, (width-tw)//2+dx, (height-th)//2+dy)
def DrawFocusIndicator(self, dc, w, h):
@@ -844,7 +844,7 @@ class GenBitmapButton(GenButton):
if not self.up:
dx = dy = self.labelDelta
hasMask = bmp.GetMask() is not None
dc.DrawBitmap(bmp, (width-bw)/2+dx, (height-bh)/2+dy, hasMask)
dc.DrawBitmap(bmp, (width-bw)//2+dx, (height-bh)//2+dy, hasMask)
#----------------------------------------------------------------------
@@ -926,12 +926,12 @@ class GenBitmapTextButton(GenBitmapButton):
if not self.up:
dx = dy = self.labelDelta
pos_x = (width-bw-tw)/2+dx # adjust for bitmap and text to centre
pos_x = (width-bw-tw)//2+dx # adjust for bitmap and text to centre
if bmp is not None:
dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask) # draw bitmap if available
dc.DrawBitmap(bmp, pos_x, (height-bh)//2+dy, hasMask) # draw bitmap if available
pos_x = pos_x + 2 # extra spacing from bitmap
dc.DrawText(label, pos_x + dx+bw, (height-th)/2+dy) # draw the text
dc.DrawText(label, pos_x + dx+bw, (height-th)//2+dy) # draw the text
#----------------------------------------------------------------------