காலிபரின் செயல்பாட்டை நீட்டிக்க உங்கள் சொந்த செருகுநிரல்களை எழுதுதல்

காலிபர் மிகவும் மட்டு வடிவமைப்பைக் கொண்டுள்ளது. காலிபரில் கிட்டத்தட்ட அனைத்து செயல்பாடுகளும் செருகுநிரல்களின் வடிவத்தில் வருகின்றன. செய்திகளைப் பதிவிறக்குவதற்கு (இவை சமையல் குறிப்புகள் என அழைக்கப்படுகின்றன), பயனர் இடைமுகத்தின் பல்வேறு கூறுகளுக்கு, வெவ்வேறு சாதனங்களுடன் இணைக்க, கோப்புகளை காலிபரில் சேர்க்கும்போது செயலாக்கவும், அவற்றை மாற்றுவதற்காகவும் செருகுநிரல்கள் பயன்படுத்தப்படுகின்றன. செல்வதன் மூலம் அனைத்து உள்ளமைக்கப்பட்ட செருகுநிரல்களின் முழுமையான பட்டியலைப் பெறலாம்: கிலாபெல்: விருப்பத்தேர்வுகள்-> மேம்பட்ட-> செருகுநிரல்கள்.

புதிய அம்சங்களை காலிபரில் சேர்க்க உங்கள் சொந்த செருகுநிரல்களை எவ்வாறு உருவாக்குவது என்பதை இங்கே நாங்கள் உங்களுக்குக் கற்பிப்போம்.

Note

இது காலிபர் வெளியீடுகளுக்கு மட்டுமே பொருந்தும்> = 0.8.60

ஒரு காலிபர் சொருகி உடற்கூறியல்

ஒரு காலிபர் சொருகி மிகவும் எளிமையானது, இது சில பைதான் குறியீடு மற்றும் சொருகி தேவைப்படும் படக் கோப்புகள் போன்ற வேறு எந்த ஆதாரங்களையும் கொண்ட ஒரு ஜிப் கோப்பு மட்டுமே. மேலும் கவலைப்படாமல், ஒரு அடிப்படை உதாரணத்தைப் பார்ப்போம்.

EPUB மற்றும் MOBI வடிவங்களில் பல்வேறு மின்-வாதங்களை சுயமாக வெளியிட நீங்கள் பயன்படுத்தும் திறமை உங்களிடம் உள்ளது என்று வைத்துக்கொள்வோம். காலிபர் உருவாக்கிய அனைத்து கோப்புகளும் அவற்றின் வெளியீட்டாளரை "ஹலோ வேர்ல்ட்" என்று அமைக்க வேண்டும் என்று நீங்கள் விரும்புகிறீர்கள், அதை எப்படி செய்வது என்பது இங்கே. பெயரிடப்பட்ட ஒரு கோப்பை உருவாக்கவும்: கோப்பு: __init __. Py (இது ஒரு சிறப்புப் பெயர் மற்றும் உங்கள் சொருகியின் முக்கிய கோப்பிற்கு எப்போதும் பயன்படுத்தப்பட வேண்டும்) மற்றும் பின்வரும் பைதான் குறியீட்டை உள்ளிடவும்:


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 = ['windows', 'osx', 'linux'] # 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          = {'epub', 'mobi'} # 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 calibre.ebooks.metadata.meta import get_metadata, set_metadata
        with open(path_to_ebook, 'r+b') as file:
            ext  = os.path.splitext(path_to_ebook)[-1][1:].lower()
            mi = get_metadata(file, ext)
            mi.publisher = 'Hello World'
            set_metadata(file, mi, ext)
        return path_to_ebook

அவ்வளவுதான். இந்த குறியீட்டை ஒரு சொருகி என காலிபரில் சேர்க்க, நீங்கள் உருவாக்கிய கோப்புறையில் பின்வருவனவற்றை இயக்கவும்: கோப்பு: __init __. Py

calibre-customize -b .

Note

MACOS இல், கட்டளை வரி கருவிகள் காலிபர் மூட்டைக்குள் உள்ளன, எடுத்துக்காட்டாக, நீங்கள் காலிபரை நிறுவியிருந்தால்: கோப்பு: /பயன்பாடுகள் கட்டளை வரி கருவிகள்:/பயன்பாடுகள்/calibre.app/பொருளடக்கம்/ .

ஹலோ உலக சொருகி இதிலிருந்து பதிவிறக்கம் செய்யலாம்: பதிவிறக்கம்_பீல்: helloworld_plugin.zip.

ஒவ்வொரு முறையும் நீங்கள் ஒரு புத்தகத்தை மாற்ற காலிபரைப் பயன்படுத்தும்போது, சொருகி: மெத்: ரன் முறை அழைக்கப்படும், மாற்றப்பட்ட புத்தகத்தில் அதன் வெளியீட்டாளர்" ஹலோ வேர்ல்ட் "ஆக அமைக்கப்பட்டிருக்கும். இது ஒரு அற்பமான சொருகி, பயனர் இடைமுகத்திற்கு உண்மையில் ஒரு கூறுகளைச் சேர்க்கும் மிகவும் சிக்கலான எடுத்துக்காட்டுக்கு செல்ல உதவுகிறது.

ஒரு பயனர் இடைமுக சொருகி

இந்த சொருகி சில கோப்புகளில் பரவுகிறது (குறியீட்டை சுத்தமாக வைத்திருக்க). சொருகி ஜிப் கோப்பிலிருந்து வளங்களை (படங்கள் அல்லது தரவுக் கோப்புகள்) எவ்வாறு பெறுவது, உங்கள் சொருகி கட்டமைக்க பயனர்களை அனுமதிப்பது, காலிபர் பயனர் இடைமுகத்தில் கூறுகளை எவ்வாறு உருவாக்குவது மற்றும் புத்தக தரவுத்தளத்தை காலிபரில் எவ்வாறு அணுகுவது மற்றும் வினவுவது என்பதை இது காண்பிக்கும்.

இந்த சொருகி இதிலிருந்து பதிவிறக்கம் செய்யலாம்: Download_file: இடைமுகம்_டெமோ_ப்ளூஜின்.ஜிப்

கவனிக்க வேண்டிய முதல் விஷயம் என்னவென்றால், இந்த ஜிப் கோப்பில் இன்னும் நிறைய கோப்புகள் உள்ளன, கீழே விளக்கப்பட்டுள்ளன, `` சொருகி-இறக்குமதி-பெயர்-இடைமுகம்_டெமோ.டெக்ஸ்டிக்கு குறிப்பாக கவனம் செலுத்துங்கள்.

** சொருகி-இறக்குமதி-பெயர்-இடைமுகம்_டெமோ.

பல கோப்பு சொருகி மந்திரத்தை இயக்க பயன்படுத்தப்படும் வெற்று உரை கோப்பு. ஒன்றுக்கு மேற்பட்ட .py கோப்பைப் பயன்படுத்தும் அனைத்து செருகுநிரல்களிலும் இந்த கோப்பு இருக்க வேண்டும். இது காலியாக இருக்க வேண்டும் மற்றும் அதன் கோப்பு பெயர் வடிவமாக இருக்க வேண்டும்: `` சொருகி-முக்கிய பெயர்-** சில_பேம் **. Txt``. இந்த கோப்பின் இருப்பு, ஜிப் கோப்பின் உள்ளே இருக்கும் .py கோப்புகளிலிருந்து குறியீட்டை இறக்குமதி செய்ய உங்களை அனுமதிக்கிறது, இது போன்ற அறிக்கையைப் பயன்படுத்தி

from calibre_plugins.some_name.some_module import some_object

`` Calibre_plugins`` முன்னொட்டு எப்போதும் இருக்க வேண்டும். `` சில_நேம்`` வெற்று உரை கோப்பின் கோப்பு பெயரில் இருந்து வருகிறது. `` சில_மோடூல்`` குறிக்கிறது: கோப்பு: சில_மோடூல்.பி கோப்பு ஜிப் கோப்பின் உள்ளே. இந்த இறக்குமதி வழக்கமான பைதான் இறக்குமதியைப் போலவே சக்தி வாய்ந்தது என்பதை நினைவில் கொள்க. நீங்கள் சாதாரணமாக (ஒவ்வொரு துணை கோப்புறையிலும் __init__.py ஐ வரையறுப்பதன் மூலம்) ஜிப் கோப்பிற்குள் .py தொகுதிகளின் தொகுப்புகள் மற்றும் துணைப் பேக்குகளை உருவாக்கலாம், மேலும் அனைத்தும் "வேலை செய்ய வேண்டும்".

`` சில_நேம்` go க்கு நீங்கள் பயன்படுத்தும் பெயர் அனைத்து செருகுநிரல்களால் பகிரப்பட்ட உலகளாவிய பெயர்வெளியில் நுழைகிறது, ** எனவே முடிந்தவரை தனித்துவத்தை உருவாக்கவும் **. ஆனால் இது செல்லுபடியாகும் பைதான் அடையாளங்காட்டியாக இருக்க வேண்டும் என்பதை நினைவில் கொள்ளுங்கள் (எழுத்துக்கள், எண்கள் மற்றும் அடிக்கோடிட்டது).

** __ init __. py **

முன்பு போல, சொருகி வகுப்பை வரையறுக்கும் கோப்பு

** main.py **

இந்த கோப்பில் பயனுள்ள ஒன்றைச் செய்யும் உண்மையான குறியீடு உள்ளது

** ui.py **

இந்த கோப்பு சொருகி இடைமுக பகுதியை வரையறுக்கிறது

** படங்கள்/icon.png **

இந்த சொருகி ஐகான்

** பற்றி. txt **

சொருகி பற்றிய தகவலுடன் உரை கோப்பு

** மொழிபெயர்ப்புகள் **

.Mo கோப்புகளைக் கொண்ட ஒரு கோப்புறை உங்கள் சொருகி பயனர் இடைமுகத்தின் மொழிபெயர்ப்புகளுடன் வெவ்வேறு மொழிகளில். விவரங்களுக்கு கீழே காண்க.

இப்போது குறியீட்டைப் பார்ப்போம்.

__init__.py

முதலில், சொருகி மெட்டாடேட்டாவை வரையறுக்க வேண்டிய கட்டாய __init __. Py`:

from calibre.customize import InterfaceActionBase


class InterfacePluginDemo(InterfaceActionBase):
    '''
    This class is a simple wrapper that provides information about the actual
    plugin class. The actual interface plugin class is called InterfacePlugin
    and is defined in the ui.py file, as specified in the actual_plugin field
    below.

    The reason for having two classes is that it allows the command line
    calibre utilities to run without needing to load the GUI libraries.
    '''
    name                = 'Interface Plugin Demo'
    description         = 'An advanced plugin demo'
    supported_platforms = ['windows', 'osx', 'linux']
    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. Its format is module_path:class_name
    #: The specified class must be defined in the specified module.
    actual_plugin       = 'calibre_plugins.interface_demo.ui:InterfacePlugin'

    def is_customizable(self):
        '''
        This method must return True to enable customization via
        Preferences->Plugins
        '''
        return True

    def config_widget(self):
        '''
        Implement this method and :meth:`save_settings` in your plugin to
        use a custom configuration dialog.

        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.

        The base class implementation of this method raises NotImplementedError
        so by default no user configuration is possible.
        '''
        # It is important to put this import statement here rather than at the
        # top of the module as importing the config class will also cause the
        # GUI libraries to be loaded, which we do not want when using calibre
        # from the command line
        from calibre_plugins.interface_demo.config import ConfigWidget
        return ConfigWidget()

    def save_settings(self, config_widget):
        '''
        Save the settings specified by the user with config_widget.

        :param config_widget: The widget returned by :meth:`config_widget`.
        '''
        config_widget.save_settings()

        # Apply the changes
        ac = self.actual_plugin_
        if ac is not None:
            ac.apply_settings()


