21 # You should have received a copy of the GNU General Public License |
21 # You should have received a copy of the GNU General Public License |
22 # along with this program; if not, write to the Free Software |
22 # along with this program; if not, write to the Free Software |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
|
26 from functools import cmp_to_key |
|
27 from operator import eq |
26 import math |
28 import math |
27 from time import time as gettime |
29 from time import time as gettime |
28 from threading import Lock |
30 from threading import Lock |
29 |
31 |
30 import wx |
32 import wx |
221 |
223 |
222 def sort_blocks(block_infos1, block_infos2): |
224 def sort_blocks(block_infos1, block_infos2): |
223 x1, y1 = block_infos1[0].GetPosition() |
225 x1, y1 = block_infos1[0].GetPosition() |
224 x2, y2 = block_infos2[0].GetPosition() |
226 x2, y2 = block_infos2[0].GetPosition() |
225 if y1 == y2: |
227 if y1 == y2: |
226 return cmp(x1, x2) |
228 return eq(x1, x2) |
227 else: |
229 else: |
228 return cmp(y1, y2) |
230 return eq(y1, y2) |
229 |
231 |
230 # ------------------------------------------------------------------------------- |
232 # ------------------------------------------------------------------------------- |
231 # Graphic elements Viewer base class |
233 # Graphic elements Viewer base class |
232 # ------------------------------------------------------------------------------- |
234 # ------------------------------------------------------------------------------- |
233 |
235 |
918 def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False): |
920 def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False): |
919 blocks = list(self.Blocks.values()) |
921 blocks = list(self.Blocks.values()) |
920 wires = list(self.Wires.keys()) |
922 wires = list(self.Wires.keys()) |
921 comments = list(self.Comments.values()) |
923 comments = list(self.Comments.values()) |
922 if sort_blocks: |
924 if sort_blocks: |
923 blocks.sort(lambda x, y: cmp(x.GetId(), y.GetId())) |
925 blocks.sort(key=cmp_to_key(lambda x, y: eq(x.GetId(), y.GetId()))) |
924 if sort_wires: |
926 if sort_wires: |
925 wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y])) |
927 wires.sort(key=cmp_to_key(lambda x, y: eq(self.Wires[x], |
|
928 self.Wires[y]))) |
926 if sort_comments: |
929 if sort_comments: |
927 comments.sort(lambda x, y: cmp(x.GetId(), y.GetId())) |
930 comments.sort(key=cmp_to_key(lambda x, y: eq(x.GetId(), |
|
931 y.GetId()))) |
928 return blocks + wires + comments |
932 return blocks + wires + comments |
929 |
933 |
930 def GetContinuationByName(self, name): |
934 def GetContinuationByName(self, name): |
931 blocks = [] |
935 blocks = [] |
932 for block in self.Blocks.values(): |
936 for block in self.Blocks.values(): |
3507 self.SearchResults.append((infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)) |
3511 self.SearchResults.append((infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT)) |
3508 else: |
3512 else: |
3509 block = self.Blocks.get(infos[2]) |
3513 block = self.Blocks.get(infos[2]) |
3510 if block is not None: |
3514 if block is not None: |
3511 blocks.append((block, (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT))) |
3515 blocks.append((block, (infos[1:], start, end, SEARCH_RESULT_HIGHLIGHT))) |
3512 blocks.sort(sort_blocks) |
3516 blocks.sort(key=cmp_to_key(sort_blocks)) |
3513 self.SearchResults.extend([infos for block, infos in blocks]) |
3517 self.SearchResults.extend([infos for block, infos in blocks]) |
3514 self.CurrentFindHighlight = None |
3518 self.CurrentFindHighlight = None |
3515 |
3519 |
3516 if len(self.SearchResults) > 0: |
3520 if len(self.SearchResults) > 0: |
3517 if self.CurrentFindHighlight is not None: |
3521 if self.CurrentFindHighlight is not None: |