View Single Post
Old 08-30-2021, 04:53 AM   #6
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,118
Karma: 1954138
Join Date: Aug 2015
Device: Kindle
Action to prompt for confirmation

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('Are you sure you want to proceed?')

        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 = 'Confirm'

    def config_widget(self):
        return ConfirmConfigWidget

    def run(self, gui, settings, chain):
        message = settings.get('message', 'Are you sure you want to proceed?')
        if not question_dialog(gui, _('Are you sure?'), message, show_copy_button=False):
            raise chain.UserInterrupt

Last edited by capink; 01-07-2022 at 06:09 AM.
capink is offline   Reply With Quote