ஒரே குறிப்பிடத்தக்க அம்சம் புலம்: ATTR: ரியல்_ப்ளூகின். காலிபர் கட்டளை வரி மற்றும் GUI இடைமுகங்கள் இரண்டையும் கொண்டிருப்பதால், இது போன்ற GUI செருகுநிரல்கள் எந்த GUI நூலகங்களையும் __init__.py இல் ஏற்றக்கூடாது. உண்மையான_பிளகின் புலம் உங்களுக்காக இதைச் செய்கிறது, உண்மையான சொருகி உங்கள் ஜிப் காப்பகத்திற்குள் மற்றொரு கோப்பில் காணப்பட வேண்டும் என்று சொல்வதன் மூலம், இது GUI சூழலில் மட்டுமே ஏற்றப்படும்.

இது வேலை செய்ய, மேலே விவாதிக்கப்பட்டபடி, உங்கள் சொருகி ஜிப் கோப்பில் சொருகி-இறக்குமதி-பெயர்-some_name.txt கோப்பை நீங்கள் வைத்திருக்க வேண்டும் என்பதை நினைவில் கொள்ளுங்கள்.

சொருகி பயனர் உள்ளமைவை செயல்படுத்த இரண்டு முறைகள் உள்ளன. இவை கீழே விவாதிக்கப்பட்டுள்ளன.

ui.py

இப்போது உண்மையான GUI சொருகி வரையறுக்கும் UI.py ஐப் பார்ப்போம். மூலக் குறியீடு பெரிதும் கருத்து தெரிவிக்கப்பட்டுள்ளது மற்றும் சுய விளக்கமாக இருக்க வேண்டும்:

from calibre.gui2.actions import InterfaceAction
from calibre_plugins.interface_demo.main import DemoDialog


class InterfacePlugin(InterfaceAction):

    name = 'Interface Plugin Demo'

    # Declare the main action associated with this plugin
    # The keyboard shortcut can be None if you dont want to use a keyboard
    # shortcut. Remember that currently calibre has no central management for
    # keyboard shortcuts, so try to use an unusual/unused shortcut.
    action_spec = ('Interface Plugin Demo', None,
            'Run the Interface Plugin Demo', 'Ctrl+Shift+F1')

    def genesis(self):
        # This method is called once per plugin, do initial setup here

        # Set the icon for this interface action
        # The get_icons function is a builtin function defined for all your
        # plugin code. It loads icons from the plugin zip file. It returns
        # QIcon objects, if you want the actual data, use the analogous
        # get_resources builtin function.
        #
        # Note that if you are loading more than one icon, for performance, you
        # should pass a list of names to get_icons. In this case, get_icons
        # will return a dictionary mapping names to QIcons. Names that
        # are not found in the zip file will result in null QIcons.
        icon = get_icons('images/icon.png', 'Interface Demo Plugin')

        # The qaction is automatically created from the action_spec defined
        # above
        self.qaction.setIcon(icon)
        self.qaction.triggered.connect(self.show_dialog)

    def show_dialog(self):
        # The base plugin object defined in __init__.py
        base_plugin_object = self.interface_action_base_plugin
        # Show the config dialog
        # The config dialog can also be shown from within
        # Preferences->Plugins, which is why the do_user_config
        # method is defined on the base plugin class
        do_user_config = base_plugin_object.do_user_config

        # self.gui is the main calibre GUI. It acts as the gateway to access
        # all the elements of the calibre user interface, it should also be the
        # parent of the dialog
        d = DemoDialog(self.gui, self.qaction.icon(), do_user_config)
        d.show()

    def apply_settings(self):
        from calibre_plugins.interface_demo.config import prefs
        # In an actual non trivial plugin, you would probably need to
        # do something based on the settings in prefs
        prefs

main.py

இடைமுக சொருகி டெமோ உரையாடலை செயல்படுத்த உண்மையான தர்க்கம்.

from qt.core import QDialog, QLabel, QMessageBox, QPushButton, QVBoxLayout


