I cannot tell whether the original code worked before, but this explicit typecasting is necessary now.
The issue occurs, for example if attempting to execute "PieChart.py" or "ScaledBitmap2Demo.py" in "samples\floatcanvas". Without typecasting, type errors are thrown, such as "TypeError: Image.Scale(): argument 1 has unexpected type 'numpy.float64'".
Apparently, this problem might be due to recent updates in Python and NumPy.
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
In response to a note from Kevin Gregory:
""
Sorry to email you directly, I wanted to submit a bugfix for FloatCanvas ScaledBitmap. It changes the bmpWidth and bmpHeight from integers to floats so that the scale is computed correctly.
FCObjects.py line 2141 from the wxpython phoenix dev build
"""