Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-24-2020, 05:24 PM   #181
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,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Edit: Will change the icon for the final release.

Last edited by capink; 12-24-2020 at 05:31 PM.
capink is offline   Reply With Quote
Old 12-24-2020, 05:38 PM   #182
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thank you.
ownedbycats is offline   Reply With Quote
Advert
Old 12-24-2020, 06:16 PM   #183
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Could the template conditions be used in place of selection modifiers?

In my fanfiction cleanup chain, I have a "Select AO3 books" modifier (publisher:"=Archive of Our Own"), then "Add ao3: modifiers" search & replace.

I'm thinking I could just tag the second action with a conditional to only run it if the template matches Archive of Our Own. Is this an intended use, or are there any problems with it I should know about?

Last edited by ownedbycats; 12-24-2020 at 06:19 PM.
ownedbycats is offline   Reply With Quote
Old 12-24-2020, 06:27 PM   #184
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,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
It is not going to work for two reasons, conditions work on a one metadata object (the first selected book, on an empty metadata object if no book is selected). This may or may not change in the future, but even if it does, if the books you want to apply actions to are not selected, conditions will not apply to them.
capink is offline   Reply With Quote
Old 12-24-2020, 06:35 PM   #185
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Ok, that makes sense. I just thought it might be nice to avoid the book list going a bit nuts when multiple selection modifiers are run in a chain (I know there's no real way around this).
ownedbycats is offline   Reply With Quote
Advert
Old 12-25-2020, 03:18 PM   #186
compurandom
Guru
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
Posts: 941
Karma: 418804
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
Wow, that's a lot of new neat features all at once! It'll take me a while to digest this, mostly because I have to upgrade everything and then test each feature.

I think this will let me merge a couple of action chains I've been running one at a time, and also remove a few more manual steps.

The danger of this is that eventually I won't remember what the chains do anymore or what steps I'm suppose to perform without them.
compurandom is offline   Reply With Quote
Old 12-25-2020, 04:03 PM   #187
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by compurandom View Post
The danger of this is that eventually I won't remember what the chains do anymore or what steps I'm suppose to perform without them.
I add comments to all my actions:

Click image for larger version

Name:	2020-12-25 17_02_17-Add actions.png
Views:	359
Size:	38.5 KB
ID:	184257
ownedbycats is offline   Reply With Quote
Old 12-25-2020, 04:27 PM   #188
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,961
Karma: 7225107
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
@chaley: since much of this was suggested by you, I would like to hear your feedback. This is still in test mode. I am not sure about Chain Variables action, the only redeeming thing about it; is that it allows setting dynamic values using templates. I also scrapped to two column solution, in favor of the template based Chains/Actions Conditions dialog.
I have been away for bit. I will look at this tomorrow, although it seems from other comments that what you built is satisfying a need.
chaley is offline   Reply With Quote
Old 12-25-2020, 04:28 PM   #189
compurandom
Guru
compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.compurandom ought to be getting tired of karma fortunes by now.
 
Posts: 941
Karma: 418804
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
Quote:
Originally Posted by ownedbycats View Post
I add comments to all my actions:
Yes, and I'm VERY greatful for that option. I comment the actions too.

The point though, is that action chains is going to make me lazy and I'll forget to the point where I'll just run the chain automatically, and if I have to run any part if it by hand I'll have to go back into the chain to remind myself of what it does.
compurandom is offline   Reply With Quote
Old 12-25-2020, 04:39 PM   #190
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Descriptive names, perhaps? Here's my own set of chains:

Click image for larger version

Name:	2020-12-25 17_35_39-.png
Views:	401
Size:	24.0 KB
ID:	184259
ownedbycats is offline   Reply With Quote
Old 12-25-2020, 10:22 PM   #191
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by capink View Post
Also, to make chains enabled only if one book is selected, use the Chain Conditions dialog as follows

Code:
template = program: globals(selection_count)
datatype = number
comparison = "="
condition value = 1
Again, this makes use of variables defined by the plugin and will not work outside Action Chains.
I attached this condition to a single field edit - ask at runtime action in one of my chains.

I selected a single book and went to restore the bookmark. It didn't activate. The other actions ran okay with both single and multiple books selected. I made sure the datatype, comparison, and value were all correct Is this condition only meant to run on full chains?

EDIT: moved agent ransack crap to new post

Last edited by ownedbycats; 12-26-2020 at 12:05 AM.
ownedbycats is offline   Reply With Quote
Old 12-26-2020, 12:05 AM   #192
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: 9,361
Karma: 63297233
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Also, how experimental is the "use multiple selections" feature? Agent Ransack fails to launch entirely with this:

Click image for larger version

Name:	2020-12-26 00_23_52-Open With.png
Views:	661
Size:	14.7 KB
ID:	184268

Code:
      {
        "active": true,
        "chain_settings": {
          "chain_links": [
            {
              "action_name": "Open With",
              "action_settings": {
                "allow_multiple": true,
                "args": "-d",
                "path_opt": "folder",
                "path_sep": ";",
                "path_to_binary": "C:\\Program Files\\Mythicsoft\\Agent Ransack\\AgentRansack.exe",
                "use_default_app": false
              },
              "comment": ""
            }
          ],
          "refresh_gui": true
        },
        "image": "",
        "menuText": "Search with Agent Ransack",
        "subMenu": ""
      },
This works in command prompt:
"C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe" -d "D:\Test1";"D:\Test2"

The action works if multiple selections is disabled.

Note that nothing appeared in Ransack's error log (it does if I send it a -d with no paths).

EDIT: Debug log:

Code:
Action Chains: Starting chain: Search with Agent Ransack
Action Chains: Search with Agent Ransack: starting action No. 1: Open With
Open:  C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe (file):  "D:\Documents\My Books\Jenny Oldfield\Starlight (5627)";"D:\Documents\My Books\Jenny Oldfield\Steamboat Charlie (5626)"  (args):  -d mutiple:  True
About to run a command: C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe
Job Spy: self.gui.tags_view.recount() is enhanced for showing icons of user category child values...
Action Chains: chain (Search with Agent Ransack) finished in: 0.2760617733001709
ANOTHER EDIT: Here's another debug log of opening a file with "multiple selections" turned off.

Code:
Action Chains: Starting chain: Search with Agent Ransack
Action Chains: Search with Agent Ransack: starting action No. 1: Open With
Open:  C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe (file):  D:\Documents\My Books\Jenny Oldfield\Steamboat Charlie (5626)  (args):  -d mutiple:  False
About to run a command: C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe
Job Spy: self.gui.tags_view.recount() is enhanced for showing icons of user category child values...
Action Chains: chain (Search with Agent Ransack) finished in: 0.2923429012298584

Last edited by ownedbycats; 12-26-2020 at 03:59 AM.
ownedbycats is offline   Reply With Quote
Old 12-26-2020, 05:53 AM   #193
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,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
I attached this condition to a single field edit - ask at runtime action in one of my chains.

I selected a single book and went to restore the bookmark. It didn't activate. The other actions ran okay with both single and multiple books selected. I made sure the datatype, comparison, and value were all correct Is this condition only meant to run on full chains?

EDIT: moved agent ransack crap to new post
I tried the above condition for a single field action and it ran as expected. When I have only one book selected it activated as normal. When I choose multiple books it does not activate, and it gives the following log:

Code:
Action Chains: Starting chain: single field ask at runtime
Action Chains: single field ask at runtime: Conditions are not met for action No. 1 (Single Field Edit)
Action Chains: chain (single field ask at runtime) finished in: 0.8641304969787598
I don't know why it is not working for you. Will later post a version that gives more details in the debug output to see what the problem is.

Last edited by capink; 01-19-2021 at 10:38 AM.
capink is offline   Reply With Quote
Old 12-26-2020, 06:17 AM   #194
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,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Also, how experimental is the "use multiple selections" feature? Agent Ransack fails to launch entirely with this:

Attachment 184268

Code:
      {
        "active": true,
        "chain_settings": {
          "chain_links": [
            {
              "action_name": "Open With",
              "action_settings": {
                "allow_multiple": true,
                "args": "-d",
                "path_opt": "folder",
                "path_sep": ";",
                "path_to_binary": "C:\\Program Files\\Mythicsoft\\Agent Ransack\\AgentRansack.exe",
                "use_default_app": false
              },
              "comment": ""
            }
          ],
          "refresh_gui": true
        },
        "image": "",
        "menuText": "Search with Agent Ransack",
        "subMenu": ""
      },
This works in command prompt:
"C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe" -d "D:\Test1";"D:\Test2"

The action works if multiple selections is disabled.

Note that nothing appeared in Ransack's error log (it does if I send it a -d with no paths).

EDIT: Debug log:

Code:
Action Chains: Starting chain: Search with Agent Ransack
Action Chains: Search with Agent Ransack: starting action No. 1: Open With
Open:  C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe (file):  "D:\Documents\My Books\Jenny Oldfield\Starlight (5627)";"D:\Documents\My Books\Jenny Oldfield\Steamboat Charlie (5626)"  (args):  -d mutiple:  True
About to run a command: C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe
Job Spy: self.gui.tags_view.recount() is enhanced for showing icons of user category child values...
Action Chains: chain (Search with Agent Ransack) finished in: 0.2760617733001709
ANOTHER EDIT: Here's another debug log of opening a file with "multiple selections" turned off.

Code:
Action Chains: Starting chain: Search with Agent Ransack
Action Chains: Search with Agent Ransack: starting action No. 1: Open With
Open:  C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe (file):  D:\Documents\My Books\Jenny Oldfield\Steamboat Charlie (5626)  (args):  -d mutiple:  False
About to run a command: C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe
Job Spy: self.gui.tags_view.recount() is enhanced for showing icons of user category child values...
Action Chains: chain (Search with Agent Ransack) finished in: 0.2923429012298584
The feature is experimental for different reasons, one of them is that I cannot cater to every possible program and every possible OS. I do not use Windows so I cannot debug this particular program.

However, from looking at your debug, one possible problem is that I did not account for program paths with spaces (missed this because it does not happen on linux). The version I will post later today will correct this by double quoting the program we are calling. If this does not help, I cannot offer much assistance with this.

Last edited by capink; 12-26-2020 at 07:22 AM.
capink is offline   Reply With Quote
Old 12-26-2020, 11:20 AM   #195
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,134
Karma: 1954142
Join Date: Aug 2015
Device: Kindle
Remove format(s) custom action

Code:
# calibre Python 3 compatibility.
import six
from six import text_type as unicode
from six.moves import range

from PyQt5.Qt import (Qt, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QFrame,
                      QGroupBox, QCheckBox, QLineEdit, QRadioButton)

from calibre.gui2.widgets2 import Dialog
from calibre.ebooks.metadata.meta import metadata_from_formats

from calibre_plugins.action_chains.actions.base import ChainAction

class ConfigWidget(QWidget):

    def __init__(self, plugin_action):
        QWidget.__init__(self)
        self.plugin_action = plugin_action
        self.gui = plugin_action.gui
        self.db = self.gui.current_db
        self._init_controls()

    def _init_controls(self):
        l = self.l = QVBoxLayout(self)
        self.setLayout(l)

        line = QFrame(self)
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)
        l.addWidget(line)
                
        group_box = QGroupBox(_('Formats options'))
        group_box_l = QVBoxLayout()
        group_box.setLayout(group_box_l)
        l.addWidget(group_box)
        
        self.all_opt = QRadioButton(_('Remove all formats'))
        self.all_opt.setChecked(True)
        group_box_l.addWidget(self.all_opt)

        self.include_opt = QRadioButton(_('Remove only specified formats (comma separated list)'))
        self.include_edit = QLineEdit()
        group_box_l.addWidget(self.include_opt)
        group_box_l.addWidget(self.include_edit)

        self.exclude_opt = QRadioButton(_('Remove all formats except spcefied (comma separated list)'))
        self.exclude_edit = QLineEdit()
        group_box_l.addWidget(self.exclude_opt)
        group_box_l.addWidget(self.exclude_edit)

        l.addStretch(1)   

    def load_settings(self, settings):
        if settings:
            if settings['opt'] == 'all':
                self.all_opt.setChecked(True)
            elif settings['opt'] == 'include':
                self.include_opt.setChecked(True)
                self.include_edit.setText(settings['include'])
            elif settings['opt'] == 'exclude':
                self.exclude_opt.setChecked(True)
                self.exclude_edit.setText(settings['exclude'])

    def save_settings(self):
        settings = {}
        if self.all_opt.isChecked():
            settings['opt'] = 'all'
        elif self.include_opt.isChecked():
            settings['opt'] = 'include'
            settings['include'] = self.include_edit.text()
        elif self.exclude_opt.isChecked():
            settings['opt'] = 'exclude'
            settings['exclude'] = self.exclude_edit.text()
        return settings