class DemoDialog(QDialog):

    def __init__(self, gui, icon, do_user_config):
        QDialog.__init__(self, gui)
        self.gui = gui
        self.do_user_config = do_user_config

        # The current database shown in the GUI
        # db is an instance of the class LibraryDatabase from db/legacy.py
        # This class has many, many methods that allow you to do a lot of
        # things. For most purposes you should use db.new_api, which has
        # a much nicer interface from db/cache.py
        self.db = gui.current_db

        self.l = QVBoxLayout()
        self.setLayout(self.l)

        self.label = QLabel(prefs['hello_world_msg'])
        self.l.addWidget(self.label)

        self.setWindowTitle('Interface Plugin Demo')
        self.setWindowIcon(icon)

        self.about_button = QPushButton('About', self)
        self.about_button.clicked.connect(self.about)
        self.l.addWidget(self.about_button)

        self.marked_button = QPushButton(
            'Show books with only one format in the calibre GUI', self)
        self.marked_button.clicked.connect(self.marked)
        self.l.addWidget(self.marked_button)

        self.view_button = QPushButton(
            'View the most recently added book', self)
        self.view_button.clicked.connect(self.view)
        self.l.addWidget(self.view_button)

        self.update_metadata_button = QPushButton(
            'Update metadata in a book\'s files', self)
        self.update_metadata_button.clicked.connect(self.update_metadata)
        self.l.addWidget(self.update_metadata_button)

        self.conf_button = QPushButton(
                'Configure this plugin', self)
        self.conf_button.clicked.connect(self.config)
        self.l.addWidget(self.conf_button)

        self.resize(self.sizeHint())

    def about(self):
        # Get the about text from a file inside the plugin zip file
        # The get_resources function is a builtin function defined for all your
        # plugin code. It loads files from the plugin zip file. It returns
        # the bytes from the specified file.
        #
        # Note that if you are loading more than one file, for performance, you
        # should pass a list of names to get_resources. In this case,
        # get_resources will return a dictionary mapping names to bytes. Names that
        # are not found in the zip file will not be in the returned dictionary.
        text = get_resources('about.txt')
        QMessageBox.about(self, 'About the Interface Plugin Demo',
                text.decode('utf-8'))

    def marked(self):
        ''' Show books with only one format '''
        db = self.db.new_api
        matched_ids = {book_id for book_id in db.all_book_ids() if len(db.formats(book_id)) == 1}
        # Mark the records with the matching ids
        # new_api does not know anything about marked books, so we use the full
        # db object
        self.db.set_marked_ids(matched_ids)

        # Tell the GUI to search for all marked records
        self.gui.search.setEditText('marked:true')
        self.gui.search.do_search()

    def view(self):
        ''' View the most recently added book '''
        most_recent = most_recent_id = None
        db = self.db.new_api
        for book_id, timestamp in db.all_field_for('timestamp', db.all_book_ids()).items():
            if most_recent is None or timestamp > most_recent:
                most_recent = timestamp
                most_recent_id = book_id

        if most_recent_id is not None:
            # Get a reference to the View plugin
            view_plugin = self.gui.iactions['View']
            # Ask the view plugin to launch the viewer for row_number
            view_plugin._view_calibre_books([most_recent_id])

    def update_metadata(self):
        '''
        Set the metadata in the files in the selected book's record to
        match the current metadata in the database.
        '''
        from calibre.ebooks.metadata.meta import set_metadata
        from calibre.gui2 import error_dialog, info_dialog

        # Get currently selected books
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return error_dialog(self.gui, 'Cannot update metadata',
                             'No books selected', show=True)
        # Map the rows to book ids
        ids = list(map(self.gui.library_view.model().id, rows))
        db = self.db.new_api
        for book_id in ids:
            # Get the current metadata for this book from the db
            mi = db.get_metadata(book_id, get_cover=True, cover_as_data=True)
            fmts = db.formats(book_id)
            if not fmts:
                continue
            for fmt in fmts:
                fmt = fmt.lower()
                # Get a python file object for the format. This will be either
                # an in memory file or a temporary on disk file
                ffile = db.format(book_id, fmt, as_file=True)
                ffile.seek(0)
                # Set metadata in the format
                set_metadata(ffile, mi, fmt)
                ffile.seek(0)
                # Now replace the file in the calibre library with the updated
                # file. We dont use add_format_with_hooks as the hooks were
                # already run when the file was first added to calibre.
                db.add_format(book_id, fmt, ffile, run_hooks=False)

        info_dialog(self, 'Updated files',
                'Updated the metadata in the files of %d book(s)'%len(ids),
                show=True)

    def config(self):
        self.do_user_config(parent=self)
        # Apply the changes
        self.label.setText(prefs['hello_world_msg'])

சொருகி ஜிப் கோப்பிலிருந்து ஆதாரங்களைப் பெறுதல்

காலிபரின் சொருகி ஏற்றுதல் அமைப்பு சொருகி ஜிப் கோப்பிலிருந்து கோப்புகளை வசதியாகப் பெற அனுமதிக்கும் இரண்டு உள்ளமைக்கப்பட்ட செயல்பாடுகளை வரையறுக்கிறது.

** get_resources (name_or_list_of_names) **

இந்த செயல்பாடு ஜிப் கோப்பின் உள்ளே உள்ள கோப்புகளுக்கான பாதைகளின் பட்டியலுடன் அழைக்கப்பட வேண்டும். எடுத்துக்காட்டாக கோப்பை அணுக: கோப்பு: icon.png ZIP கோப்பில் உள்ள கோப்புறை படங்களில், நீங்கள் பயன்படுத்துவீர்கள்:` படங்கள்/icon.png`. ஜன்னல்களில் கூட, பாதை பிரிப்பானாக எப்போதும் முன்னோக்கி குறைப்பதைப் பயன்படுத்துங்கள். நீங்கள் ஒரு பெயரில் கடந்து செல்லும்போது, செயல்பாடு அந்த கோப்பின் மூல பைட்டுகளைத் தரும் அல்லது ஜிப் கோப்பில் பெயர் காணப்படாவிட்டால் எதுவும் இல்லை. நீங்கள் ஒன்றுக்கு மேற்பட்ட பெயர்களை கடந்து சென்றால், அது ஒரு அகராதியை பைட்டுகளுக்கு மேப்பிங் செய்கிறது. ஒரு பெயர் கிடைக்கவில்லை என்றால், அது திரும்பிய அகராதியில் இருக்காது.

.

Get_resources () க்கான ஒரு ரேப்பர், இது get_resources ஆல் திரும்பிய மூல பைட்டுகளிலிருந்து கிகான் பொருள்களை உருவாக்குகிறது. ஜிப் கோப்பில் ஒரு பெயர் காணப்படவில்லை என்றால், தொடர்புடைய கிகான் பூஜ்யமாக இருக்கும். ஐகான் தீம்-இங்கை ஆதரிக்க, உங்கள் சொருகி மனித நட்பு பெயரை `` செருகுநிரல்_பெயர்`` என அனுப்பவும். உங்கள் சொருகி ஐகான்களுடன் பயனர் ஒரு ஐகான் கருப்பொருளைப் பயன்படுத்துகிறார்களானால், அவை முன்னுரிமையாக ஏற்றப்படும்.

உங்கள் சொருகி பயனர் உள்ளமைவை இயக்குகிறது

உங்கள் சொருகி கட்டமைக்க பயனர்களை அனுமதிக்க, உங்கள் அடிப்படை சொருகி வகுப்பில் மூன்று முறைகளை வரையறுக்க வேண்டும், ** is_customizable **, ** config_widget ** மற்றும் ** save_settings ** கீழே காட்டப்பட்டுள்ளபடி:

    def is_customizable(self):
        '''
        This method must return True to enable customization via
        Preferences->Plugins
        '''
        return True
    def config_widget(self):
        '''
        Implement this method and :meth:`save_settings` in your plugin to
        use a custom configuration dialog.

        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.

        The base class implementation of this method raises NotImplementedError
        so by default no user configuration is possible.
        '''
        # It is important to put this import statement here rather than at the
        # top of the module as importing the config class will also cause the
        # GUI libraries to be loaded, which we do not want when using calibre
        # from the command line
        from calibre_plugins.interface_demo.config import ConfigWidget
        return ConfigWidget()
    def save_settings(self, config_widget):
        '''
        Save the settings specified by the user with config_widget.

        :param config_widget: The widget returned by :meth:`config_widget`.
        '''
        config_widget.save_settings()

        # Apply the changes
        ac = self.actual_plugin_
        if ac is not None:
            ac.apply_settings()

உள்ளமைவு தரவை (அதன் நீண்ட வரலாற்றின் மரபு) சேமிக்க காலிபர் பல வழிகளைக் கொண்டுள்ளது. பரிந்துரைக்கப்பட்ட வழி ** jsonconfig ** வகுப்பைப் பயன்படுத்துவது, இது உங்கள் உள்ளமைவு தகவல்களை ஒரு .json கோப்பில் சேமிக்கிறது.

டெமோ சொருகி உள்ளமைவு தரவை நிர்வகிப்பதற்கான குறியீடு config.py இல் உள்ளது:

from qt.core import QHBoxLayout, QLabel, QLineEdit, QWidget

# This is where all preferences for this plugin will be stored
# Remember that this name (i.e. plugins/interface_demo) is also
# in a global namespace, so make it as unique as possible.
# You should always prefix your config file name with plugins/,
# so as to ensure you dont accidentally clobber a calibre config file
prefs = JSONConfig('plugins/interface_demo')

# Set defaults
prefs.defaults['hello_world_msg'] = 'Hello, World!'


