View Single Post
Old 07-13-2021, 06:17 AM   #616
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,092
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Hortensia View Post
I am attaching an image for easier explaination: the custom action you refers to is equivalent to clicking on the option I framed in red (that is at least what I understand) while I want a custom action equivalent to clicking on the option I framed in blue.

With the custom action you suggest, I have a cover I do not want in the ebook and I set this cover as the ebook cover. I need to generate the cover.
Try this:

Code:
from calibre.ebooks.covers import generate_cover
from calibre.gui2.covers import CoverSettingsWidget
from calibre_plugins.action_chains.actions.base import ChainAction

class ConfigWidget(CoverSettingsWidget):
    def __init__(self, plugin_action):
        CoverSettingsWidget.__init__(self)
        self.plugin_action = plugin_action
        self.gui = plugin_action.gui
        self.db = self.gui.current_db

    def load_settings(self, settings):
        self.apply_prefs(settings)

    def save_settings(self):
        return self.prefs_for_rendering

class GenerateCover(ChainAction):

    name = 'Generate Cover'
    support_scopes = True

    def run(self, gui, settings, chain):
        db = gui.current_db
        book_ids = chain.scope().get_book_ids()

        for book_id in book_ids:
            mi = db.get_metadata(book_id, index_is_id=True)
            cdata = generate_cover(mi, settings)
            db.new_api.set_cover({book_id:cdata})

    def config_widget(self):
        return ConfigWidget

Last edited by capink; 07-13-2021 at 06:45 AM.
capink is offline   Reply With Quote