View Single Post
Old 11-21-2020, 07:52 AM   #4
capink
Evangelist
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 466
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Early feedback: One small feature that seems to be missing is the ability to add a descriptor/label to actions.
Yes. I realized this after I've done it. First I needed to change the order of some actions, so I added drag and drop, but it is not perfect because it does not have visual indication of what is being dragged. So I thought adding identifiers might help.

I am thinking about rewriting it as a table to add identifiers and make changing order easier.

Quote:
Originally Posted by ownedbycats View Post
Also, I found it's helpful to add a Calibre Action to toggle mark on all the books before starting a chain, and then at the very end setting a search to marked:true.
Nice. At least some extra use for Calibre Actions

Quote:
Originally Posted by ownedbycats View Post
A small suggestion: It might be a good idea to have a custom action to prompt for confirmation for more...destructive action chains, and pressing "no" would halt the entire thing. I guess this could be made with a module though I'm not sure how.
As I pointed out in first post, I have not yet settled on how to deal with the control flow. But your request is simple enough to be used as demonstration of how to write custom actions, so here it is:

Code:
from PyQt5.Qt 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; 03-23-2021 at 01:27 PM. Reason: typos
capink is online now   Reply With Quote