Its format is module_path:class_name #: The specified class must be defined in the specified module. ''' name = 'Interface Plugin Demo' description = 'An advanced plugin demo' supported_platforms = author = 'Kovid Goyal' version = ( 1, 0, 0 ) minimum_calibre_version = ( 0, 7, 53 ) #: This field defines the GUI plugin class that contains all the code #: that actually does something. The reason for having two classes is that it allows the command line calibre utilities to run without needing to load the GUI libraries. The actual interface plugin class is called InterfacePlugin and is defined in the ui.py file, as specified in the actual_plugin field below. _init_.py ¶įirst, the obligatory _init_.py to define the plugin metadata:įrom calibre.customize import InterfaceActionBase class InterfacePluginDemo ( InterfaceActionBase ): ''' This class is a simple wrapper that provides information about the actual plugin class. Interface of your plugin into different languages. mo files with the translations of the user This file defines the interface part of the plugin images/icon.pngĪ text file with information about the plugin translationsĪ folder containing. This file contains the actual code that does something useful ui.py _init_.pyĪs before, the file that defines the plugin class main.py The name you use for some_name enters a global namespace shared by all plugins, so make it as unique as possible.īut remember that it must be a valid Python identifier (only alphabets, numbers and the underscore). Just like you would normally (by defining _init_.py in each sub-folder), and everything should “just work”. You can create packages and subpackages of. Some_module refers to some_module.py file inside the ZIP file. some_name comes from the filename of the empty text file. The prefix calibre_plugins must always be present. The first thing to note is that this ZIP file has a lot more files in it, explained below, pay particular attention toįrom calibre_plugins.some_name.some_module import some_object You can download this plugin from interface_demo_plugin.zip How to create elements in the calibre user interface and how to access (images or data files) from the plugin ZIP file, allow users to configure your plugin, This plugin will be spread over a few files (to keep the code clean). This is a trivial plugin, lets move on toĪ more complex example that actually adds a component to the user interface. You can download the Hello World plugin fromĮvery time you use calibre to convert a book, the plugin’s run() method will be called and theĬonverted book will have its publisher set to “Hello World”. If you installed calibre in /Applications the command line toolsĪre in /Applications/calibre.app/Contents/MacOS/. On macOS, the command line tools are inside the calibre bundle, for example, The folder in which you created _init_.py: To add this code to calibre as a plugin, simply run the following in publisher = 'Hello World' set_metadata ( file, mi, ext ) return path_to_ebook lower () mi = get_metadata ( file, ext ) mi. From calibre.customize import FileTypePlugin class HelloWorld ( FileTypePlugin ): name = 'Hello World Plugin' # Name of the plugin description = 'Set the publisher to Hello World for all new conversions' supported_platforms = # Platforms this plugin will run on author = 'Acme Inc.' # The author of this plugin version = ( 1, 0, 0 ) # The version number of this plugin file_types = # The file types that this plugin will be applied to on_postprocess = True # Run this plugin after conversion is complete minimum_calibre_version = ( 0, 7, 53 ) def run ( self, path_to_ebook ): from import get_metadata, set_metadata with open ( path_to_ebook, 'r+b' ) as file : ext = os.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |