--- a/IDEFrame.py Fri Oct 28 15:19:24 2022 +0800
+++ b/IDEFrame.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key @@ -155,7 +157,8 @@
if tab["pos"][0] == rect.x:
others = [t for t in tabs if t != tab]
- others.sort(lambda x, y: cmp(x["pos"][0], y["pos"][0]))
+ others.sort(key=cmp_to_key(lambda x, y: eq(x["pos"][0], if other["pos"][1] == tab["pos"][1] and \
other["size"][1] == tab["size"][1] and \
@@ -170,7 +173,8 @@
elif tab["pos"][1] == rect.y:
others = [t for t in tabs if t != tab]
- others.sort(lambda x, y: cmp(x["pos"][1], y["pos"][1]))
+ others.sort(key=cmp_to_key(lambda x, y: eq(x["pos"][1], if other["pos"][0] == tab["pos"][0] and \
other["size"][0] == tab["size"][0] and \
@@ -807,7 +811,7 @@
if tab_infos is not None:
tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
- tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
+ tabs.sort(key=cmp_to_key(lambda x, y: eq(x["pos"], y["pos"]))) size = notebook.GetSize()
return ComputeTabsLayout(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
--- a/PLCGenerator.py Fri Oct 28 15:19:24 2022 +0800
+++ b/PLCGenerator.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key from functools import reduce
@@ -77,9 +79,9 @@
ax, ay = int(a.getx()), int(a.gety())
bx, by = int(b.getx()), int(b.gety())
def JoinList(separator, mylist):
@@ -993,9 +995,9 @@
otherInstances["connectors"].append(instance)
elif isinstance(instance, CoilClass):
otherInstances["outVariables&coils"].append(instance)
- orderedInstances.sort()
- otherInstances["outVariables&coils"].sort(SortInstances)
- otherInstances["blocks"].sort(SortInstances)
+ orderedInstances.sort(key=lambda n: n[0]) + otherInstances["outVariables&coils"].sort(key=cmp_to_key(SortInstances)) + otherInstances["blocks"].sort(key=cmp_to_key(SortInstances)) instances = [instance for (executionOrderId, instance) in orderedInstances]
instances.extend(otherInstances["outVariables&coils"] + otherInstances["blocks"] + otherInstances["connectors"])
for instance in instances:
--- a/controls/FolderTree.py Fri Oct 28 15:19:24 2022 +0800
+++ b/controls/FolderTree.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key @@ -34,7 +36,7 @@
@@ -135,7 +137,7 @@
os.path.splitext(filename)[1] == self.CurrentFilter):
items.append((filename, FILE, None))
- items.sort(sort_folder)
+ items.sort(key=cmp_to_key(sort_folder)) def SetFilter(self, filter):
--- a/controls/IDBrowser.py Fri Oct 28 15:19:24 2022 +0800
+++ b/controls/IDBrowser.py Fri Oct 28 17:01:10 2022 +0800
@@ -4,6 +4,7 @@
# See COPYING file for copyrights details.
import PSKManagement as PSK
@@ -43,9 +44,9 @@
row1 = self.GetRow(item1)
row2 = self.GetRow(item2)
- return cmp(int(self.data[row1][col]), int(self.data[row2][col]))
+ return eq(int(self.data[row1][col]), int(self.data[row2][col])) - return cmp(self.data[row1][col], self.data[row2][col])
+ return eq(self.data[row1][col], self.data[row2][col]) def DeleteRows(self, rows):
--- a/controls/LogViewer.py Fri Oct 28 15:19:24 2022 +0800
+++ b/controls/LogViewer.py Fri Oct 28 17:01:10 2022 +0800
@@ -24,6 +24,7 @@
from datetime import datetime
from time import time as gettime
from weakref import proxy
@@ -241,8 +242,8 @@
def __cmp__(self, other):
if self.Date == other.Date:
- return cmp(self.Seconds, other.Seconds)
- return cmp(self.Date, other.Date)
+ return eq(self.Seconds, other.Seconds) + return eq(self.Date, other.Date) date = self.Date.replace(second=int(self.Seconds))
--- a/editors/Viewer.py Fri Oct 28 15:19:24 2022 +0800
+++ b/editors/Viewer.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key from time import time as gettime
from threading import Lock
@@ -223,9 +225,9 @@
x1, y1 = block_infos1[0].GetPosition()
x2, y2 = block_infos2[0].GetPosition()
# -------------------------------------------------------------------------------
# Graphic elements Viewer base class
@@ -920,11 +922,13 @@
wires = list(self.Wires.keys())
comments = list(self.Comments.values())
- blocks.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
+ blocks.sort(key=cmp_to_key(lambda x, y: eq(x.GetId(), y.GetId()))) - wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y]))
+ wires.sort(key=cmp_to_key(lambda x, y: eq(self.Wires[x], - comments.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
+ comments.sort(key=cmp_to_key(lambda x, y: eq(x.GetId(), return blocks + wires + comments
def GetContinuationByName(self, name):
@@ -3509,7 +3513,7 @@
block = self.Blocks.get(infos[2])
blocks.append((block, (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)))
- blocks.sort(sort_blocks)
+ blocks.sort(key=cmp_to_key(sort_blocks)) self.SearchResults.extend([infos for block, infos in blocks])
self.CurrentFindHighlight = None
--- a/graphics/GraphicCommons.py Fri Oct 28 15:19:24 2022 +0800
+++ b/graphics/GraphicCommons.py Fri Oct 28 17:01:10 2022 +0800
@@ -294,7 +294,7 @@
distances.append((sqrt((self.Pos.x + connector_pos.x - position.x) ** 2 +
(self.Pos.y + connector_pos.y - position.y) ** 2),
+ distances.sort(key=lambda n: n[0]) --- a/graphics/LD_Objects.py Fri Oct 28 15:19:24 2022 +0800
+++ b/graphics/LD_Objects.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key from graphics.GraphicCommons import *
@@ -157,7 +159,7 @@
for connect in self.Connectors:
connect_pos = connect.GetRelPosition()
connect.SetPosition(wx.Point(connect_pos.x, connect_pos.y - miny))
- self.Connectors.sort(lambda x, y: cmp(x.Pos.y, y.Pos.y))
+ self.Connectors.sort(key=cmp_to_key(lambda x, y: eq(x.Pos.y, y.Pos.y))) for connect in self.Connectors:
connect_pos = connect.GetRelPosition()
--- a/graphics/SFC_Objects.py Fri Oct 28 15:19:24 2022 +0800
+++ b/graphics/SFC_Objects.py Fri Oct 28 17:01:10 2022 +0800
@@ -23,6 +23,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+from functools import cmp_to_key from graphics.GraphicCommons import *
@@ -1239,8 +1241,8 @@
for output in self.Outputs:
output_pos = output.GetRelPosition()
output.SetPosition(wx.Point(output_pos.x - minx, output_pos.y))
- self.Inputs.sort(lambda x, y: cmp(x.Pos.x, y.Pos.x))
- self.Outputs.sort(lambda x, y: cmp(x.Pos.x, y.Pos.x))
+ self.Inputs.sort(key=cmp_to_key(lambda x, y: eq(x.Pos.y, y.Pos.y))) + self.Outputs.sort(key=cmp_to_key(lambda x, y: eq(x.Pos.y, y.Pos.y))) self.Size[0] = maxx - minx
connector.MoveConnected()