Quote:
Originally Posted by bluerfoot
It works perfectly, boy on a separate note I really need to learn python, I started learning perl but perhaps that is not the way to go...one last question...would it be possible to
a) make it open the table of contents expanded? as it is now it opens up just book title and you then have to open the book. kind of silly since you are already reading that book its like duh...why should I have to click it again?
Anyway great thanks...
|
I used to use perl for some heavy-duty text processing, and it's very good for that kind of work. Python, however, seems cleaner as a language, and I find it much easier to understand the code I wrote when I look at it again six months down the road.
As for your request, how about I tell you how to go about it, and you use it as an exercise in learning python? The extra button push doesn't bother me enough to make me want to put in the extra effort

. The place to add your code is in the method 'sonyfyTOC', just before the loop that starts inserting additional items. You want to check if the first 'navPoint' element has any other 'navPoint' siblings, and if it doesn't, you want to move all of its 'navPoint' children (and the '#text' nodes around them) up to be its siblings. To move each one in turn, use 'removeChild()' based on its current navPoint parent, and then 'insertChild()' based on the navMap parent. That probably sounds confusing, but if you unzip the original epub file and look at the 'OEBPS/toc.ncx' file, you'll see how the XML structure is laid out and it'll make more sense. The indenting will be wrong in the new TOC file, but that won't affect how it works in the e-reader. Go to
http://docs.python.org/library/xml.dom.html and look at the 'Node Objects' section to see how to manipulate the XML elements. I expect this would take about ten to twenty lines of code. (It's funny that the net result of all this will be to move one '</ncx:navPoint>' line in the file

)