IDE: python-3.10: wxPython calls don't accept float anymore when int is expected python3
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 12 Apr 2023 19:32:38 +0200
branchpython3
changeset 3792 365f866ee120
parent 3791 c98646b1c981
child 3793 9958cf865da0
IDE: python-3.10: wxPython calls don't accept float anymore when int is expected
editors/Viewer.py
graphics/GraphicCommons.py
graphics/RubberBand.py
plcopen/BlockInstanceCollector.py
--- a/editors/Viewer.py	Wed Apr 12 19:28:37 2023 +0200
+++ b/editors/Viewer.py	Wed Apr 12 19:32:38 2023 +0200
@@ -717,7 +717,7 @@
             faces["size"] -= 1
         self.Editor.SetFont(font)
         self.MiniTextDC = wx.MemoryDC(wx.Bitmap(1, 1))
-        self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["helv"]))
+        self.MiniTextDC.SetFont(wx.Font(int(faces["size"] * 0.75), wx.SWISS, wx.NORMAL, wx.NORMAL, faceName=faces["helv"]))
 
         self.CurrentScale = None
         self.SetScale(ZOOM_FACTORS.index(1.0), False)
@@ -1373,7 +1373,7 @@
         element.SetPosition(instance.x, instance.y)
         element.SetSize(instance.width, instance.height)
         for i, output_connector in enumerate(instance.outputs):
-            connector_pos = wx.Point(*output_connector.position)
+            connector_pos = wx.Point(*map(int, output_connector.position))
             if isinstance(element, FBD_Block):
                 connector = element.GetConnector(connector_pos,
                                                  output_name=output_connector.name)
@@ -1389,7 +1389,7 @@
                 if connectors["outputs"].index(connector) == i:
                     connector.SetPosition(connector_pos)
         for i, input_connector in enumerate(instance.inputs):
-            connector_pos = wx.Point(*input_connector.position)
+            connector_pos = wx.Point(*map(int,input_connector.position))
             if isinstance(element, FBD_Block):
                 connector = element.GetConnector(connector_pos,
                                                  input_name=input_connector.name)
@@ -1430,7 +1430,7 @@
 
             points = link.points
             end_connector = connected.GetConnector(
-                wx.Point(points[-1].x, points[-1].y)
+                wx.Point(int(points[-1].x), int(points[-1].y))
                 if len(points) > 0 else wx.Point(0, 0),
                 link.formalParameter)
             if end_connector is not None:
