--- author: '' category: '' date: 2010/09/23 22:33 description: '' link: '' priority: '' slug: BB919 tags: programming, pyqt, python, qt title: 'eBooks and PyQt: a good match' type: text updated: 2010/09/23 22:33 url_type: '' --- 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: .. raw:: html 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.