Defines various abstract base classes that can be subclassed to create powerful plugins. The useful classes are:
A calibre plugin. Useful members include:
- self.plugin_path: Stores path to the zip file that contains
this plugin or None if it is a builtin plugin
- self.site_customization: Stores a customization string entered
by the user.
Methods that should be overridden in sub classes:
Useful methods:
List of platforms this plugin works on For example: ['windows', 'osx', 'linux']
The name of this plugin. You must set it something other than Trivial Plugin for it to work.
The version of this plugin as a 3-tuple (major, minor, revision)
A short string describing what this plugin does
The author of this plugin
When more than one plugin exists for a filetype, the plugins are run in order of decreasing priority i.e. plugins with higher priority will be run first. The highest possible priority is sys.maxint. Default priority is 1.
The earliest version of calibre this plugin requires
If False, the user will not be able to disable this plugin. Use with care.
The type of this plugin. Used for categorizing plugins in the GUI
Called once when calibre plugins are initialized. Plugins are re-initialized every time a new plugin is added.
Perform any plugin specific initialization here, such as extracting resources from the plugin zip file. The path to the zip file is available as self.plugin_path.
Note that self.site_customization is not available at this point.
Implement this method and save_settings() in your plugin to use a custom configuration dialog, rather then relying on the simple string based default customization.
This method, if implemented, must return a QWidget. The widget can have an optional method validate() that takes no arguments and is called immediately after the user clicks OK. Changes are applied if and only if the method returns True.
If for some reason you cannot perform the configuration at this time, return a tuple of two strings (message, details), these will be displayed as a warning dialog to the user and the process will be aborted.
Save the settings specified by the user with config_widget.
| Parameters: | config_widget – The widget returned by config_widget(). |
|---|
This method shows a configuration dialog for this plugin. It returns True if the user clicks OK, False otherwise. The changes are automatically applied.
If this plugin comes in a ZIP file (user added plugin), this method will allow you to load resources from the ZIP file.
For example to load an image:
pixmap = QPixmap()
pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
icon = QIcon(pixmap)
| Parameters: | names – List of paths to resources in the zip file using / as separator |
|---|---|
| Returns: | A dictionary of the form {name : file_contents}. Any names that were not found in the zip file will not be present in the dictionary. |
Return a string giving help on how to customize this plugin. By default raise a NotImplementedError, which indicates that the plugin does not require customization.
If you re-implement this method in your subclass, the user will be asked to enter a string as customization for this plugin. The customization string will be available as self.site_customization.
Site customization could be anything, for example, the path to a needed binary on the user’s computer.
| Parameters: | gui – If True return HTML help, otherwise return plain text help. |
|---|
Return a file-like object that is a temporary file on the file system. This file will remain available even after being closed and will only be removed on interpreter shutdown. Use the name member of the returned object to access the full path to the created temporary file.
| Parameters: | suffix – The suffix that the temporary file will have. |
|---|
Bases: calibre.customize.Plugin
A plugin that is associated with a particular set of file types.
Set of file types for which this plugin should be run For example: set(['lit', 'mobi', 'prc'])
If True, this plugin is run when books are added to the database
If True, this plugin is run after books are added to the database
If True, this plugin is run just before a conversion
If True, this plugin is run after conversion on the final file produced by the conversion output plugin.
Run the plugin. Must be implemented in subclasses. It should perform whatever modifications are required on the ebook and return the absolute path to the modified ebook. If no modifications are needed, it should return the path to the original ebook. If an error is encountered it should raise an Exception. The default implementation simply return the path to the original ebook.
The modified ebook file should be created with the temporary_file() method.
| Parameters: | path_to_ebook – Absolute path to the ebook. |
|---|---|
| Returns: | Absolute path to the modified ebook. |
Bases: calibre.customize.Plugin
A plugin that implements reading metadata from a set of file types.
Set of file types for which this plugin should be run For example: set(['lit', 'mobi', 'prc'])
Return metadata for the file represented by stream (a file like object that supports reading). Raise an exception when there is an error with the input data. :param type: The type of file. Guaranteed to be one of the entries in file_types. :return: A calibre.ebooks.metadata.book.Metadata object
Bases: calibre.customize.Plugin
A plugin that implements reading metadata from a set of file types.
Set of file types for which this plugin should be run For example: set(['lit', 'mobi', 'prc'])
Set metadata for the file represented by stream (a file like object that supports reading). Raise an exception when there is an error with the input data. :param type: The type of file. Guaranteed to be one of the entries in file_types. :param mi: A calibre.ebooks.metadata.book.Metadata object
Bases: calibre.customize.Plugin
A plugin that implements a catalog generator.
Output file type for which this plugin should be run For example: ‘epub’ or ‘xml’
CLI parser options specific to this plugin, declared as namedtuple Option:
from collections import namedtuple
Option = namedtuple('Option', 'option, default, dest, help')
cli_options = [Option('--catalog-title',
default = 'My Catalog',
dest = 'catalog_title',
help = (_('Title of generated catalog. \nDefault:') + " '" +
'%default' + "'"))]
cli_options parsed in library.cli:catalog_option_parser()
If plugin is not a built-in, copy the plugin’s .ui and .py files from the zip file to $TMPDIR. Tab will be dynamically generated and added to the Catalog Options dialog in calibre.gui2.dialogs.catalog.py:Catalog
Run the plugin. Must be implemented in subclasses. It should generate the catalog in the format specified in file_types, returning the absolute path to the generated catalog file. If an error is encountered it should raise an Exception.
The generated catalog file should be created with the temporary_file() method.
| Parameters: |
|
|---|
Bases: calibre.customize.Plugin
Set of capabilities supported by this plugin. Useful capabilities are: ‘identify’, ‘cover’
List of metadata fields that can potentially be download by this plugin during the identify phase
Set this to True if your plugin returns HTML formatted comments
Setting this to True means that the browser object will add Accept-Encoding: gzip to all requests. This can speedup downloads but make sure that the source actually supports gzip transfer encoding correctly first
Cached cover URLs can sometimes be unreliable (i.e. the download could fail or the returned image could be bogus. If that is often the case with this source set to False
A list of Option objects. They will be used to automatically construct the configuration widget for this plugin
A string that is displayed at the top of the config widget for this plugin
If True this source can return multiple covers for a given query
Return False if your plugin needs to be configured before it can be used. For example, it might need a username/password/API key.
Take a list of authors and return a list of tokens useful for an AND search query. This function tries to return tokens in first name middle names last name order, by assuming that if a comma is in the author name, the name is in lastname, other names form.
Take a title and return a list of tokens useful for an AND search query. Excludes connectives(optionally) and punctuation.
Return the first field from self.touched_fields that is null on the mi object
Call this method in your plugin’s identify method to normalize metadata before putting the Metadata object into result_queue. You can of course, use a custom algorithm suited to your metadata source.
Return a 3-tuple or None. The 3-tuple is of the form: (identifier_type, identifier_value, URL). The URL is the URL for the book identified by identifiers at this source. identifier_type, identifier_value specify the identifier corresponding to the URL. This URL must be browseable to by a human using a browser. It is meant to provide a clickable link for the user to easily visit the books page at this source. If no URL is found, return None. This method must be quick, and consistent, so only implement it if it is possible to construct the URL from a known scheme given identifiers.
Return a human readable name from the return value of get_book_url().
Return cached cover URL for the book identified by the identifiers dict or None if no such URL exists.
Note that this method must only return validated URLs, i.e. not URLS that could result in a generic cover image or a not found error.
Return a function that is used to generate a key that can sort Metadata objects by their relevance given a search query (title, authors, identifiers).
These keys are used to sort the results of a call to identify().
For details on the default algorithm see InternalMetadataCompareKeyGen. Re-implement this function in your plugin if the default algorithm is not suitable.
Identify a book by its title/author/isbn/etc.
If identifiers(s) are specified and no match is found and this metadata source does not store all related identifiers (for example, all ISBNs of a book), this method should retry with just the title and author (assuming they were specified).
If this metadata source also provides covers, the URL to the cover should be cached so that a subsequent call to the get covers API with the same ISBN/special identifier does not need to get the cover URL again. Use the caching API for this.
Every Metadata object put into result_queue by this method must have a source_relevance attribute that is an integer indicating the order in which the results were returned by the metadata source for this query. This integer will be used by compare_identify_results(). If the order is unimportant, set it to zero for every result.
Make sure that any cover/isbn mapping information is cached before the Metadata object is put into result_queue.
| Parameters: |
|
|---|---|
| Returns: | None if no errors occurred, otherwise a unicode representation of the error suitable for showing to the user |
Download a cover and put it into result_queue. The parameters all have the same meaning as for identify(). Put (self, cover_data) into result_queue.
This method should use cached cover URLs for efficiency whenever possible. When cached data is not present, most plugins simply call identify and use its results.
If the parameter get_best_cover is True and this plugin can get multiple covers, it should only get the “best” one.
Generate a sort key for comparison of the relevance of Metadata objects, given a search query. This is used only to compare results from the same metadata source, not across different sources.
The sort key ensures that an ascending order sort is a sort by order of decreasing relevance.
The algorithm is:
Prefer results that have the same ISBN as specified in the query
Prefer results with a cached cover URL
Prefer results with all available fields filled in
Prefer results that are an exact title match to the query
Prefer results with longer comments (greater than 10% longer)
- Use the relevance of the result as reported by the metadata source’s search
engine
Bases: calibre.customize.Plugin
InputFormatPlugins are responsible for converting a document into HTML+OPF+CSS+etc. The results of the conversion must be encoded in UTF-8. The main action happens in convert().
Set of file types for which this plugin should be run For example: set(['azw', 'mobi', 'prc'])
If True, this input plugin generates a collection of images, one per HTML file. You can obtain access to the images via convenience method, get_image_collection().
Number of CPU cores used by this plugin A value of -1 means that it uses all available cores
If set to True, the input plugin will perform special processing to make its output suitable for viewing
The encoding that this input plugin creates files in. A value of None means that the encoding is undefined and must be detected individually
Options shared by all Input format plugins. Do not override in sub-classes. Use options instead. Every option must be an instance of OptionRecommendation.
Options to customize the behavior of this plugin. Every option must be an instance of OptionRecommendation.
A set of 3-tuples of the form (option_name, recommended_value, recommendation_level)
Return a list of absolute paths to the images, if this input plugin represents an image collection. The list of images is in the same order as the spine and the TOC.
This method must be implemented in sub-classes. It must return the path to the created OPF file or an OEBBook instance. All output should be contained in the current directory. If this plugin creates files outside the current directory they must be deleted/marked for deletion before this method returns.
| Parameters: |
|
|---|
Called to allow the input plugin to perform postprocessing after the book has been parsed.
Bases: calibre.customize.Plugin
OutputFormatPlugins are responsible for converting an OEB document (OPF+HTML) into an output ebook.
The OEB document can be assumed to be encoded in UTF-8. The main action happens in convert().
The file type (extension without leading period) that this plugin outputs
Options shared by all Input format plugins. Do not override in sub-classes. Use options instead. Every option must be an instance of OptionRecommendation.
Options to customize the behavior of this plugin. Every option must be an instance of OptionRecommendation.
A set of 3-tuples of the form (option_name, recommended_value, recommendation_level)
Render the contents of oeb_book (which is an instance of calibre.ebooks.oeb.OEBBook to the file specified by output.
| Parameters: |
|
|---|
Can be used to make changes to the css during the CSS flattening process.
| Parameters: |
|
|---|
The base class for all device drivers is DevicePlugin. However, if your device exposes itself as a USBMS drive to the operating system, you should use the USBMS class instead as it implements all the logic needed to support these kinds of devices.
Bases: calibre.customize.Plugin
Defines the interface that should be implemented by backends that communicate with an ebook reader.
Ordered list of supported formats
VENDOR_ID can be either an integer, a list of integers or a dictionary If it is a dictionary, it must be a dictionary of dictionaries, of the form:
{
integer_vendor_id : { product_id : [list of BCDs], ... },
...
}
An integer or a list of integers
BCD can be either None to not distinguish between devices based on BCD, or it can be a list of the BCD numbers of all devices supported by this driver.
Height for thumbnails on the device
Width for thumbnails on the device. Setting this will force thumbnails to this size, not preserving aspect ratio. If it is not set, then the aspect ratio will be preserved and the thumbnail will be no higher than THUMBNAIL_HEIGHT Set this to True if the device supports updating cover thumbnails during sync_booklists. Setting it to true will ask device.py to refresh the cover thumbnails during book matching
Whether the metadata on books can be set via the GUI.
Whether the device can handle device_db metadata plugboards
Path separator for paths to books on device
Icon for this device
alias of Annotation
GUI displays this as a message if not None. Useful if opening can take a long time
Set of extensions that are “virtual books” on the device and therefore cannot be viewed/saved/added to library For example: frozenset(['kobo'])
Whether to nuke comments in the copy of the book sent to the device. If not None this should be short string that the comments will be replaced by.
If True indicates that this driver completely manages device detection, ejecting and so forth. If you set this to True, you must implement the detect_managed_devices and debug_managed_device_detection methods. A driver with this set to true is responsible for detection of devices, managing a blacklist of devices, a list of ejected devices and so forth. calibre will periodically call the detect_managed_devices() method and is it returns a detected device, calibre will call open(). open() will be called every time a device is returned even is previous calls to open() failed, therefore the driver must maintain its own blacklist of failed devices. Similarly, when ejecting, calibre will call eject() and then assuming the next call to detect_managed_devices() returns None, it will call post_yank_cleanup().
If set the True, calibre will call the get_driveinfo() method after the books lists have been loaded to get the driveinfo.
If set to True, calibre will ask the user if they want to manage the device with calibre, the first time it is detected. If you set this to True you must implement get_device_uid() and ignore_connected_device() and get_user_blacklisted_devices() and set_user_blacklisted_devices()
Set this to a dictionary of the form {‘title’:title, ‘msg’:msg, ‘det_msg’:detailed_msg} to have calibre popup a message to the user after some callbacks are run (currently only upload_books). Be careful to not spam the user with too many messages. This variable is checked after every callback, so only set it when you really need to.
Return True, device_info if a device handled by this plugin is currently connected.
| Parameters: | devices_on_system – List of devices currently connected |
|---|
Called only if MANAGES_DEVICE_PRESENCE is True.
Scan for devices that this driver can handle. Should return a device object if a device is found. This object will be passed to the open() method as the connected_device. If no device is found, return None. The returned object can be anything, calibre does not use it, it is only passed to open().
This method is called periodically by the GUI, so make sure it is not too resource intensive. Use a cache to avoid repeatedly scanning the system.
| Parameters: |
|
|---|
Called only if MANAGES_DEVICE_PRESENCE is True.
Should write information about the devices detected on the system to output, which is a file like object.
Should return True if a device was detected and successfully opened, otherwise False.
| Parameters: |
|
|---|
Optional method to perform further checks on a device to see if this driver is capable of handling it. If it is not it should return False. This method is only called after the vendor, product ids and the bcd have matched, so it can do some relatively time intensive checks. The default implementation returns True. This method is called only on windows. See also can_handle().
| Parameters: | device_info – On windows a device ID string. On Unix a tuple of (vendor_id, product_id, bcd). |
|---|
Unix version of can_handle_windows()
| Parameters: | device_info – Is a tuple of (vid, pid, bcd, manufacturer, product, serial number) |
|---|
Perform any device specific initialization. Called after the device is detected but before any other functions that communicate with the device. For example: For devices that present themselves as USB Mass storage devices, this method would be responsible for mounting the device or if the device has been automounted, for finding out where it has been mounted. The method calibre.devices.usbms.device.Device.open() has an implementation of this function that should serve as a good example for USB Mass storage devices.
This method can raise an OpenFeedback exception to display a message to the user.
| Parameters: |
|
|---|
Un-mount / eject the device from the OS. This does not check if there are pending GUI jobs that need to communicate with the device.
NOTE: That this method may not be called on the same thread as the rest of the device methods.
Set a function to report progress information.
| Parameters: | report_progress – Function that is called with a % progress (number between 0 and 100) for various tasks If it is called with -1 that means that the task does not have any progress information |
|---|
Ask device for device information. See L{DeviceInfoQuery}.
| Returns: | (device name, device version, software version on device, mime type) The tuple can optionally have a fifth element, which is a drive information dictionary. See usbms.driver for an example. |
|---|
Return the driveinfo dictionary. Usually called from get_device_information(), but if loading the driveinfo is slow for this driver, then it should set SLOW_DRIVEINFO. In this case, this method will be called by calibre after the book lists have been loaded. Note that it is not called on the device thread, so the driver should cache the drive info in the books() method and this function should return the cached data.
Return a 2 element list of the prefix to paths on the cards. If no card is present None is set for the card’s prefix. E.G. (‘/place’, ‘/place2’) (None, ‘place2’) (‘place’, None) (None, None)
| Returns: | A 3 element list with total space in bytes of (1, 2, 3). If a particular device doesn’t have any of these locations it should return 0. |
|---|
| Returns: | A 3 element list with free space in bytes of (1, 2, 3). If a particular device doesn’t have any of these locations it should return -1. |
|---|
Return a list of ebooks on the device.
| Parameters: | oncard – If ‘carda’ or ‘cardb’ return a list of ebooks on the specific storage card, otherwise return list of ebooks in main memory of device. If a card is specified and no books are on the card return empty list. |
|---|---|
| Returns: | A BookList. |
Upload a list of books to the device. If a file already exists on the device, it should be replaced. This method should raise a FreeSpaceError if there is not enough free space on the device. The text of the FreeSpaceError must contain the word “card” if on_card is not None otherwise it must contain the word “memory”.
| Parameters: |
|
|---|---|
| Returns: | A list of 3-element tuples. The list is meant to be passed to add_books_to_metadata(). |
Add locations to the booklists. This function must not communicate with the device.
| Parameters: |
|
|---|
Remove books from the metadata list. This function must not communicate with the device.
| Parameters: |
|
|---|
Update metadata on device.
| Parameters: | booklists – A tuple containing the result of calls to (books(oncard=None)(), books(oncard='carda')(), :meth`books(oncard=’cardb’)`). |
|---|
Read the file at path on the device and write it to outfile.
| Parameters: | outfile – file object like sys.stdout or the result of an open() call. |
|---|
Should return a QWidget. The QWidget contains the settings for the device interface
Should save settings to disk. Takes the widget created in config_widget() and saves all settings to disk.
Should return an opts object. The opts object should have at least one attribute format_map which is an ordered list of formats for the device.
provide the driver the current set of plugboards and a function to select a specific plugboard. This method is called immediately before add_books and sync_booklists.
You give it the current device name (either the class name or DEVICE_PLUGBOARD_NAME), the format you are interested in (a ‘real’ format or ‘device_db’), and the plugboards (you were given those by set_plugboards, the same place you got this method).
| Returns: | None or a single plugboard instance. |
|---|
Set the device name in the driveinfo file to ‘name’. This setting will persist until the file is re-created or the name is changed again.
Non-disk devices should implement this method based on the location codes returned by the get_device_information() method.
Given a list of paths, returns another list of paths. These paths point to addable versions of the books.
If there is an error preparing a book, then instead of a path, the position in the returned list for that book should be a three tuple: (original_path, the exception instance, traceback)
Called when calibre is is starting the device. Do any initialization required. Note that multiple instances of the class can be instantiated, and thus __init__ can be called multiple times, but only one instance will have this method called. This method is called on the device thread, not the GUI thread.
Called when calibre is shutting down, either for good or in preparation to restart. Do any cleanup required. This method is called on the device thread, not the GUI thread.
Must return a unique id for the currently connected device (this is called immediately after a successful call to open()). You must implement this method if you set ASK_TO_ALLOW_CONNECT = True
Should ignore the device identified by uid (the result of a call to get_device_uid()) in the future. You must implement this method if you set ASK_TO_ALLOW_CONNECT = True. Note that this function is called immediately after open(), so if open() caches some state, the driver should reset that state.
Return map of device uid to friendly name for all devices that the user has asked to be ignored.
Set the list of device uids that should be ignored by this driver.
Implement this method if your device wants to override a particular preference. You must ensure that all call sites that want a preference that can be overridden use device_prefs[‘something’] instead of prefs[‘something’]. Your method should call device_prefs.set_overrides(pref=val, pref=val, ...). Currently used for: metadata management (prefs[‘manage_device_metadata’])
Called by the device manager when starting plugins. If this method returns a string, then a) it supports the device manager’s dynamic control interface, and b) that name is to be used when talking to the plugin.
This method can be called on the GUI thread. A driver that implements this method must be thread safe.
This method is called to start the plugin. The plugin should begin to accept device connections however it does that. If the plugin is already accepting connections, then do nothing.
This method can be called on the GUI thread. A driver that implements this method must be thread safe.
This method is called to stop the plugin. The plugin should no longer accept connections, and should cleanup behind itself. It is likely that this method should call shutdown. If the plugin is already not accepting connections, then do nothing.
This method can be called on the GUI thread. A driver that implements this method must be thread safe.
Return the value of the option indicated by opt_string. This method can be called when the plugin is not started. Return None if the option does not exist.
This method can be called on the GUI thread. A driver that implements this method must be thread safe.
Bases: list
A list of books. Each Book object must have the fields
- title
- authors
- size (file size of the book)
- datetime (a UTC time tuple)
- path (path on the device to the book)
- thumbnail (can be None) thumbnail is either a str/bytes object with the image data or it should have an attribute image_path that stores an absolute (platform native) path to the image
- tags (a list of strings, can be empty).
Add the book to the booklist. Intent is to maintain any device-internal metadata. Return True if booklists must be sync’ed
Remove a book from the booklist. Correct any device metadata at the same time
Return a dictionary of collections created from collection_attributes. Each entry in the dictionary is of the form collection name:[list of books]
The list of books is sorted by book title, except for collections created from series, in which case series_index is used.
| Parameters: | collection_attributes – A list of attributes of the Book object |
|---|
The base class for such devices is calibre.devices.usbms.driver.USBMS. This class in turn inherits some of its functionality from its bases, documented below. A typical basic USBMS based driver looks like this:
from calibre.devices.usbms.driver import USBMS
class PDNOVEL(USBMS):
name = 'Pandigital Novel device interface'
gui_name = 'PD Novel'
description = _('Communicate with the Pandigital Novel')
author = 'Kovid Goyal'
supported_platforms = ['windows', 'linux', 'osx']
FORMATS = ['epub', 'pdf']
VENDOR_ID = [0x18d1]
PRODUCT_ID = [0xb004]
BCD = [0x224]
VENDOR_NAME = 'ANDROID'
WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = '__UMS_COMPOSITE'
THUMBNAIL_HEIGHT = 144
EBOOK_DIR_MAIN = 'eBooks'
SUPPORTS_SUB_DIRS = False
def upload_cover(self, path, filename, metadata):
coverdata = getattr(metadata, 'thumbnail', None)
if coverdata and coverdata[2]:
with open('%s.jpg' % os.path.join(path, filename), 'wb') as coverfile:
coverfile.write(coverdata[2])
Bases: calibre.devices.usbms.deviceconfig.DeviceConfig, calibre.devices.interface.DevicePlugin
This class provides logic common to all drivers for devices that export themselves as USB Mass Storage devices. Provides implementations for mounting/ejecting of USBMS devices on all platforms.
String identifying the main memory of the device in the windows PnP id strings This can be None, string, list of strings or compiled regex
String identifying the first card of the device in the windows PnP id strings This can be None, string, list of strings or compiled regex
String identifying the second card of the device in the windows PnP id strings This can be None, string, list of strings or compiled regex
Used by the new driver detection to disambiguate main memory from storage cards. Should be a regular expression that matches the main memory mount point assigned by OS X
The maximum length of paths created on the device
Put news in its own folder
Called to disambiguate main memory and storage card for devices that do not distinguish between them on the basis of WINDOWS_CARD_NAME. For e.g.: The EB600
Callback to allow drivers to change the default file name set by create_upload_path().
Bases: calibre.devices.usbms.cli.CLI, calibre.devices.usbms.device.Device
The base class for all USBMS devices. Implements the logic for sending/getting/updating metadata/caching metadata/etc.
Upload book cover to the device. Default implementation does nothing.
| Parameters: |
|
|---|
If you are adding your own plugin in a zip file, you should subclass both InterfaceActionBase and InterfaceAction. The load_actual_plugin() method of you InterfaceActionBase subclass must return an instantiated object of your InterfaceBase subclass.
Bases: PyQt4.QtCore.QObject
A plugin representing an “action” that can be taken in the graphical user interface. All the items in the toolbar and context menus are implemented by these plugins.
Note that this class is the base class for these plugins, however, to integrate the plugin with calibre’s plugin system, you have to make a wrapper class that references the actual plugin. See the calibre.customize.builtins module for examples.
If two InterfaceAction objects have the same name, the one with higher priority takes precedence.
Sub-classes should implement the genesis(), library_changed(), location_selected() shutting_down() and initialization_complete() methods.
Once initialized, this plugin has access to the main calibre GUI via the gui member. You can access other plugins by name, for example:
self.gui.iactions['Save To Disk']
To access the actual plugin, use the interface_action_base_plugin attribute, this attribute only becomes available after the plugin has been initialized. Useful if you want to use methods from the plugin class like do_user_config().
The QAction specified by action_spec is automatically create and made available as self.qaction.
The plugin name. If two plugins with the same name are present, the one with higher priority takes precedence.
The plugin priority. If two plugins with the same name are present, the one with higher priority takes precedence.
The menu popup type for when this plugin is added to a toolbar
Whether this action should be auto repeated when its shortcut key is held down.
Of the form: (text, icon_path, tooltip, keyboard shortcut) icon, tooltip and keyboard shortcut can be None shortcut must be a string, None or tuple of shortcuts. If None, a keyboard shortcut corresponding to the action is not registered. If you pass an empty tuple, then the shortcut is registered with no default key binding.
If True, a menu is automatically created and added to self.qaction
If True, a clone of self.qaction is added to the menu of self.qaction If you want the text of this action to be different from that of self.qaction, set this variable to the new text
Set of locations to which this action must not be added. See all_locations for a list of possible locations
Set of locations from which this action must not be removed. See all_locations for a list of possible locations
Type of action ‘current’ means acts on the current view ‘global’ means an action that does not act on the current view, but rather on calibre as a whole
If True, then this InterfaceAction will have the opportunity to interact with drag and drop events. See the methods, accept_enter_event(), :meth`:accept_drag_move_event`, drop_event() for details.
This method should return True iff this interface action is capable of handling the drag event. Do not call accept/ignore on the event, that will be taken care of by the calibre UI.
This method should return True iff this interface action is capable of handling the drag event. Do not call accept/ignore on the event, that will be taken care of by the calibre UI.
This method should perform some useful action and return True iff this interface action is capable of handling the drop event. Do not call accept/ignore on the event, that will be taken care of by the calibre UI. You should not perform blocking/long operations in this function. Instead emit a signal or use QTimer.singleShot and return quickly. See the builtin actions for examples.
Convenience method to easily add actions to a QMenu. Returns the created QAction, This action has one extra attribute calibre_shortcut_unique_name which if not None refers to the unique name under which this action is registered with the keyboard manager.
| Parameters: |
|
|---|
If this plugin comes in a ZIP file (user added plugin), this method will allow you to load resources from the ZIP file.
For example to load an image:
pixmap = QPixmap()
pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
icon = QIcon(pixmap)
| Parameters: | names – List of paths to resources in the zip file using / as separator |
|---|---|
| Returns: | A dictionary of the form {name : file_contents}. Any names that were not found in the zip file will not be present in the dictionary. |
Setup this plugin. Only called once during initialization. self.gui is available. The action specified by action_spec is available as self.qaction.
Called whenever the book list being displayed in calibre changes. Currently values for loc are: library, main, card and cardb.
This method should enable/disable this action and its sub actions as appropriate for the location.
Called whenever the current library is changed.
| Parameters: | db – The LibraryDatabase corresponding to the current library. |
|---|
Called once per action when the layout of the main GUI is completed. If your action needs to make changes to the layout, they should be done here, rather than in initialization_complete().
Bases: calibre.customize.Plugin
Bases: calibre.customize.Plugin
A plugin representing a widget displayed in the Preferences dialog.
This plugin has only one important method create_widget(). The various fields of the plugin control how it is categorized in the UI.
Import path to module that contains a class named ConfigWidget which implements the ConfigWidgetInterface. Used by create_widget().
Where in the list of categories the category of this plugin should be.
Where in the list of names in a category, the gui_name of this plugin should be
The category this plugin should be in
The category name displayed to the user for this plugin
The name displayed to the user for this plugin
The icon for this plugin, should be an absolute path
The description used for tooltips and the like
Create and return the actual Qt widget used for setting this group of preferences. The widget must implement the calibre.gui2.preferences.ConfigWidgetInterface.
The default implementation uses config_widget to instantiate the widget.
This class defines the interface that all widgets displayed in the Preferences dialog must implement. See ConfigWidgetBase for a base class that implements this interface and defines various convenience methods as well.
This signal must be emitted whenever the user changes a value in this widget
Set to True iff the restore_to_defaults() method is implemented.
The tooltip for the Restore to defaults button
If True the Preferences dialog will not allow the user to set any more preferences. Only has effect if commit() returns True.
Called once before the widget is displayed, should perform any necessary setup.
| Parameters: | gui – The main calibre graphical user interface |
|---|
Should set all config values to their initial values (the values stored in the config files).
Base class that contains code to easily add standard config widgets like checkboxes, combo boxes, text fields and so on. See the register() method.
This class automatically handles change notification, resetting to default, translation between gui objects and config objects, etc. for registered settings.
If your config widget inherits from this class but includes setting that are not registered, you should override the ConfigWidgetInterface methods and call the base class methods inside the overrides.
Register a setting.
| Parameters: |
|
|---|