Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 03-18-2012, 12:06 PM   #1
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
Developing plugin to process notes from Sony PRS-T1: no module named

Hi all,

I'm developing a Calibe plugin to import/export notes from a Sony PRS-T1 device. My first goal is to be able to "merge" handwritten annotations with the original pdf, using the "cairo" and "rsvg" libraries.

The user interface and SQLite bits are in place, but I can't seem to do "import cairo" or "import rsvg" in my plugin, because Calibre will tell me:
Quote:
Traceback (most recent call last):
File "site-packages/calibre/gui2/ui.py", line 123, in __init__
File "site-packages/calibre/gui2/ui.py", line 137, in init_iaction
File "site-packages/calibre/customize/__init__.py", line 543, in load_actual_plugin
File "importlib/__init__.py", line 37, in import_module
File "site-packages/calibre/customize/zipplugin.py", line 150, in load_module
File "calibre_plugins.prst1_notes.ui", line 18, in <module>
File "site-packages/calibre/customize/zipplugin.py", line 150, in load_module
File "calibre_plugins.prst1_notes.main", line 27, in <module>
File "site-packages/calibre/customize/zipplugin.py", line 150, in load_module
File "calibre_plugins.prst1_notes.PRST1NotesPDFMergeInt erface", line 6, in <module>
ImportError: No module named cairo
However, the cairo and rsvg python libraries are in place on my system (Ubuntu 11.10), and working for other (standalone) Python applications.

I tried calibre-debug, same result:
Quote:
$ calibre-debug -c "import cairo"
Traceback (most recent call last):
File "site.py", line 58, in main
File "site-packages/calibre/debug.py", line 216, in main
File "<string>", line 1, in <module>
ImportError: No module named cairo
Am I overlooking something? I'm running Python 2.7.2.

Many thanks for your help!
sjvs is offline   Reply With Quote
Old 03-18-2012, 12:26 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre has its own private copy of python. You will need to include those packages in the zip file, or add the path to them explicitly to sys.path in your calibre plugin before trying to import. Note that if the packages contain sompiled code, then they cannot be imported from zip files, in which case you will have to add the path to them to sys.path.

Last edited by kovidgoyal; 03-18-2012 at 12:32 PM.
kovidgoyal is offline   Reply With Quote
 
Enthusiast
Old 03-18-2012, 12:35 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Also, rather than using rsvg to render svg you can simply use QSvgRenderer from PyQt.
kovidgoyal is offline   Reply With Quote
Old 03-18-2012, 12:36 PM   #4
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
I'm not sure whether distributing cairo and all of its dependencies with the plugin is a good idea...

On the other hand, including hard-coded paths in the plugin will limit portability to other distributions and platforms. Is there are more widely accepted and standardised way of doing this?

I'm new to Calibre plugin development and wouldn't want to invent the wheel twice!
sjvs is offline   Reply With Quote
Old 03-18-2012, 12:39 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It most definitely isn't a good idea WHat exactly are you trying to use cairo for? You might me able to do whatever it is with pypdf, poppler or podofo, all of which are distributed with calibre. And use Qt to render svg instead of rsvg, which is also distributed with calibre.
kovidgoyal is offline   Reply With Quote
Old 03-18-2012, 12:44 PM   #6
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
Excellent tips, I'll look into using those. Many thanks!
sjvs is offline   Reply With Quote
Old 03-18-2012, 01:12 PM   #7
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
Hmm... Seems like Poppler is not exactly what I'd call well-documented. I'm trying to get it to render on a QPainter instance, no luck so far... I could rasterise the SVG first, but that would be a waste of time, space and quality.

A hint anyone?
sjvs is offline   Reply With Quote
Old 03-18-2012, 11:42 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
IIRC okular uses the combination of poppler and Qt to render PDFs. Try a quick look through its source code.
kovidgoyal is offline   Reply With Quote
Old 03-23-2012, 09:11 PM   #9
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
The plugin (using QSvgRenderer and PyPdf) works on my machine, I'll be testing it on other platforms over the next couple of days. If all goes well, I'll publish the plugin early next week.

