From 112605f540ec8cb4826ea9c872cbb0bf09dc023d Mon Sep 17 00:00:00 2001 From: PChemGuy <39730837+pchemguy@users.noreply.github.com> Date: Sat, 20 Aug 2022 09:27:31 +0300 Subject: [PATCH 1/3] Missing NumPy package reference in FloatCanvas.py Package reference (N) is missing when NumPy type "float_" is used. --- wx/lib/floatcanvas/FloatCanvas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wx/lib/floatcanvas/FloatCanvas.py b/wx/lib/floatcanvas/FloatCanvas.py index 5d3abc44..a0c316cd 100644 --- a/wx/lib/floatcanvas/FloatCanvas.py +++ b/wx/lib/floatcanvas/FloatCanvas.py @@ -779,7 +779,7 @@ class FloatCanvas(wx.Panel): BoundingBox = self.BoundingBox if (BoundingBox is not None) and (not BoundingBox.IsNull()): self.ViewPortCenter = N.array(((BoundingBox[0,0]+BoundingBox[1,0])/2, - (BoundingBox[0,1]+BoundingBox[1,1])/2 ),float_) + (BoundingBox[0,1]+BoundingBox[1,1])/2 ),N.float_) self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter) # Compute the new Scale BoundingBox = BoundingBox*self.MapProjectionVector # this does need to make a copy! From 8d771a389cb4b8234b37d6f0709b9d6f135faf18 Mon Sep 17 00:00:00 2001 From: PChemGuy <39730837+pchemguy@users.noreply.github.com> Date: Sat, 20 Aug 2022 13:58:51 +0300 Subject: [PATCH 2/3] py3: use six.moves.range instead of xrange The xrange module was removed in Python 3 and we should use 'six.moves.range' instead of 'xrange' to make code compatible with py 2 and 3 as well. --- samples/floatcanvas/DrawBot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/floatcanvas/DrawBot.py b/samples/floatcanvas/DrawBot.py index 581aefb2..52ea41e0 100644 --- a/samples/floatcanvas/DrawBot.py +++ b/samples/floatcanvas/DrawBot.py @@ -14,6 +14,7 @@ I think it's easier with FloatCavnas, and you get zoomign and scrolling to boot! """ import wx +from six import moves from math import * try: # see if there is a local FloatCanvas to use @@ -53,7 +54,7 @@ class DrawFrame(wx.Frame): Canvas = self.Canvas phi = (sqrt(5) + 1)/2 - 1 oradius = 10.0 - for i in xrange(720): + for i in moves.xrange(720): radius = 1.5 * oradius * sin(i * pi/720) Color = (255*(i / 720.), 255*( i / 720.), 255 * 0.25) x = oradius + 0.25*i*cos(phi*i*2*pi) From af3721f1673bf90e80d0071728c8f92b0a4c42c4 Mon Sep 17 00:00:00 2001 From: PChemGuy <39730837+pchemguy@users.noreply.github.com> Date: Sat, 20 Aug 2022 17:41:12 +0300 Subject: [PATCH 3/3] Explicit NumPy.float64 to int typecasting in FCObjects.py 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. --- samples/ribbon/ribbonbar_demo.py | 2 +- wx/lib/floatcanvas/FCObjects.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/ribbon/ribbonbar_demo.py b/samples/ribbon/ribbonbar_demo.py index 78501ef0..40e5ab82 100644 --- a/samples/ribbon/ribbonbar_demo.py +++ b/samples/ribbon/ribbonbar_demo.py @@ -572,7 +572,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, int((iWidth - size.GetWidth() + 1) / 2), int((iHeight - size.GetHeight()) / 2)) dc.SelectObjectAsSource(wx.NullBitmap) item = gallery.Append(bitmap, wx.ID_ANY) diff --git a/wx/lib/floatcanvas/FCObjects.py b/wx/lib/floatcanvas/FCObjects.py index 624b03e0..bf307bdc 100644 --- a/wx/lib/floatcanvas/FCObjects.py +++ b/wx/lib/floatcanvas/FCObjects.py @@ -2269,7 +2269,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): """ XY = WorldToPixel(self.XY) H = ScaleWorldToPixel(self.Height)[0] - W = H * (self.bmpWidth / self.bmpHeight) + W = int(H * (self.bmpWidth / self.bmpHeight)) if (self.ScaledBitmap is None) or (self.ScaledBitmap[0] != (0, 0, self.bmpWidth, self.bmpHeight, W, H) ): #if True: #fixme: (self.ScaledBitmap is None) or (H != self.ScaledHeight) : self.ScaledHeight = H @@ -2689,7 +2689,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): dc.SetPen(self.Pen) for i, brush in enumerate(self.Brushes): dc.SetBrush( brush ) - dc.DrawEllipticArc(Corner[0], Corner[1], WH[0], WH[1], self.Angles[i], self.Angles[i+1]) + dc.DrawEllipticArc(int(Corner[0]), int(Corner[1]), int(WH[0]), int(WH[1]), self.Angles[i], self.Angles[i+1]) if HTdc and self.HitAble: if self.Scaled: radius = (ScaleWorldToPixel(self.Diameter)/2)[0]# just the x-coord @@ -2697,7 +2697,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): radius = self.Diameter/2 HTdc.SetPen(self.HitPen) HTdc.SetBrush(self.HitBrush) - HTdc.DrawCircle(CenterXY, radius) + HTdc.DrawCircle(CenterXY.tolist(), int(radius)) class Group(DrawObject):