5 |
5 |
6 """ |
6 """ |
7 Module implementing some graphical utility functions. |
7 Module implementing some graphical utility functions. |
8 """ |
8 """ |
9 |
9 |
|
10 |
10 class RecursionError(OverflowError, ValueError): |
11 class RecursionError(OverflowError, ValueError): |
11 """ |
12 """ |
12 Unable to calculate result because of recursive structure. |
13 Unable to calculate result because of recursive structure. |
13 """ |
14 """ |
14 |
15 |
15 def sort(nodes, routes, noRecursion = False): |
16 |
|
17 def sort(nodes, routes, noRecursion=False): |
16 """ |
18 """ |
17 Function to sort widgets topographically. |
19 Function to sort widgets topographically. |
18 |
20 |
19 Passed a list of nodes and a list of source, dest routes, it attempts |
21 Passed a list of nodes and a list of source, dest routes, it attempts |
20 to create a list of stages, where each sub list is one stage in a process. |
22 to create a list of stages, where each sub list is one stage in a process. |
40 if nodes and not stage: |
42 if nodes and not stage: |
41 # there is no element, which does not depend on some other element! |
43 # there is no element, which does not depend on some other element! |
42 stage.append(nodes[0]) |
44 stage.append(nodes[0]) |
43 |
45 |
44 taken.extend(stage) |
46 taken.extend(stage) |
45 nodes = list(filter(lambda x, l = stage: x not in l, nodes)) |
47 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
46 while nodes: |
48 while nodes: |
47 previousStageChildren = [] |
49 previousStageChildren = [] |
48 nodelen = len(nodes) |
50 nodelen = len(nodes) |
49 |
51 |
50 # second stage are those nodes, which are direct children of the first stage |
52 # second stage are those nodes, which are direct children of the first stage |
71 while remove in stage: |
73 while remove in stage: |
72 stage.remove(remove) |
74 stage.remove(remove) |
73 |
75 |
74 stages.append(stage) |
76 stages.append(stage) |
75 taken.extend(stage) |
77 taken.extend(stage) |
76 nodes = list(filter(lambda x, l = stage: x not in l, nodes)) |
78 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
77 if nodelen == len(nodes): |
79 if nodelen == len(nodes): |
78 if noRecursion: |
80 if noRecursion: |
79 raise RecursionError(nodes) |
81 raise RecursionError(nodes) |
80 else: |
82 else: |
81 stages.append(nodes[:]) |
83 stages.append(nodes[:]) |
82 nodes = [] |
84 nodes = [] |
83 |
85 |
84 return stages |
86 return stages |
85 |
87 |
|
88 |
86 def _buildChildrenLists(routes): |
89 def _buildChildrenLists(routes): |
87 """ |
90 """ |
88 Function to build up parent - child relationships. |
91 Function to build up parent - child relationships. |
89 |
92 |
90 Taken from Boa Constructor. |
93 Taken from Boa Constructor. |