2.2.11. Limiting Recursion in Trees with Loops (layout.managers.recursion
)¶
-
class
layout.managers.recursion.
RecursionStopperLM
(recursion_limit=2, element=None)¶ Bases:
layout.managers.root.LayoutManager
Because you can arrange the layout tree in any way you choose, it is possible to create circular loops in the tree which would lead to infinite loops in the code. Loops normally indicate that your code has a bug, but sometimes you do want the loop. In this case, adding this class somewhere in the loop prevents the loop from recursing more than a specified number of times.
If the loop hasn’t reached its maximum number of iterations, this class acts as if it isn’t there: it passes all calls onto its child element. Otherwise it will act as if it were a zero sized element that has no visual effect.
Note that this class uses the data object passed in to hold its recursion count, in particular in a field called ‘recusion_stopper_count’. It cleans up after itself, so you shouldn’t need to worry about clearing the value after you’ve run the layout (if you want to render again using the same data object, for example). But you shouldn’t mess with that value yourself.
-
get_minimum_size
(data)¶ How small can the element be? Should return a Point.
-
render
(rect, data)¶ Asks the element to render itself.
-