class ConfigWidget(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.l = QHBoxLayout()
        self.setLayout(self.l)

        self.label = QLabel('Hello world &message:')
        self.l.addWidget(self.label)

        self.msg = QLineEdit(self)
        self.msg.setText(prefs['hello_world_msg'])
        self.l.addWidget(self.msg)
        self.label.setBuddy(self.msg)

    def save_settings(self):
        prefs['hello_world_msg'] = self.msg.text()

`` PREFS`` பொருள் இப்போது சொருகி குறியீடு முழுவதும் ஒரு எளிய

from calibre_plugins.interface_demo.config import prefs

Main.py இல் பயன்படுத்தப்படும் `` PREFS`` பொருளை நீங்கள் காணலாம்:

        self.do_user_config(parent=self)
        # Apply the changes
        self.label.setText(prefs['hello_world_msg'])

புத்தக செருகுநிரல்களைத் திருத்தவும்

இப்போது கியர்களை சிறிது மாற்றுவோம், மேலும் காலிபர் புத்தக எடிட்டருக்கு கருவிகளைச் சேர்க்க ஒரு சொருகி உருவாக்குவதைப் பார்ப்போம். சொருகி இங்கே கிடைக்கிறது :: Download_file: atitor_demo_plugin.zip.

முதல் படி, அனைத்து செருகுநிரல்களையும் பொறுத்தவரை, இறக்குமதி பெயரை வெற்று TXT கோப்பை உருவாக்குவது, விவரிக்கப்பட்டுள்ளபடி: ref: மேலே <இறக்குமதி_நாம்_TXT>. `` சொருகி-இறக்குமதி-பெயர்-எடிட்டர்_ப்ளூகின்_டெமோ.டெக்ஸ்டிக்` கோப்பை பெயரிடுவோம்.

இப்போது நாம் கட்டாய __init __. Py` கோப்பை உருவாக்குகிறோம், அது சொருகி பற்றிய மெட்டாடேட்டாவைக் கொண்டுள்ளது - அதன் பெயர், ஆசிரியர், பதிப்பு போன்றவை.

from calibre.customize import EditBookToolPlugin


class DemoPlugin(EditBookToolPlugin):

    name = 'Edit Book plugin demo'
    version = (1, 0, 0)
    author = 'Kovid Goyal'
    supported_platforms = ['windows', 'osx', 'linux']
    description = 'A demonstration of the plugin interface for the ebook editor'
    minimum_calibre_version = (1, 46, 0)

ஒரு ஒற்றை எடிட்டர் சொருகி பல கருவிகளை வழங்க முடியும், ஒவ்வொரு கருவியும் கருவிப்பட்டியில் உள்ள ஒற்றை பொத்தானுக்கு ஒத்திருக்கிறது மற்றும் நுழைவு: கிலாபெல்: எடிட்டரில் செருகுநிரல்கள் மெனு. கருவி பல தொடர்புடைய செயல்களைக் கொண்டிருந்தால் இவை துணை மெனஸைக் கொண்டிருக்கலாம்.

கருவிகள் அனைத்தும் உங்கள் சொருகி `` main.py`` கோப்பில் வரையறுக்கப்பட வேண்டும். ஒவ்வொரு கருவியும்: வகுப்பிலிருந்து பெறும் ஒரு வர்க்கமாகும்: calibre.gui2.tweak_book.plugin.tool வகுப்பு. டெமோ சொருகியிலிருந்து `` main.py`` ஐப் பார்ப்போம், மூலக் குறியீடு பெரிதும் கருத்து தெரிவிக்கப்பட்டுள்ளது, மேலும் சுய விளக்கமாக இருக்க வேண்டும். மேலும் விவரங்களுக்கு API ஆவணங்களைப் படியுங்கள்: வகுப்பு: calibre.gui2.tweak_book.plugin.tool வகுப்பைப் படியுங்கள்.

main.py

பயனர் வழங்கிய எண்ணால் புத்தகத்தில் உள்ள அனைத்து எழுத்துரு அளவுகளையும் பெருக்கும் ஒற்றை கருவியின் வரையறையை இங்கே காண்போம். இந்த கருவி உங்கள் சொந்த செருகுநிரல்களை வளர்ப்பதில் உங்களுக்குத் தேவையான பல்வேறு முக்கியமான கருத்துக்களை நிரூபிக்கிறது, எனவே நீங்கள் (பெரிதும் கருத்து தெரிவிக்கப்பட்ட) மூலக் குறியீட்டை கவனமாக படிக்க வேண்டும்.

import re

from calibre import force_unicode
from calibre.ebooks.oeb.polish.container import OEB_DOCS, OEB_STYLES, serialize
from calibre.gui2 import error_dialog

# The base class that all tools must inherit from
from calibre.gui2.tweak_book.plugin import Tool
from css_parser.css import CSSRule
from qt.core import QAction, QInputDialog


class DemoTool(Tool):

    #: Set this to a unique name it will be used as a key
    name = 'demo-tool'

    #: If True the user can choose to place this tool in the plugins toolbar
    allowed_in_toolbar = True

    #: If True the user can choose to place this tool in the plugins menu
    allowed_in_menu = True

    def create_action(self, for_toolbar=True):
        # Create an action, this will be added to the plugins toolbar and
        # the plugins menu
        ac = QAction(get_icons('images/icon.png'), 'Magnify fonts', self.gui)  # noqa
        if not for_toolbar:
            # Register a keyboard shortcut for this toolbar action. We only
            # register it for the action created for the menu, not the toolbar,
            # to avoid a double trigger
            self.register_shortcut(ac, 'magnify-fonts-tool', default_keys=('Ctrl+Shift+Alt+D',))
        ac.triggered.connect(self.ask_user)
        return ac

    def ask_user(self):
        # Ask the user for a factor by which to multiply all font sizes
        factor, ok = QInputDialog.getDouble(
            self.gui, 'Enter a magnification factor', 'Allow font sizes in the book will be multiplied by the specified factor',
            value=2, min=0.1, max=4
        )
        if ok:
            # Ensure any in progress editing the user is doing is present in the container
            self.boss.commit_all_editors_to_container()
            try:
                self.magnify_fonts(factor)
            except Exception:
                # Something bad happened report the error to the user
                import traceback
                error_dialog(self.gui, _('Failed to magnify fonts'), _(
                    'Failed to magnify fonts, click "Show details" for more info'),
                    det_msg=traceback.format_exc(), show=True)
                # Revert to the saved restore point
                self.boss.revert_requested(self.boss.global_undo.previous_container)
            else:
                # Show the user what changes we have made, allowing her to
                # revert them if necessary
                self.boss.show_current_diff()
                # Update the editor UI to take into account all the changes we
                # have made
                self.boss.apply_container_update_to_gui()

    def magnify_fonts(self, factor):
        # Magnify all font sizes defined in the book by the specified factor
        # First we create a restore point so that the user can undo all changes
        # we make.
        self.boss.add_savepoint('Before: Magnify fonts')

        container = self.current_container  # The book being edited as a container object

        # Iterate over all style declarations in the book, this means css
        # stylesheets, <style> tags and style="" attributes
        for name, media_type in container.mime_map.items():
            if media_type in OEB_STYLES:
                # A stylesheet. Parsed stylesheets are css_parser CSSStylesheet
                # objects.
                self.magnify_stylesheet(container.parsed(name), factor)
                container.dirty(name)  # Tell the container that we have changed the stylesheet
            elif media_type in OEB_DOCS:
                # A HTML file. Parsed HTML files are lxml elements

                for style_tag in container.parsed(name).xpath('//*[local-name="style"]'):
                    if style_tag.text and style_tag.get('type', None) in {None, 'text/css'}:
                        # We have an inline CSS <style> tag, parse it into a
                        # stylesheet object
                        sheet = container.parse_css(style_tag.text)
                        self.magnify_stylesheet(sheet, factor)
                        style_tag.text = serialize(sheet, 'text/css', pretty_print=True)
                        container.dirty(name)  # Tell the container that we have changed the stylesheet
                for elem in container.parsed(name).xpath('//*[@style]'):
                    # Process inline style attributes
                    block = container.parse_css(elem.get('style'), is_declaration=True)
                    self.magnify_declaration(block, factor)
                    elem.set('style', force_unicode(block.getCssText(separator=' '), 'utf-8'))

    def magnify_stylesheet(self, sheet, factor):
        # Magnify all fonts in the specified stylesheet by the specified
        # factor.
        for rule in sheet.cssRules.rulesOfType(CSSRule.STYLE_RULE):
            self.magnify_declaration(rule.style, factor)

    def magnify_declaration(self, style, factor):
        # Magnify all fonts in the specified style declaration by the specified
        # factor
        val = style.getPropertyValue('font-size')
        if not val:
            return
        # see if the font-size contains a number
        num = re.search(r'[0-9.]+', val)
        if num is not None:
            num = num.group()
            val = val.replace(num, '%f' % (float(num) * factor))
            style.setProperty('font-size', val)
        # We should also be dealing with the font shorthand property and
        # font sizes specified as non numbers, but those are left as exercises
        # for the reader

`` Main.py`` ஐ உடைப்போம். *பெயரிடப்பட்ட ஒரு கருவியை இது வரையறுக்கிறது என்பதை நாங்கள் காண்கிறோம் *எழுத்துருக்களை பெரிதாக்குங்கள் *. இந்த கருவி பயனரைக் கேட்கும் மற்றும் புத்தகத்தில் உள்ள அனைத்து எழுத்துரு அளவுகளையும் அந்த எண்ணால் பெருக்கும்.

முதல் முக்கியமான விஷயம் என்னவென்றால், நீங்கள் ஒப்பீட்டளவில் சில தனித்துவமான சரத்திற்கு அமைக்க வேண்டிய கருவி பெயர், ஏனெனில் இது இந்த கருவிக்கான விசையாக பயன்படுத்தப்படும்.

அடுத்த முக்கியமான நுழைவு புள்ளி: meth: calibre.gui2.tweak_book.plugin.tool.create_action. இந்த முறை செருகுநிரல்கள் கருவிப்பட்டி மற்றும் சொருகி மெனுவில் தோன்றும் QACTION பொருள்களை உருவாக்குகிறது. இது, விருப்பமாக, பயனர் தனிப்பயனாக்கக்கூடிய விசைப்பலகை குறுக்குவழியை ஒதுக்குகிறது. Qaction இலிருந்து தூண்டப்பட்ட சமிக்ஞை ASK_USER () முறையுடன் இணைக்கப்பட்டுள்ளது, இது பயனரிடம் எழுத்துரு அளவு பெருக்கியைக் கேட்கிறது, பின்னர் உருப்பெருக்கக் குறியீட்டை இயக்குகிறது.

உருப்பெருக்கக் குறியீடு நன்கு கருத்து மற்றும் மிகவும் எளிமையானது. கவனிக்க வேண்டிய முக்கிய விஷயங்கள் என்னவென்றால், நீங்கள் எடிட்டர் சாளரத்திற்கு ஒரு குறிப்பை `` self.gui`` மற்றும் ஆசிரியர் * முதலாளி * `` self.boss`` எனப் பெறுவீர்கள். * முதலாளி * என்பது எடிட்டர் பயனர் இடைமுகத்தை கட்டுப்படுத்தும் பொருள். இது பல பயனுள்ள முறைகளைக் கொண்டுள்ளது, அவை ஆவணப்படுத்தப்பட்டுள்ளன: வகுப்பில்: calibre.gui2.tweak_book.boss.boss வகுப்பில்.

இறுதியாக, `` self.current_container`` உள்ளது, இது புத்தகத்தை ஒரு: வகுப்பு: calibre.ebooks.ob.polish.container.container பொருள் என திருத்தியதற்கான குறிப்பு. இது புத்தகத்தை அதன் தொகுதி HTML/CSS/படக் கோப்புகளின் தொகுப்பாகக் குறிக்கிறது மற்றும் பல பயனுள்ள விஷயங்களைச் செய்வதற்கான வசதியான முறைகளைக் கொண்டுள்ளது. உங்கள் சொருகி குறியீட்டில் மீண்டும் பயன்படுத்தக்கூடிய கொள்கலன் பொருள் மற்றும் பல்வேறு பயனுள்ள பயன்பாட்டு செயல்பாடுகள் ஆவணப்படுத்தப்பட்டுள்ளன: Ref: Polish_api.

உங்கள் சொருகி மொழிபெயர்ப்புகளைச் சேர்ப்பது

உங்கள் சொருகி மொழிபெயர்க்கப்பட்ட மற்றும் முக்கிய காலிபர் பயனர் இடைமுகத்திற்கு அமைக்கப்பட்ட எந்த மொழியிலும் காண்பிக்கப்படும் அனைத்து பயனர் இடைமுக சரங்களையும் நீங்கள் வைத்திருக்கலாம்.

முதல் படி, உங்கள் சொருகி மூலக் குறியீட்டைக் கடந்து, அனைத்து பயனர் புலப்படும் சரங்களையும் மொழிபெயர்க்கக்கூடியதாகக் குறிக்கவும், அவற்றை _ () இல் சுற்றி வருவதன் மூலம். உதாரணத்திற்கு:

action_spec = (_('My plugin'), None, _('My plugin is cool'), None)

உங்கள் சொருகி மூலக் குறியீட்டிலிருந்து .po கோப்புகளை உருவாக்க சில நிரலைப் பயன்படுத்தவும். நீங்கள் மொழிபெயர்க்க விரும்பும் ஒவ்வொரு மொழிக்கும் ஒன்று .po கோப்பு இருக்க வேண்டும். எடுத்துக்காட்டாக: ஜெர்மன் -க்கு DE.PO, பிரஞ்சு மற்றும் பலவற்றிற்கான fr.po. இதற்காக நீங்கள் `போய்டிட் <https://poedit.net/> _ _ நிரலைப் பயன்படுத்தலாம்.

இந்த .po கோப்புகளை உங்கள் மொழிபெயர்ப்பாளர்களுக்கு அனுப்பவும். அவற்றை திரும்பப் பெற்றவுடன், அவற்றை .mo கோப்புகளில் தொகுக்கவும். அதற்காக நீங்கள் மீண்டும் போய்டிட்டைப் பயன்படுத்தலாம், அல்லது செய்யுங்கள்

calibre-debug -c "from calibre.translations.msgfmt import main; main()" filename.po

.Mo கோப்புகளை உங்கள் சொருகி `` மொழிபெயர்ப்புகள்` கோப்புறையில் வைக்கவும்.

உங்கள் சொருகி .py கோப்புகளின் மேற்புறத்தில் load_translations () என்ற செயல்பாட்டை வெறுமனே அழைப்பது கடைசி கட்டமாகும். செயல்திறன் காரணங்களுக்காக நீங்கள் இந்த செயல்பாட்டை மட்டுமே அந்த .py கோப்புகளில் மட்டுமே அழைக்க வேண்டும், அவை உண்மையில் மொழிபெயர்க்கக்கூடிய சரங்களைக் கொண்டுள்ளன. எனவே ஒரு பொதுவான பயனர் இடைமுக சொருகியில் நீங்கள் அதை `` ui.py`` இன் மேலே அழைப்பீர்கள், ஆனால் __init __. Py`.

பயனர் இடைமுக மொழியை காலிபரில் மாற்றுவதன் மூலம் உங்கள் செருகுநிரல்களின் மொழிபெயர்ப்புகளை நீங்கள் சோதிக்கலாம்: கிலாபெல்: `விருப்பத்தேர்வுகள்-> இடைமுகம்-> பாருங்கள் உதாரணத்திற்கு:

CALIBRE_OVERRIDE_LANG=de

நீங்கள் சோதிக்க விரும்பும் மொழியின் மொழிக் குறியீட்டைக் கொண்டு `` டி`` ஐ மாற்றவும்.

பன்மை உடனான மொழிபெயர்ப்புகளுக்கு, `` _ () `` க்கு பதிலாக `` ngettext () `செயல்பாட்டைப் பயன்படுத்தவும். உதாரணத்திற்கு:

ngettext('Delete a book', 'Delete {} books', num_books).format(num_books)

சொருகி API

நீங்கள் மேலே கவனித்திருக்கலாம், காலிபரில் ஒரு சொருகி ஒரு வகுப்பு. வெவ்வேறு வகையான செருகுநிரல்களுக்கு வெவ்வேறு வகுப்புகள் உள்ளன. அனைத்து செருகுநிரல்களின் அடிப்படை வகுப்பு உட்பட ஒவ்வொரு வகுப்பிலும் உள்ள விவரங்களை இதில் காணலாம்: குறிப்பு: செருகுநிரல்கள்.

உங்கள் சொருகி கிட்டத்தட்ட காலிபரிலிருந்து குறியீட்டைப் பயன்படுத்தப் போகிறது. காலிபர் குறியீடு தளத்தில் பல்வேறு செயல்பாடுகளை எவ்வாறு கண்டுபிடிப்பது என்பதை அறிய, காலிபரில் உள்ள பகுதியைப் படியுங்கள்: ref: code_layout.

பிழைத்திருத்த செருகுநிரல்கள்

முதல், மிக முக்கியமான படி பிழைத்திருத்த பயன்முறையில் காலிபரை இயக்குவது. கட்டளை வரியிலிருந்து இதை நீங்கள் செய்யலாம்

calibre-debug -g

.

கட்டளை வரியிலிருந்து இயங்கும் போது, பிழைத்திருத்த வெளியீடு கன்சோலுக்கு அச்சிடப்படும், காலிபருக்குள் இருந்து இயங்கும் போது வெளியீடு ஒரு TXT கோப்புக்கு செல்லும்.

உங்கள் சொருகி குறியீட்டில் எங்கும் அச்சு அறிக்கைகளை நீங்கள் செருகலாம், அவை பிழைத்திருத்த பயன்முறையில் வெளியீடாக இருக்கும். நினைவில் கொள்ளுங்கள், இது பைதான், பிழைத்திருத்தத்திற்கு அச்சு அறிக்கைகளைத் தவிர வேறு எதுவும் உங்களுக்கு தேவையில்லை;) இந்த பிழைத்திருத்த நுட்பத்தைப் பயன்படுத்தி எல்லா திறன்களையும் உருவாக்கினேன்.

பின்வரும் கட்டளை வரியைப் பயன்படுத்தி உங்கள் சொருகி மாற்றங்களை விரைவாக சோதிக்கலாம்

calibre-debug -s; calibre-customize -b /path/to/your/plugin/folder; calibre

இது இயங்கும் காலிபரை நிறுத்திவிடும், பணிநிறுத்தம் முடிவடையும் வரை காத்திருங்கள், பின்னர் உங்கள் சொருகி காலிபரில் புதுப்பித்து, காலிபர் காலிபர்.

மேலும் சொருகி எடுத்துக்காட்டுகள்

பல அதிநவீன காலிபர் செருகுநிரல்களின் பட்டியலை நீங்கள் காணலாம் இங்கே <https://www.mobileered.com/forums/showthread.php?t=118764> _.

உங்கள் செருகுநிரல்களை மற்றவர்களுடன் பகிர்ந்து கொள்ளுங்கள்

நீங்கள் உருவாக்கிய செருகுநிரல்களை காலிபரின் பிற பயனர்களுடன் பகிர்ந்து கொள்ள விரும்பினால், உங்கள் சொருகி ஒரு புதிய நூலில் `காலிபர் செருகுநிரல்கள் மன்றத்தில் <https://www.mobileered.com/forums/forumdisplay.php?f=237 இல் இடுங்கள் > `_.