View Single Post
Old 03-26-2021, 05:07 AM   #443
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: 11,052
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by capink View Post
That is certainly not intended and is not happening for me. I need your copy of [CALIBRE CONFIG DIR]/plugins/action_chains/action-chains-user-modules.json to investigate this.
Here both file and code

Code:
{
  "Confirmation": "from PyQt5.Qt import QWidget, QVBoxLayout, QGroupBox, QTextEdit\n\nfrom calibre.gui2 import question_dialog\nfrom calibre_plugins.action_chains.actions.base import ChainAction\n\nclass ConfirmConfigWidget(QWidget):\n    def __init__(self, plugin_action):\n        QWidget.__init__(self)\n        self._init_controls()\n\n    def _init_controls(self):\n\n        l = QVBoxLayout()\n        self.setLayout(l)\n\n        gb = QGroupBox('Confirm message')\n        gb_l = QVBoxLayout()\n        gb.setLayout(gb_l)\n\n        self.tb = QTextEdit()\n        self.tb.insertPlainText('Are you sure you want to proceed?')\n\n        gb_l.addWidget(self.tb)\n        l.addWidget(gb)\n\n    def load_settings(self, settings):\n        if settings:\n            self.tb.setText(settings['message'])\n\n    def save_settings(self):\n        settings = {}\n        settings['message'] = self.tb.toPlainText()\n        return settings\n\nclass MyAction(ChainAction):\n\n    name = 'Confirm'\n\n    def config_widget(self):\n        return ConfirmConfigWidget\n\n    def run(self, gui, settings, chain_loop):\n        message = settings.get('message', 'Are you sure you want to proceed?')\n        if not question_dialog(gui, _('Are you sure?'), message, show_copy_button=False):\n            raise chain_loop.UserInterrupt\n",
  "Open Tag Manager": "from PyQt5.Qt import (QApplication, Qt, QWidget, QVBoxLayout, QGroupBox, QComboBox)\n\nfrom calibre.gui2.dialogs.tag_editor import TagEditor\nfrom calibre_plugins.action_chains.actions.base import ChainAction\n\ndef get_possible_cols(db):\n    fm = db.field_metadata.custom_field_metadata()\n    cols = [ col for col, cmeta in fm.items() if cmeta['is_multiple'] ]\n    cols = [ col for col in cols if fm[col]['datatype'] not in ['composite',None] ]\n    cols.insert(0, 'tags')\n    return cols\n\nclass ItemEditorConfig(QWidget):\n    def __init__(self, plugin_action):\n        QWidget.__init__(self)\n        self.plugin_action = plugin_action\n        self.gui = plugin_action.gui\n        self.db = self.gui.current_db\n        self.possible_cols = self.get_possible_cols()\n        self._init_controls()\n\n    def _init_controls(self):\n        self.blockSignals(True)\n        l = QVBoxLayout()\n        self.setLayout(l)\n\n        col_box = QGroupBox(_('Choose column:'))\n        col_box_layout = QVBoxLayout()\n        col_box.setLayout(col_box_layout)\n        self.col_combobox = QComboBox()\n        self.col_combobox.addItems(self.possible_cols)\n        self.col_combobox.setCurrentText('tags')\n        col_box_layout.addWidget(self.col_combobox)\n        l.addWidget(col_box)   \n\n        l.addStretch(1)\n        self.setMinimumSize(300,200)\n        self.blockSignals(False)\n\n    def get_possible_cols(self):\n        return get_possible_cols(self.db)\n\n    def load_settings(self, settings):\n        if settings:\n            self.col_combobox.setCurrentText(settings['col_name'])\n\n    def save_settings(self):\n        settings = {}\n        settings['col_name'] = self.col_combobox.currentText()\n        return settings\n\nclass ItemEditorAction(ChainAction):\n\n    name = 'Open Tag Manager'\n\n    def run(self, gui, settings, chain_loop):\n        db = gui.current_db\n        rows = gui.current_view().selectionModel().selectedRows()\n        book_ids = [ gui.library_view.model().db.id(row.row()) for row in rows ]\n\n        col_name = settings['col_name']\n        if col_name == 'tags':\n            key = None\n        else:\n            key = col_name\n        \n        if len(book_ids) == 0:\n            return\n        elif len(book_ids) == 1:\n            book_id = book_ids[0]\n        else:\n            book_id = None\n\n        d = TagEditor(gui, db, book_id, key)\n        QApplication.setOverrideCursor(Qt.ArrowCursor)\n        try:\n            d.exec_()\n        finally:\n            QApplication.restoreOverrideCursor()\n        if d.result() == d.Accepted:\n            val = d.tags\n            id_map = {book_id: val for book_id in book_ids}\n            db.new_api.set_field(col_name, id_map)\n\n        del d\n\n    def config_widget(self):\n        return ItemEditorConfig\n\n    def validate(self, settings):\n        gui = self.plugin_action.gui\n        db = gui.current_db\n        if not settings:\n            return (_('Settings Error'), _('You must configure this action before running it'))\n        col_name = settings['col_name']\n        if not col_name in get_possible_cols(db):\n            return (_('Column Error'), _('Cannot find a column with name \"{}\" in current library'.format(col_name)))\n        return True",
  "Resort View": "from calibre_plugins.action_chains.actions.base import ChainAction\n\nclass RefreshAction(ChainAction):\n\n    name = 'Refresh View'\n\n    def run(self, gui, settings, chain_loop):\n        gui.current_view().resort()",
  "view_manager_last_view": "from calibre_plugins.action_chains.templates import TemplateFunction\n\nclass ViewManagerLastVIew(TemplateFunction):\n\n    name = 'view_manager_last_view'\n    arg_count = 0\n\n    def evaluate(self, formatter, kwargs, mi, locals):\n        import calibre_plugins.view_manager.config as cfg\n        gui = self.plugin_action.gui\n        library_config = cfg.get_library_config(gui.current_db)\n        return library_config.get(cfg.KEY_LAST_VIEW, '')"
}
Attached Files
File Type: zip action-chains-user-modules.zip (1.7 KB, 538 views)
ownedbycats is offline   Reply With Quote