13 |
13 |
14 class RecursionError(OverflowError, ValueError): |
14 class RecursionError(OverflowError, ValueError): |
15 """ |
15 """ |
16 Unable to calculate result because of recursive structure. |
16 Unable to calculate result because of recursive structure. |
17 """ |
17 """ |
18 |
18 pass |
|
19 |
19 |
20 |
20 def sort(nodes, routes, noRecursion=False): |
21 def sort(nodes, routes, noRecursion=False): |
21 """ |
22 """ |
22 Function to sort widgets topographically. |
23 Function to sort widgets topographically. |
23 |
24 |
50 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
51 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
51 while nodes: |
52 while nodes: |
52 previousStageChildren = [] |
53 previousStageChildren = [] |
53 nodelen = len(nodes) |
54 nodelen = len(nodes) |
54 |
55 |
55 # second stage are those nodes, which are direct children of the first stage |
56 # second stage are those nodes, which are direct children of the |
|
57 # first stage |
56 for node in stage: |
58 for node in stage: |
57 for child in children.get(node, []): |
59 for child in children.get(node, []): |
58 if child not in previousStageChildren and child not in taken: |
60 if child not in previousStageChildren and child not in taken: |
59 previousStageChildren.append(child) |
61 previousStageChildren.append(child) |
60 elif child in taken and noRecursion: |
62 elif child in taken and noRecursion: |