class RemoveFormats(ChainAction):

    name = 'Remove Formats'
    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:
            fmts_to_delete = set()
            fmts_string = db.formats(book_id, index_is_id=True)
            if fmts_string:
                available_fmts = [ fmt.strip().upper() for fmt in fmts_string.split(',') ]
            else:
                available_fmts = []
            if settings['remove_opt'] == 'all':
                if available_fmts:
                    fmts_to_delete = available_fmts
            elif settings['remove_opt'] == 'include':
                fmts_to_delete = [ fmt.strip().upper() for fmt in settings.get('include', '').split(',') ]
            elif settings['remove_opt'] == 'exclude':
                fmts_to_keep = set([ fmt.strip().upper() for fmt in settings.get('exclude', '').split(',') ])
                fmts_to_delete = set(available_fmts).difference(fmts_to_keep)
            for fmt in fmts_to_delete:
                fmt = fmt.upper()
                if fmt in available_fmts:
                    db.remove_format(book_id, fmt, index_is_id=True, notify=False)

    def default_settings(self):
        return {'opt': 'all'}

    def config_widget(self):
        return ConfigWidget

Last edited by capink; 08-26-2021 at 05:23 PM.
capink is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] Editor Chains capink Plugins 94 07-03-2024 07:26 PM
Action Chains Resources capink Plugins 65 07-01-2024 03:12 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 06:38 PM.


MobileRead.com is a privately owned, operated and funded community.