Download calibre User Manual Release 2.7.0 Kovid Goyal

Transcript
calibre User Manual, Release 2.7.0
calibre-customize -b .
Note:
On OS X, the command line tools are inside the calibre bundle,
ample,
if you installed calibre in /Applications the command line tools
/Applications/calibre.app/Contents/console.app/Contents/MacOS/.
for exare in
You can download the Hello World plugin from helloworld_plugin.zip96 .
Every time you use calibre to convert a book, the plugin’s run() method will be called and the converted book will
have its publisher set to “Hello World”. This is a trivial plugin, lets move on to a more complex example that actually
adds a component to the user interface.
A User Interface plugin
This plugin will be spread over a few files (to keep the code clean). It will show you how to get resources (images
or data files) from the plugin zip file, allow users to configure your plugin, how to create elements in the calibre user
interface and how to access and query the books database in calibre.
You can download this plugin from interface_demo_plugin.zip97 The first thing to note is that this zip file has a lot
more files in it, explained below, pay particular attention to plugin-import-name-interface_demo.txt.
plugin-import-name-interface_demo.txt An empty text file used to enable the multi-file plugin magic.
This file must be present in all plugins that use more than one .py file. It should be empty and its
filename must be of the form: plugin-import-name-some_name.txt The presence of this file allows
you to import code from the .py files present inside the zip file, using a statement like:
from calibre_plugins.some_name.some_module import some_object
The prefix calibre_plugins must always be present. some_name comes from the filename
of the empty text file. some_module refers to some_module.py file inside the zip file. Note
that this importing is just as powerful as regular python imports. You can create packages and
subpackages of .py modules inside the zip file, just like you would normally (by defining __init__.py
in each sub directory), and everything should Just Work.
The name you use for some_name enters a global namespace shared by all plugins, so make it as
unique as possible. But remember that it must be a valid python identifier (only alphabets, numbers
and the underscore).
__init__.py As before, the file that defines the plugin class
main.py This file contains the actual code that does something useful
ui.py This file defines the interface part of the plugin
images/icon.png The icon for this plugin
about.txt A text file with information about the plugin
translations A folder containing .mo files with the translations of the user interface of your plugin into
different languages. See below for details.
Now let’s look at the code.
96 http://calibre-ebook.com/downloads/helloworld_plugin.zip
97 http://calibre-ebook.com/downloads/interface_demo_plugin.zip
1.9. Tutorials
199