--- a/graphics/GraphicCommons.py	Wed Apr 12 19:28:37 2023 +0200
+++ b/graphics/GraphicCommons.py	Wed Apr 12 19:32:38 2023 +0200
@@ -183,8 +183,9 @@
     """
     pos = event.GetLogicalPosition(dc)
     if scaling:
-        pos.x = round(pos.x / scaling[0]) * scaling[0]
-        pos.y = round(pos.y / scaling[1]) * scaling[1]
+        sx,sy=tuple(map(round,scaling))
+        pos.x = round(pos.x / sx) * sx
+        pos.y = round(pos.y / sy) * sy
     return pos
 
 
@@ -201,7 +202,7 @@
 
 
 def MiterPen(colour, width=1, style=wx.SOLID):
-    pen = wx.Pen(colour, width, style)
+    pen = wx.Pen(colour, round(width), style)
     pen.SetJoin(wx.JOIN_MITER)
     pen.SetCap(wx.CAP_PROJECTING)
     return pen
@@ -314,8 +315,8 @@
 
     # Changes the block position
     def SetPosition(self, x, y):
-        self.Pos.x = x
-        self.Pos.y = y
+        self.Pos.x = int(x)
+        self.Pos.y = int(y)
         self.RefreshConnected()
         self.RefreshBoundingBox()
 
@@ -325,8 +326,8 @@
 
     # Changes the element size
     def SetSize(self, width, height):
-        self.Size.SetWidth(width)
-        self.Size.SetHeight(height)
+        self.Size.SetWidth(int(width))
+        self.Size.SetHeight(int(height))
         self.RefreshConnectors()
         self.RefreshBoundingBox()
 
@@ -431,13 +432,13 @@
         pos = event.GetPosition()
         pt = wx.Point(*self.Parent.CalcUnscrolledPosition(pos.x, pos.y))
 
-        left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
-        center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2
-        right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
-
-        top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
-        middle = (self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE // 2
-        bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
+        left = round((self.BoundingBox.x - 2) * scalex - HANDLE_SIZE)
+        center = round((self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2)
+        right = round((self.BoundingBox.x + self.BoundingBox.width + 2) * scalex)
+
+        top = round((self.BoundingBox.y - 2) * scaley - HANDLE_SIZE)
+        middle = round((self.BoundingBox.y + self.BoundingBox.height / 2) * scaley - HANDLE_SIZE // 2)
+        bottom = round((self.BoundingBox.y + self.BoundingBox.height + 2) * scaley)
 
         extern_rect = wx.Rect(left, top, right + HANDLE_SIZE - left, bottom + HANDLE_SIZE - top)
         intern_rect = wx.Rect(left + HANDLE_SIZE, top + HANDLE_SIZE, right - left - HANDLE_SIZE, bottom - top - HANDLE_SIZE)
@@ -679,13 +680,13 @@
                 dc.SetPen(MiterPen(wx.BLACK))
                 dc.SetBrush(wx.BLACK_BRUSH)
 
-                left = (self.BoundingBox.x - 2) * scalex - HANDLE_SIZE
-                center = (self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2
-                right = (self.BoundingBox.x + self.BoundingBox.width + 2) * scalex
-
-                top = (self.BoundingBox.y - 2) * scaley - HANDLE_SIZE
-                middle = (self.BoundingBox.y + self.BoundingBox.height // 2) * scaley - HANDLE_SIZE // 2
-                bottom = (self.BoundingBox.y + self.BoundingBox.height + 2) * scaley
+                left = round((self.BoundingBox.x - 2) * scalex - HANDLE_SIZE)
+                center = round((self.BoundingBox.x + self.BoundingBox.width // 2) * scalex - HANDLE_SIZE // 2)
+                right = round((self.BoundingBox.x + self.BoundingBox.width + 2) * scalex)
+
+                top = round((self.BoundingBox.y - 2) * scaley - HANDLE_SIZE)
+                middle = round((self.BoundingBox.y + self.BoundingBox.height // 2) * scaley - HANDLE_SIZE // 2)
+                bottom = round((self.BoundingBox.y + self.BoundingBox.height + 2) * scaley)
 
                 for x, y in [(left, top), (center, top), (right, top),
                              (left, middle), (right, middle),
@@ -1978,10 +1979,10 @@
             self.StartPoint = [None, vector(self.Points[0], self.Points[1])]
             self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])]
             # Calculate the start and end points
-            self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0],
-                                          self.Points[0].y + CONNECTOR_SIZE * self.StartPoint[1][1])
-            self.EndPoint[0] = wx.Point(self.Points[-1].x + CONNECTOR_SIZE * self.EndPoint[1][0],
-                                        self.Points[-1].y + CONNECTOR_SIZE * self.EndPoint[1][1])
+            self.StartPoint[0] = wx.Point(self.Points[0].x + round(CONNECTOR_SIZE * self.StartPoint[1][0]),
+                                          self.Points[0].y + round(CONNECTOR_SIZE * self.StartPoint[1][1]))
+            self.EndPoint[0] = wx.Point(self.Points[-1].x + round(CONNECTOR_SIZE * self.EndPoint[1][0]),
+                                        self.Points[-1].y + round(CONNECTOR_SIZE * self.EndPoint[1][1]))
             self.Points[0] = self.StartPoint[0]
             self.Points[-1] = self.EndPoint[0]
             # Calculate the segments directions
@@ -1992,7 +1993,7 @@
                 if i > lp - 2:
                     break
 
-                segment = vector(self.Points[i], self.Points[i + 1])
+                segment = tuple(map(round,vector(self.Points[i], self.Points[i + 1])))
 
                 # merge segment if requested
                 if merge_segments and 0 < i and \
@@ -2026,10 +2027,10 @@
     # Returns a list of the position of all wire points
     def GetPoints(self, invert=False):
         points = self.VerifyPoints()
-        points[0] = wx.Point(points[0].x - CONNECTOR_SIZE * self.StartPoint[1][0],
-                             points[0].y - CONNECTOR_SIZE * self.StartPoint[1][1])
-        points[-1] = wx.Point(points[-1].x - CONNECTOR_SIZE * self.EndPoint[1][0],
-                              points[-1].y - CONNECTOR_SIZE * self.EndPoint[1][1])
+        points[0] = wx.Point(points[0].x - round(CONNECTOR_SIZE * self.StartPoint[1][0]),
+                             points[0].y - round(CONNECTOR_SIZE * self.StartPoint[1][1]))
+        points[-1] = wx.Point(points[-1].x - round(CONNECTOR_SIZE * self.EndPoint[1][0]),
+                              points[-1].y - round(CONNECTOR_SIZE * self.EndPoint[1][1]))
         # An inversion of the list is asked
         if invert:
             points.reverse()
@@ -2068,16 +2069,16 @@
     def GeneratePoints(self, realpoints=True):
         i = 0
         # Calculate the start enad end points with the minimum segment size in the right direction
-        end = wx.Point(self.EndPoint[0].x + self.EndPoint[1][0] * MIN_SEGMENT_SIZE,
-                       self.EndPoint[0].y + self.EndPoint[1][1] * MIN_SEGMENT_SIZE)
-        start = wx.Point(self.StartPoint[0].x + self.StartPoint[1][0] * MIN_SEGMENT_SIZE,
-                         self.StartPoint[0].y + self.StartPoint[1][1] * MIN_SEGMENT_SIZE)
+        end = wx.Point(self.EndPoint[0].x + round(self.EndPoint[1][0] * MIN_SEGMENT_SIZE),
+                       self.EndPoint[0].y + round(self.EndPoint[1][1] * MIN_SEGMENT_SIZE))
+        start = wx.Point(self.StartPoint[0].x + round(self.StartPoint[1][0] * MIN_SEGMENT_SIZE),
+                         self.StartPoint[0].y + round(self.StartPoint[1][1] * MIN_SEGMENT_SIZE))
         # Evaluate the point till it's the last
         while i < len(self.Points) - 1:
             # The next point is the last
             if i + 1 == len(self.Points) - 1:
                 # Calculate the direction from current point to end point
-                v_end = vector(self.Points[i], end)
+                v_end = tuple(map(round,vector(self.Points[i], end)))
                 # The current point is the first
                 if i == 0:
                     # If the end point is not in the start direction, a point is added
@@ -2199,7 +2200,7 @@
                             1,
                             DirectionChoice((self.Segments[0][1],
                                              self.Segments[0][0]),
-                                            vector(start, self.Points[1]),
+                                            tuple(map(round,vector(start, self.Points[1]))),
                                             self.Segments[1]))
                     else:
                         self.Points[1].x, self.Points[1].y = start.x, start.y
@@ -2286,8 +2287,8 @@
             # during a resize dragging
             for i, point in enumerate(self.RealPoints):
                 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
-                    point[0] = point[0] * width / max(lastwidth, 1)
-                    point[1] = point[1] * height / max(lastheight, 1)
+                    point[0] = int(point[0] * width / max(lastwidth, 1))
+                    point[1] = int(point[1] * height / max(lastheight, 1))
             # Calculate the correct position of the points from real points
             for i, point in enumerate(self.RealPoints):
                 if not (i == 0 and self.StartConnected) and not (i == len(self.Points) - 1 and self.EndConnected):
@@ -2671,9 +2672,9 @@
         if len(self.Points) > 0 and (not self.StartConnected or self.OverStart):
             dc.DrawCircle(round(self.Points[0].x * scalex),
                           round(self.Points[0].y * scaley),
-                          (POINT_RADIUS + 1) * scalex + 2)
+                          round((POINT_RADIUS + 1) * scalex + 2))
         if len(self.Points) > 1 and (not self.EndConnected or self.OverEnd):
-            dc.DrawCircle(self.Points[-1].x * scalex, self.Points[-1].y * scaley, (POINT_RADIUS + 1) * scalex + 2)
+            dc.DrawCircle(round(self.Points[-1].x * scalex), round(self.Points[-1].y * scaley), round((POINT_RADIUS + 1) * scalex + 2))
         # Draw the wire lines and the last point (it seems that DrawLines stop before the last point)
         if len(self.Points) > 1:
             points = [wx.Point(round((self.Points[0].x - self.Segments[0][0]) * scalex),
@@ -2922,12 +2923,12 @@
         dc.SetBrush(wx.Brush(HIGHLIGHTCOLOR))
         dc.SetLogicalFunction(wx.AND)
 
-        left = (self.Pos.x - 1) * scalex - 2
-        right = (self.Pos.x + self.Size[0] + 1) * scalex + 2
-        top = (self.Pos.y - 1) * scaley - 2
-        bottom = (self.Pos.y + self.Size[1] + 1) * scaley + 2
-        angle_top = (self.Pos.x + self.Size[0] - 9) * scalex + 2
-        angle_right = (self.Pos.y + 9) * scaley - 2
+        left = round((self.Pos.x - 1) * scalex - 2)
+        right = round((self.Pos.x + self.Size[0] + 1) * scalex + 2)
+        top = round((self.Pos.y - 1) * scaley - 2)
+        bottom = round((self.Pos.y + self.Size[1] + 1) * scaley + 2)
+        angle_top = round((self.Pos.x + self.Size[0] - 9) * scalex + 2)
+        angle_right = round((self.Pos.y + 9) * scaley - 2)
 
         polygon = [wx.Point(left, top), wx.Point(angle_top, top),
                    wx.Point(right, angle_right), wx.Point(right, bottom),
--- a/graphics/RubberBand.py	Wed Apr 12 19:28:37 2023 +0200
+++ b/graphics/RubberBand.py	Wed Apr 12 19:32:38 2023 +0200
@@ -168,8 +168,8 @@
         for bbox in bboxes:
             if bbox is not None:
                 dc.DrawRectangle(
-                    bbox.x * scalex, bbox.y * scaley,
-                    bbox.width * scalex, bbox.height * scaley)
+                    round(bbox.x * scalex), round(bbox.y * scaley),
+                    round(bbox.width * scalex), round(bbox.height * scaley))
 
         dc.SetLogicalFunction(wx.COPY)
 
--- a/plcopen/BlockInstanceCollector.py	Wed Apr 12 19:28:37 2023 +0200
+++ b/plcopen/BlockInstanceCollector.py	Wed Apr 12 19:32:38 2023 +0200
@@ -124,14 +124,14 @@
         self.SpecificValues = None
 
         self.CurrentInstance = _BlockInstanceInfos(
-            *(_translate_args([_StringValue, int] + [float] * 4, args) +
+            *(_translate_args([_StringValue, int] + [int] * 4, args) +
               [specific_values, [], []]))
 
         self.BlockInstances[self.CurrentInstance.id] = self.CurrentInstance
 
     def AddInstanceConnection(self, context, *args):
         connection_args = _translate_args(
-            [_StringValue] * 2 + [_BoolValue, _StringValue] + [float] * 2, args)
+            [_StringValue] * 2 + [_BoolValue, _StringValue] + [int] * 2, args)
 
         self.CurrentConnection = _InstanceConnectionInfos(
             *(connection_args[1:4] + [
@@ -152,7 +152,7 @@
 
     def AddLinkPoint(self, context, *args):
         self.CurrentLink.points.append(_Point(
-            *_translate_args([float] * 2, args)))
+            *_translate_args([int] * 2, args)))
 
     def AddAction(self, context, *args):
         if len(self.SpecificValues) == 0: