The first problem occurs whether or not anything is selected.
You will find debugging ui's much easier if you present to a panel, to allow you to run pdb in the console on a live view.
Also, simply use raise, rather than raise e, as that will preserve the stacktrace.except AttributeError: raise
instead ofexcept AttributeError,e: raise e
(there are ways to use sys.exec_info, and the other raise arguments to prserve stacktrace, but i find plain raise usually works just fine)
Then once you get an error, switch to the console and use a
import pdb; pdb.pm(). That shows the error occurs in draw, because the innermost path had no superview.
Here is a contrived case with three folders, a contains b contains c. I started the filenav at a. I added some prints to monitor open, draw, collapse. Here is the sequence of calls after expanding all, then collapsing ashould collapse a should collapse a/b should collapse a/b/c collapse a/b removing subview a/b/c collapse a removing subview a/b draw a/b/c
pdb tells me that the final draw, where the error occurs, is called from should_collapse of a. So, a thinks a/b/c is still below, even though it was removed when a/b was collapsed. Moving the two linesself.above = [x for x in self.superview.subviews if x.y < self.y] self.below = [x for x in self.superview.subviews if x.y > self.y]
until after the for sd in self.children loop fixes this error. I suspect this may explain the overlap issue if you do the same in should_open.