From 1d2eb2e39d71404f266f72cb5e1f4adf9ebfc221 Mon Sep 17 00:00:00 2001 From: mprosperi Date: Wed, 31 May 2023 15:39:33 +0200 Subject: [PATCH] fix float->int compatibility for py3.10+ (also fixes #2349) --- wx/lib/ogl/basic.py | 16 ++++++++-------- wx/lib/ogl/diagram.py | 2 +- wx/lib/ogl/drawn.py | 18 +++++++++--------- wx/lib/ogl/oglmisc.py | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/wx/lib/ogl/basic.py b/wx/lib/ogl/basic.py index e7e17bc8..37341ab7 100644 --- a/wx/lib/ogl/basic.py +++ b/wx/lib/ogl/basic.py @@ -1377,11 +1377,11 @@ class Shape(ShapeEvtHandler): def OnDrawOutline(self, dc, x, y, w, h): """The draw outline handler.""" - points = [[x - w / 2.0, y - h / 2.0], - [x + w / 2.0, y - h / 2.0], - [x + w / 2.0, y + h / 2.0], - [x - w / 2.0, y + h / 2.0], - [x - w / 2.0, y - h / 2.0], + points = [[int(x - w / 2.0), int(y - h / 2.0)], + [int(x + w / 2.0), int(y - h / 2.0)], + [int(x + w / 2.0), int(y + h / 2.0)], + [int(x - w / 2.0), int(y + h / 2.0)], + [int(x - w / 2.0), int(y - h / 2.0)], ] dc.DrawLines(points) @@ -3174,7 +3174,7 @@ class PolygonShape(Shape): dc.SetPen(self._pen) if self._brush: dc.SetBrush(self._brush) - dc.DrawPolygon(self._points, self._xpos, self._ypos) + dc.DrawPolygon(self._points, int(self._xpos), int(self._ypos)) def OnDrawOutline(self, dc, x, y, w, h): """The draw outline handler.""" @@ -3185,8 +3185,8 @@ class PolygonShape(Shape): intPoints = [] for point in self._originalPoints: - intPoints.append(wx.Point(x_proportion * point[0], y_proportion * point[1])) - dc.DrawPolygon(intPoints, x, y) + intPoints.append(wx.Point(int(x_proportion * point[0]), int(y_proportion * point[1]))) + dc.DrawPolygon(intPoints, int(x), int(y)) # Make as many control points as there are vertices def MakeControlPoints(self): diff --git a/wx/lib/ogl/diagram.py b/wx/lib/ogl/diagram.py index be3865ad..d24b3c6b 100644 --- a/wx/lib/ogl/diagram.py +++ b/wx/lib/ogl/diagram.py @@ -116,7 +116,7 @@ class Diagram(object): dc.SetPen(wx.Pen(wx.BLACK, 1, wx.PENSTYLE_DOT)) dc.SetBrush(wx.TRANSPARENT_BRUSH) - dc.DrawLines([[x1, y1], [x2, y1], [x2, y2], [x1, y2], [x1, y1]]) + dc.DrawLines([[int(x1), int(y1)], [int(x2), int(y1)], [int(x2), int(y2)], [int(x1), int(y2)], [int(x1), int(y1)]]) def RecentreAll(self, dc): """Recentre all the text that should be centred. diff --git a/wx/lib/ogl/drawn.py b/wx/lib/ogl/drawn.py index 17a2992c..2da0025b 100644 --- a/wx/lib/ogl/drawn.py +++ b/wx/lib/ogl/drawn.py @@ -165,21 +165,21 @@ class OpDraw(DrawOp): def Do(self, dc, xoffset, yoffset): if self._op == DRAWOP_DRAW_LINE: - dc.DrawLine(self._x1 + xoffset, self._y1 + yoffset, self._x2 + xoffset, self._y2 + yoffset) + dc.DrawLine(int(self._x1 + xoffset), int(self._y1 + yoffset), int(self._x2 + xoffset), int(self._y2 + yoffset)) elif self._op == DRAWOP_DRAW_RECT: - dc.DrawRectangle(self._x1 + xoffset, self._y1 + yoffset, self._x2, self._y2) + dc.DrawRectangle(int(self._x1 + xoffset), int(self._y1 + yoffset), int(self._x2), int(self._y2)) elif self._op == DRAWOP_DRAW_ROUNDED_RECT: - dc.DrawRoundedRectangle(self._x1 + xoffset, self._y1 + yoffset, self._x2, self._y2, self._radius) + dc.DrawRoundedRectangle(int(self._x1 + xoffset), int(self._y1 + yoffset), int(self._x2), int(self._y2), self._radius) elif self._op == DRAWOP_DRAW_ELLIPSE: - dc.DrawEllipse(self._x1 + xoffset, self._y1 + yoffset, self._x2, self._y2) + dc.DrawEllipse(int(self._x1 + xoffset), int(self._y1 + yoffset), int(self._x2), int(self._y2)) elif self._op == DRAWOP_DRAW_ARC: - dc.DrawArc(self._x2 + xoffset, self._y2 + yoffset, self._x3 + xoffset, self._y3 + yoffset, self._x1 + xoffset, self._y1 + yoffset) + dc.DrawArc(int(self._x2 + xoffset), int(self._y2 + yoffset), int(self._x3 + xoffset), int(self._y3 + yoffset), int(self._x1 + xoffset), int(self._y1 + yoffset)) elif self._op == DRAWOP_DRAW_ELLIPTIC_ARC: - dc.DrawEllipticArc(self._x1 + xoffset, self._y1 + yoffset, self._x2, self._y2, self._x3 * 360 / (2 * math.pi), self._y3 * 360 / (2 * math.pi)) + dc.DrawEllipticArc(int(self._x1 + xoffset), int(self._y1 + yoffset), int(self._x2), int(self._y2), self._x3 * 360 / (2 * math.pi), self._y3 * 360 / (2 * math.pi)) elif self._op == DRAWOP_DRAW_POINT: dc.DrawPoint(self._x1 + xoffset, self._y1 + yoffset) elif self._op == DRAWOP_DRAW_TEXT: - dc.DrawText(self._textString, self._x1 + xoffset, self._y1 + yoffset) + dc.DrawText(self._textString, int(self._x1 + xoffset), int(self._y1 + yoffset)) def Scale(self, scaleX, scaleY): self._x1 *= scaleX self._y1 *= scaleY @@ -267,9 +267,9 @@ class OpPolyDraw(DrawOp): def Do(self, dc, xoffset, yoffset): if self._op == DRAWOP_DRAW_POLYLINE: - dc.DrawLines(self._points, xoffset, yoffset) + dc.DrawLines(self._points, int(xoffset), int(yoffset)) elif self._op == DRAWOP_DRAW_POLYGON: - dc.DrawPolygon(self._points, xoffset, yoffset) + dc.DrawPolygon(self._points, int(xoffset), int(yoffset)) elif self._op == DRAWOP_DRAW_SPLINE: dc.DrawSpline(self._points) # no offsets in DrawSpline diff --git a/wx/lib/ogl/oglmisc.py b/wx/lib/ogl/oglmisc.py index 78263aba..a685a329 100644 --- a/wx/lib/ogl/oglmisc.py +++ b/wx/lib/ogl/oglmisc.py @@ -528,7 +528,7 @@ def GetArrowPoints(x1, y1, x2, y2, length, width): x3 = -length * i_bar + x2 y3 = -length * j_bar + y2 - return x2, y2, width * -j_bar + x3, width * i_bar + y3, -width * -j_bar + x3, -width * i_bar + y3 + return int(x2), int(y2), int(width * -j_bar + x3), int(width * i_bar + y3), int(-width * -j_bar + x3), int(-width * i_bar + y3) def DrawArcToEllipse(x1, y1, width1, height1, x2, y2, x3, y3):