eBooks and PyQt: a good match

I have been putting lots of love into Aranduka an eBook manager, (which is looking very good lately, thanks!), and I didn't want it to also be an eBook reader.

But then I thought... how hard can it be to read ePub? Well, it's freaking easy!

Here's a good start at stackoverflow.com but the short of it is... it's a zip with some XML in it.

One of those XML files tells you where things are, one of them is the TOC, the rest is just a small static collection of HTML/CSS/images.

So, here are the ingredients to roll-your-own ePub reader widget in 150 LOC:

  • Use python's zipfile library to avoid exploding the zip (that's lame)
  • Use Element Tree to parse said XML files.
  • Use PyQt's QtWebKit to display said collection of XML/CSS/Images
  • Use this recipe to make QtWebKit tell you when it wants something from the zipfile.

Plug some things to others, shake vigorously, and you end up with this:

Share photos on twitter with Twitpic

Here's the code (as of today) and the UI file you need.

Missing stuff:

  • It doesn't display the cover.
  • It only shows the top level of the table of contents.
  • I only tested it on two books ;-)
  • It sure can use a lot of refactoring!

Neither should be terribly hard to do.

Comments

Comments powered by Disqus