Help with debugging *please*
Normally, I don't ask for debugging help, but in writing a file picker, I've run into some bugs I can't seem to track down. The file picker is written to only allow the selection of directories, not of files, because I've written it for specific use in another project.
The first thing is with selections. If I select a folder and then close the folder TWO levels above it, I get an error. If I close the immediate parent folder, everything behaves as expected. This mystifies me, as everything is called recursively. The error does not appear if I haven't selected anything, which further confuses me, because the error appears somewhere that superficially has nothing to do with selection.
If you open two directories, and close them in the same order they were opened, a weird overlap occurs. If you close them in the opposite order they were opened, this does not happen
I'm most immediately concerned about the first issue. If anyone more experienced could devote a little bit of time to helping me, I'd be hugely appreciative.
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
except 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 a
should 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 lines
self.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.
Thanks a lot, @JonB. I'm on the bus home from school right now, as soon as I get home I'll try this. (my phone is iPhone 4/ios7 and therefore not beta-compatible.)
This fixes issue 1, not issue 2. Thanks for your help anyway.
I will also mention... it is a little strange to add/remove subviews inside draw(). You have to be a little careful, because I think draw can be called when you do not expect, such as when rotating, etc. It might be better to rename the function you call internally, and have that called once at the top level. I have not looked at problem 2 so not sure if that is happening here.
Comments at the bottom of the gist.