View Single Post
Old 01-29-2022, 08:06 PM   #25
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 8,639
Karma: 61234567
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Prompt for Action

Modified from 'Prompt for Confirmation' (thanks to capink for assistance) is "Prompt for Action,' to enable selected actions using a yes/no prompt.

Code:
from qt.core import QWidget, QVBoxLayout, QGroupBox, QTextEdit

from calibre.gui2 import question_dialog
from calibre_plugins.action_chains.actions.base import ChainAction

class ConfirmConfigWidget(QWidget):
    def __init__(self, plugin_action):
        QWidget.__init__(self)
        self._init_controls()

    def _init_controls(self):

        l = QVBoxLayout()
        self.setLayout(l)

        gb = QGroupBox('Confirm message')
        gb_l = QVBoxLayout()
        gb.setLayout(gb_l)

        self.tb = QTextEdit()
        self.tb.insertPlainText('Do you want to run the next action?')

        gb_l.addWidget(self.tb)
        l.addWidget(gb)

    def load_settings(self, settings):
        if settings:
            self.tb.setText(settings['message'])

    def save_settings(self):
        settings = {}
        settings['message'] = self.tb.toPlainText()
        return settings

class ConfirmAction(ChainAction):

    name = 'Prompt for Action'

    def config_widget(self):
        return ConfirmConfigWidget

    def run(self, gui, settings, chain):
        message = settings.get('message', 'Do you want to run the next action?')
        if question_dialog(gui, _('Are you sure?'), message, show_copy_button=False):
            chain.set_chain_vars({'prompt_action': 'Yes'})

Place the module action somewhere in the chain, obviously before the action you wish to prompt for, and then add the

program: globals(prompt_action)
text = Yes


condition to the actions you wish to prompt for.

I've attached a sample chain for demonstration.
Attached Files
File Type: zip ViewBookOnYes.zip (618 Bytes, 153 views)

Last edited by capink; 01-30-2022 at 06:58 PM. Reason: Change import statement to qt.core
ownedbycats is offline   Reply With Quote