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

@@ -393,7 +393,7 @@ class SizeReportCtrl(wx.Control):
dc.SetPen(wx.LIGHT_GREY_PEN)
dc.DrawLine(0, 0, size.x, size.y)
dc.DrawLine(0, size.y, size.x, 0)
dc.DrawText(s, (size.x-w)/2, (size.y-height*5)/2)
dc.DrawText(s, (size.x-w)//2, (size.y-height*5)//2)
if self._mgr:
@@ -401,19 +401,19 @@ class SizeReportCtrl(wx.Control):
s = "Layer: %d"%pi.dock_layer
w, h = dc.GetTextExtent(s)
dc.DrawText(s, (size.x-w)/2, ((size.y-(height*5))/2)+(height*1))
dc.DrawText(s, (size.x-w)//2, ((size.y-(height*5))//2)+(height*1))
s = "Dock: %d Row: %d"%(pi.dock_direction, pi.dock_row)
w, h = dc.GetTextExtent(s)
dc.DrawText(s, (size.x-w)/2, ((size.y-(height*5))/2)+(height*2))
dc.DrawText(s, (size.x-w)//2, ((size.y-(height*5))//2)+(height*2))
s = "Position: %d"%pi.dock_pos
w, h = dc.GetTextExtent(s)
dc.DrawText(s, (size.x-w)/2, ((size.y-(height*5))/2)+(height*3))
dc.DrawText(s, (size.x-w)//2, ((size.y-(height*5))//2)+(height*3))
s = "Proportion: %d"%pi.dock_proportion
w, h = dc.GetTextExtent(s)
dc.DrawText(s, (size.x-w)/2, ((size.y-(height*5))/2)+(height*4))
dc.DrawText(s, (size.x-w)//2, ((size.y-(height*5))//2)+(height*4))
def OnEraseBackground(self, event):
@@ -435,7 +435,7 @@ class SettingsPanel(wx.Panel):
s1 = wx.BoxSizer(wx.HORIZONTAL)
self._border_size = wx.SpinCtrl(self, ID_PaneBorderSize, "%d"%frame.GetDockArt().GetMetric(aui.AUI_DOCKART_PANE_BORDER_SIZE),
wx.DefaultPosition, wx.Size(50, 20), wx.SP_ARROW_KEYS, 0, 100,
wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 100,
frame.GetDockArt().GetMetric(aui.AUI_DOCKART_PANE_BORDER_SIZE))
s1.Add((1, 1), 1, wx.EXPAND)
s1.Add(wx.StaticText(self, -1, "Pane Border Size:"))
@@ -445,7 +445,7 @@ class SettingsPanel(wx.Panel):
s2 = wx.BoxSizer(wx.HORIZONTAL)
self._sash_size = wx.SpinCtrl(self, ID_SashSize, "%d"%frame.GetDockArt().GetMetric(aui.AUI_DOCKART_SASH_SIZE), wx.DefaultPosition,
wx.Size(50, 20), wx.SP_ARROW_KEYS, 0, 100, frame.GetDockArt().GetMetric(aui.AUI_DOCKART_SASH_SIZE))
wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 100, frame.GetDockArt().GetMetric(aui.AUI_DOCKART_SASH_SIZE))
s2.Add((1, 1), 1, wx.EXPAND)
s2.Add(wx.StaticText(self, -1, "Sash Size:"))
s2.Add(self._sash_size)
@@ -454,7 +454,7 @@ class SettingsPanel(wx.Panel):
s3 = wx.BoxSizer(wx.HORIZONTAL)
self._caption_size = wx.SpinCtrl(self, ID_CaptionSize, "%d"%frame.GetDockArt().GetMetric(aui.AUI_DOCKART_CAPTION_SIZE),
wx.DefaultPosition, wx.Size(50, 20), wx.SP_ARROW_KEYS, 0, 100, frame.GetDockArt().GetMetric(aui.AUI_DOCKART_CAPTION_SIZE))
wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 100, frame.GetDockArt().GetMetric(aui.AUI_DOCKART_CAPTION_SIZE))
s3.Add((1, 1), 1, wx.EXPAND)
s3.Add(wx.StaticText(self, -1, "Caption Size:"))
s3.Add(self._caption_size)
@@ -807,9 +807,9 @@ class ProgressGauge(wx.Window):
# We take the percent way of the colour from colour -> white
i = percent
r = colour.Red() + ((i*rd*100)/high)/100
g = colour.Green() + ((i*gd*100)/high)/100
b = colour.Blue() + ((i*bd*100)/high)/100
r = colour.Red() + ((i*rd*100)//high)//100
g = colour.Green() + ((i*gd*100)//high)//100
b = colour.Blue() + ((i*bd*100)//high)//100
return wx.Colour(r, g, b)
@@ -826,10 +826,10 @@ class ProgressGauge(wx.Window):
x, y, width, height = clientRect
x, width = self._pos, interval
gradientRect.SetHeight(gradientRect.GetHeight()/2)
gradientRect.SetHeight(gradientRect.GetHeight()//2)
topStart, topEnd = self._topStartColour, self._topEndColour
rc1 = wx.Rect(x, y, width, height/2)
rc1 = wx.Rect(int(x), y, int(width), height//2)
path1 = self.GetPath(gc, rc1, 8)
br1 = gc.CreateLinearGradientBrush(x, y, x, y+height/2, topStart, topEnd)
gc.SetBrush(br1)
@@ -845,14 +845,14 @@ class ProgressGauge(wx.Window):
bottomStart, bottomEnd = self._bottomStartColour, self._bottomEndColour
rc3 = wx.Rect(x, y+height/2, width, height/2)
rc3 = wx.Rect(int(x), y+height//2, int(width), height//2)
path3 = self.GetPath(gc, rc3, 8)
br3 = gc.CreateLinearGradientBrush(x, y+height/2, x, y+height, bottomStart, bottomEnd)
gc.SetBrush(br3)
gc.FillPath(path3) #draw main
path4 = gc.CreatePath()
path4.AddRectangle(x, y+height/2, width, 8)
path4.AddRectangle(x, y+height//2, width, 8)
path4.CloseSubpath()
gc.SetBrush(br3)
gc.FillPath(path4)
@@ -2613,7 +2613,7 @@ class AuiFrame(wx.Frame):
flex.Add(wx.TextCtrl(panel, -1, "", wx.DefaultPosition, wx.Size(100, -1)),
1, wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add(wx.StaticText(panel, -1, "wxSpinCtrl:"), 0, wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add(wx.SpinCtrl(panel, -1, "5", wx.DefaultPosition, wx.Size(100, -1),
flex.Add(wx.SpinCtrl(panel, -1, "5", wx.DefaultPosition, wx.DefaultSize,
wx.SP_ARROW_KEYS, 5, 50, 5), 0, wx.ALL|wx.ALIGN_CENTRE, 5)
flex.Add((5, 5))
flex.Add((5, 5))

View File

@@ -223,12 +223,12 @@ class MacRenderer(object):
mdc.SelectObject(wx.NullBitmap)
# Center the progress bar vertically in the box supplied
y = y + (h - PIPE_HEIGHT)/2
y = y + (h - PIPE_HEIGHT)//2
if percent == 0:
middle = 0
else:
middle = (w * percent)/100
middle = int((w * percent)/100)
if w < 1:
return

View File

@@ -149,10 +149,10 @@ class PeakMeterCtrlDemo(wx.Panel):
def OnStart(self, event):
self.timer.Start(1000/2) # 2 fps
self.timer.Start(1000//2) # 2 fps
self.vertPeak.Start(1000/18) # 18 fps
self.horzPeak.Start(1000/20) # 20 fps
self.vertPeak.Start(1000//18) # 18 fps
self.horzPeak.Start(1000//20) # 20 fps
def OnStop(self, event):

View File

@@ -234,7 +234,7 @@ class PersistentFrame1(wx.Frame):
sizer_1.Add(label_1, 0, wx.ALL, 5)
sizer_1.Add(combo, 0, wx.LEFT|wx.RIGHT, 5)
sizer_1.Add((20, 20), 1)
box2.Add(sizer_1, 1, wx.EXPAND|wx.ALIGN_CENTER, 0)
box2.Add(sizer_1, 1, wx.EXPAND, 0)
box2.Add((0, 0), 1, 1)
otherPanel.SetSizer(box2)

View File

@@ -799,7 +799,7 @@ class RibbonFrame(wx.Frame):
(c.Blue() + 192) % 256)
dc.SetTextForeground(foreground)
dc.DrawText(colour, (iWidth - size.GetWidth() + 1) / 2, (iHeight - size.GetHeight()) / 2)
dc.DrawText(colour, (iWidth - size.GetWidth() + 1) // 2, (iHeight - size.GetHeight()) // 2)
dc.SelectObjectAsSource(wx.NullBitmap)
item = gallery.Append(bitmap, wx.ID_ANY)

View File

@@ -418,7 +418,7 @@ class SpeedMeterDemo(wx.Panel):
bsizer3 = wx.BoxSizer(wx.VERTICAL)
hsizer3 = wx.BoxSizer(wx.HORIZONTAL)
sc = wx.SpinCtrl(panel3, -1, size=(60,20))
sc = wx.SpinCtrl(panel3, -1)
sc.SetRange(1, 250)
sc.SetValue(50)

View File

@@ -43,7 +43,7 @@ class SuperToolTipDemo(wx.Frame):
self.topColourPicker = wx.ColourPickerCtrl(self.mainPanel, colour=wx.WHITE)
system = wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION)
r, g, b, a = system
self.middleColourPicker = wx.ColourPickerCtrl(self.mainPanel, colour=wx.Colour((255-r)/2, (255-g)/2, (255-b)/2))
self.middleColourPicker = wx.ColourPickerCtrl(self.mainPanel, colour=wx.Colour((255-r)//2, (255-g)//2, (255-b)//2))
self.bottomColourPicker = wx.ColourPickerCtrl(self.mainPanel, colour=system)
self.headerCheck = wx.CheckBox(self.mainPanel, -1, "Show Header")
self.headerText = wx.TextCtrl(self.mainPanel, -1, "Merge And Center")
@@ -233,7 +233,6 @@ class SuperToolTipDemo(wx.Frame):
frameSizer.Add(self.mainPanel, 1, wx.EXPAND, 0)
self.SetSizer(frameSizer)
frameSizer.Layout()
frameSizer.Fit(self)
self.Layout()
wx.CallAfter(mainSizer.Layout)

View File

@@ -4,6 +4,7 @@ import wx
import os
import images
import wx.lib.agw.scrolledthumbnail as TC
from wx.lib.agw.scrolledthumbnail import (ScrolledThumbnail,
Thumb,
NativeImageHandler,

View File

@@ -216,7 +216,7 @@ class UltimateRenderer_1(object):
mdc.SetFont(wx.Font(8, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
text = "%d Mb"%self.progressValue
textWidth, dummy = mdc.GetTextExtent(text)
mdc.DrawText(text, rect.width/2 - textWidth/2, rect.height/2 - dummy/2)
mdc.DrawText(text, rect.width//2 - textWidth//2, rect.height//2 - dummy//2)
dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height)
dc.Blit(rect.x+3, rect.y, rect.width-6, rect.height, mdc, 0, 0)
dc.DestroyClippingRegion()
@@ -279,12 +279,12 @@ class UltimateRenderer_1(object):
mdc.SelectObject(wx.NullBitmap)
# Center the progress bar vertically in the box supplied
y = y + (h - PIPE_HEIGHT)/2
y = y + (h - PIPE_HEIGHT)//2
if percent == 0:
middle = 0
else:
middle = (w * percent)/100
middle = (w * percent)//100
if middle == 0: # not started
bitmap = self.REMAINING_BITMAP.GetSubBitmap((1, 0, w, PIPE_HEIGHT))
@@ -335,7 +335,7 @@ class UltimateRenderer_2(object):
colours = [wx.RED, wx.WHITE, wx.GREEN, wx.Colour("SKY BLUE")]
w, h = dc.GetTextExtent("Hg")
x = rect.x + 1
y = rect.y + rect.height/2 - h/2
y = rect.y + rect.height//2 - h//2
for ch in self.text:
dc.SetTextForeground(random.choice(colours))

View File

@@ -127,13 +127,13 @@ class FirstColumnRenderer(object):
"""Draw a custom progress bar using double buffering to prevent flicker"""
bmpWidth, bmpHeight = self.icon.GetWidth(), self.icon.GetHeight()
dc.DrawIcon(self.icon, rect.x+5, rect.y+(rect.height-bmpHeight)/2)
dc.DrawIcon(self.icon, rect.x+5, rect.y+(rect.height-bmpHeight)//2)
dc.SetFont(self.normalFont)
textWidth, textHeight = dc.GetTextExtent(self.text)
dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNTEXT))
dc.DrawText(self.text, rect.x+bmpWidth+10, rect.y+(rect.height - textHeight)/4)
dc.DrawText(self.text, rect.x+bmpWidth+10, rect.y+(rect.height - textHeight)//4)
if not self.description:
return
@@ -144,10 +144,10 @@ class FirstColumnRenderer(object):
textWidth, textHeight = dc.GetTextExtent("Type: " + self.description)
dc.SetTextForeground(self.greyColour)
dc.DrawText("Type: ", rect.x+bmpWidth+10, rect.y+3*(rect.height - textHeight)/4)
dc.DrawText("Type: ", rect.x+bmpWidth+10, rect.y+3*(rect.height - textHeight)//4)
dc.SetTextForeground(wx.BLACK)
dc.DrawText(self.description, rect.x+bmpWidth+dummy1+10, rect.y+3*(rect.height - textHeight)/4)
dc.DrawText(self.description, rect.x+bmpWidth+dummy1+10, rect.y+3*(rect.height - textHeight)//4)
def GetLineHeight(self):
@@ -207,10 +207,10 @@ class SecondColumnRenderer(object):
textWidth, textHeight = dc.GetTextExtent("Date modified: " + date)
dc.SetTextForeground(self.greyColour)
dc.DrawText("Date modified: ", rect.x+5, rect.y+(rect.height - textHeight)/4)
dc.DrawText("Date modified: ", rect.x+5, rect.y+(rect.height - textHeight)//4)
dc.SetTextForeground(wx.BLACK)
dc.DrawText(date, rect.x+dummy1+5, rect.y+(rect.height - textHeight)/4)
dc.DrawText(date, rect.x+dummy1+5, rect.y+(rect.height - textHeight)//4)
if not self.size:
return
@@ -218,10 +218,10 @@ class SecondColumnRenderer(object):
dummy1, dummy2= dc.GetTextExtent("Size: ")
dc.SetTextForeground(self.greyColour)
dc.DrawText("Size: ", rect.x+5, rect.y+3*(rect.height - textHeight)/4)
dc.DrawText("Size: ", rect.x+5, rect.y+3*(rect.height - textHeight)//4)
dc.SetTextForeground(wx.BLACK)
dc.DrawText(self.size, rect.x+dummy1+5, rect.y+3*(rect.height - textHeight)/4)
dc.DrawText(self.size, rect.x+dummy1+5, rect.y+3*(rect.height - textHeight)//4)
def GetLineHeight(self):

View File

@@ -55,7 +55,7 @@ class TestPanel(wx.Panel):
reflections = glob.glob(bitmapDir + "/*96Flip40.png")
separatorImage = bitmapDir + "/separator.gif"
separatorReflection = bitmapDir + "/separatorFlip.png"
separatorReflection = bitmapDir + "/separatorflip.png"
count = 0
for std, ref in zip(standard, reflections):