Currently, it's only capable of processing notes from (unscaled!) PDF books. I'm not quite sure what to do with EPUBs. First of all, I'd have to find out how EPUB scaling works on the reader. After that, I'd have to hook the plugin up to Calibre's EPUB conversion code in order to produce an output PDF.

Before I start digging through the Calibre source code looking for hints - which approach would you prefer:
1) convert both ebook and handwriting to PDF, merge into single PDF.
2) directly render handwriting on EPUB. I have no clue whatsoever how EPUB is structured, any clues?

Thanks!
sjvs is offline   Reply With Quote
Old 03-23-2012, 10:55 PM   #10
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
EPUB is just HTML. you can insert the SVG into the HTML directly. No need to render, and especially, no need to convert to PDF.
kovidgoyal is offline   Reply With Quote
Old 03-24-2012, 08:08 AM   #11
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
For some reason I was expecting something much more complicated than HTML. However, wouldn't the rendering of the EPUB heavily rely on the device (browser)? Especially when merging with an SVG of handwriting, it's important to have the text at a consistent position.

I'll look into this, but if you have any hints, tips or trips - feel free to let me know.
sjvs is offline   Reply With Quote
Old 03-24-2012, 08:45 AM   #12
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Pretty much all epub viewers (barring very few in marginal devices) are based on (somewhat modified) webkit engines, so there shouldn't be any problem with rendering them. Also SVG support is IIRC mandated by the EPUB spec. As for positioning them, that is a bigger issue. You can always just insert the svg has an inline <svg> tag at the start of the closest element to the annotation position. Anything more sophisticated will probably require support from the viewing application.
kovidgoyal is offline   Reply With Quote
Old 03-24-2012, 09:27 AM   #13
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
I like annotating books on my PRS-T1 with handwriting: underlining sentences, circling words, scribbling things in the margin. Based on your post, I think it will be virtually impossible to (a) reproduce the exact same rendering (zoom factor!) outside the ereader and (b) render handwriting at the correct location.

I'll give it a shot, but no high hopes...
sjvs is offline   Reply With Quote
Old 03-24-2012, 09:40 AM   #14
sjvs
Enthusiast
sjvs began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Mar 2012
Device: Sony PRS-T1
Oh, and I forgot to ask: it seems that the Poppler Python libraries are not shipped with Calibre, is this right? The source code only seems to contains references to Poppler in C++ parts (reflow.cpp and reflow.h), but I can't do "import poppler" in Python.

PyPDF is capable of processing (reading/writing) PDF files, but as far as I can see doesn't support rendering in a GUI. Although it's not essential, it would be nice to show the user a preview of what he/she is about to get.

Any hints on this? Or would you mind shipping the Poppler Python libraries with Calibre in future releases?
sjvs is offline   Reply With Quote
Old 03-24-2012, 10:28 AM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,125
Karma: 5381911
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
poppler is shipped with calibre, though not its GUI bindings. If you want to show the suer a PDF, simply save it as a file on the filesystem and use local_open(). Most computers have PDF reading software on them.
kovidgoyal is offline   Reply With Quote
Reply

Tags
cairo, import, prs-t1

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ImportError: No module named djvu canadianjameson Conversion 12 04-01-2012 11:23 PM
Calibre 0.8.36 - Linux Compile Error - No module named dateutil.parser jasn Calibre 2 01-21-2012 11:36 PM
Error on install: No module named PyQt4 good_man Calibre 4 02-18-2011 03:10 PM
ImportError: No module named profiles ould Calibre 11 02-28-2009 07:25 PM
ImportError: No module named pkg_resources erik80 Calibre 3 08-02-2008 09:33 AM


All times are GMT -4. The time now is 02:58 PM.


MobileRead.com is a privately owned, operated and funded community.