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 08-06-2021, 06:25 PM   #631
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,746
Karma: 30237526
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Lightbulb Invoke an Action Chain on Add

@capink - Any thoughts as to feasibility?

Apologies if it already exists

BR

Last edited by BetterRed; 08-06-2021 at 06:27 PM.
BetterRed is offline   Reply With Quote
Old 08-06-2021, 07:31 PM   #632
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Only on the "add books" action, or also autoadd from a folder?
ownedbycats is offline   Reply With Quote
Advert
Old 08-07-2021, 03:41 AM   #633
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by BetterRed View Post
@capink - Any thoughts as to feasibility?

Apologies if it already exists

BR
If you want the chain to be triggered on auto-add as suggested by @ownedbycats, that would need a modification to calibre source to insert the necessary signal.

On the other hand, if you want this when adding books manually, you can have a chain where the add action (through Calibre Actions) is at the top followed by any other actions you want after it. if you choose to go down this route, not the following:
  • When you configure "Calibre Actions", you need to tick the option: "wait until any progress bar shown by action finishes".
  • You probably want all the newly added books to be selected so that other actions in the chain work on them. To do this, add a "Selection Modifier" action right after the "Calibre Actions" action, and tick the option "Select books modified by last action"

Now whenever you want to add books, you click on this chain and it will open Add Books file dialog where you select the books you want as usual. After all books are added, all other actions in the chain will run.
capink is offline   Reply With Quote
Old 08-07-2021, 05:00 AM   #634
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
For future reference, is there a less tedious way to change multiple submenu entries? Selecting multiple chains and using F2 just modified the last one selected.
ownedbycats is offline   Reply With Quote
Old 08-07-2021, 05:05 AM   #635
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,746
Karma: 30237526
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by capink View Post
If you want the chain to be triggered on auto-add as suggested by @ownedbycats, that would need a modification to calibre source to insert the necessary signal.

On the other hand, if you want this when adding books manually, you can have a chain where the add action (through Calibre Actions) is at the top followed by any other actions you want after it. if you choose to go down this route, not the following:
  • When you configure "Calibre Actions", you need to tick the option: "wait until any progress bar shown by action finishes".
  • You probably want all the newly added books to be selected so that other actions in the chain work on them. To do this, add a "Selection Modifier" action right after the "Calibre Actions" action, and tick the option "Select books modified by last action"

Now whenever you want to add books, you click on this chain and it will open Add Books file dialog where you select the books you want as usual. After all books are added, all other actions in the chain will run.
I initiate adding books to calibre libraries from Windows, not from calibre itself. Either via a shortcut to calibre.exe I have in the Windows->File Explorer->Send To folder, or via DnD from the Desktop to the Book list.

I avoid dialogue boxes almost as much as I avoid the mouse - maybe even more. One of the first things I did when I started with calibre was to find ways of dodging some of its dialogue boxes - such as Add books and Metadata edit.

So, what I had in mind was a variant of Action Chains (or a wrapper) that ran as File Type plugin - a'la the GetFileName and deDRM plugins.

Don't treat this as a request - it was just an early morning idea that popped into my head and jumped onto the keyboard.


But on another tangent - is what you wrote in November still true ==>> 20. i.e. Conversions can't be initiated from an Action Chain.

BR
BetterRed is offline   Reply With Quote
Advert
Old 08-07-2021, 05:29 AM   #636
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by BetterRed View Post
I initiate adding books to calibre libraries from Windows, not from calibre itself. Either via a shortcut to calibre.exe I have in the Windows->File Explorer->Send To folder, or via DnD from the Desktop to the Book list.

I avoid dialogue boxes almost as much as I avoid the mouse - maybe even more. One of the first things I did when I started with calibre was to find ways of dodging some of its dialogue boxes - such as Add books and Metadata edit.

So, what I had in mind was a variant of Action Chains (or a wrapper) that ran as File Type plugin - a'la the GetFileName and deDRM plugins.

Don't treat this as a request - it was just an early morning idea that popped into my head and jumped onto the keyboard.
Never thought about this. I have no experience with File Type plugins. I will have a look when I have some time to spare.


Quote:
Originally Posted by BetterRed View Post
But on another tangent - is what you wrote in November still true ==>> 20. i.e. Conversions can't be initiated from an Action Chain.

BR
This problem was solved in version 1.5.0. You now can initiate conversions from Action Chains using "Calibre Actions". Note that you have to tick the option "wait until any job started by the selected action finishes"
capink is offline   Reply With Quote
Old 08-07-2021, 05:54 AM   #637
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
For future reference, is there a less tedious way to change multiple submenu entries? Selecting multiple chains and using F2 just modified the last one selected.
Currently no. I will look into this for the next release.
capink is offline   Reply With Quote
Old 08-07-2021, 06:28 AM   #638
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks. One way I can see is when changing a submenu entry, check for other ones and then offer to change them. I suspect this might get annoying if you're just moving some to a different submenu though.
ownedbycats is offline   Reply With Quote
Old 08-07-2021, 07:12 AM   #639
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Thanks. One way I can see is when changing a submenu entry, check for other ones and then offer to change them. I suspect this might get annoying if you're just moving some to a different submenu though.
Pressing F2 with multiple selections and active cell is submenu > pop up an input dialog.
capink is offline   Reply With Quote
Old 08-07-2021, 12:48 PM   #640
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
@BetterRed

Here is another method of achieving what you want, you need to add the following custom event (Manage modules > add module > copy paste the code below):

Code:
from functools import partial

# python 3 compatibility
from six import text_type as unicode

from PyQt5.Qt import (QApplication, Qt, QTimer, QWidget, QVBoxLayout, QCheckBox, pyqtSignal)

from calibre import prints
from calibre.constants import DEBUG
from calibre.db.listeners import EventType
from calibre.utils.date import now

from calibre_plugins.action_chains.events.base import ChainEvent
import calibre_plugins.action_chains.config as cfg

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.setLayout(l)

        self.select_chk = QCheckBox(_('Select newly added books'))
        self.select_chk.setChecked(True)
        l.addWidget(self.select_chk)
        
        l.addStretch(1)

        self.setMinimumSize(300,300)

    def load_settings(self, settings):
        if settings:
            self.select_chk.setChecked(settings['select_books'])

    def save_settings(self):
        settings = {}
        settings['select_books'] = self.select_chk.isChecked()
        return settings

class BooksAddedEvent(ChainEvent):

    name = 'Books Added'
    books_added = pyqtSignal(object)
    timer_interval = 30

    def __init__(self, plugin_action):
        ChainEvent.__init__(self, plugin_action)
        self.db = plugin_action.gui.current_db
        self.gui.add_db_listener(self.process_event_in_db)
        self.book_created_cache = set()
        self.book_created_cache_last_updated = None
        QTimer.singleShot(self.timer_interval * 1000, self._on_timeout)

    def process_event_in_db(self, db, event_type, event_data):
        if not db.library_id == self.gui.current_db.library_id:
            return
        if event_type == EventType.book_created:
            book_id = event_data[0]
            self.add_to_book_created_cache(book_id, now())
        elif event_type == EventType.books_removed:
            removed_book_ids = event_data[0]
            self.book_created_cache = self.book_created_cache.difference(set(removed_book_ids))
        
    def _on_timeout(self):
        # Make sure no modal widget dialog is present (e.g. add books duplicate dialog). Otherwise, postpone
        if QApplication.instance().activeModalWidget():
            pass
        # postpone event if another action chains is running
        elif self.plugin_action.chainStack:
            pass
        else:
            utime = self.book_created_cache_last_updated
            if utime:
                elapsed = now() - utime
                if elapsed.seconds > 20:
                    QTimer.singleShot(0, partial(self.books_added.emit, self.book_created_cache))
                    QTimer.singleShot(0, self.clean_book_created_cache)
        
        # keep the timer runnig
        QTimer.singleShot(self.timer_interval * 1000, self._on_timeout) 

    def add_to_book_created_cache(self, book_id, timestamp):
        self.book_created_cache.add(book_id)
        self.book_created_cache_last_updated = timestamp

    def clean_book_created_cache(self):
        self.book_created_cache = set()
        self.book_created_cache_last_updated = None
    
    def get_event_signal(self):
        return self.books_added

    def config_widget(self):
        return ConfigWidget

    def pre_chains_event_actions(self, event_args, event_opts):
        if event_opts.get('select_books', False):
            book_ids = event_args[0]
            self.gui.library_view.select_rows(book_ids)
            if DEBUG:
                prints('Action Chains: Books Added Event: Selecting newly added book_ids: {}')
After adding this you should have an event called "Books Added" in the dropdown list of the Event Manager. You can attach whatever chains you want to that event.

Notes:
  • The event will automatically select all added books, so that any chains attached to the event can act on them. If whatever reason you don't want this, you can turn it off (Event Manager > Books Added > Event optinos)
  • There is a lag of several seconds before the event is activated. This is done to ensure calibre's adder (and auto-adder) has added all the books.
  • You can attach one or more chain(s) to the event: Event Manager > Add Event > Books Added > click settings button next to the event.
  • Whenever you change the name of a chain attached to an event, you will need to open the Event Manager to re-attach it.

Edit: The solution above is updated to work with auto-add. The File Type plugin solution could work, but it will need a separate plugin, also it will invoke the chain once after each book is added instead of waiting for all books before running the chain.

Edit2: The solution above is updated to be more cleaner:
  • It no longer monkeypatches calibre code.
  • It waits for all books to be added, and then releases one event for all added books, instead of a separate event per book.
  • This will only work with Action Chains version >= 1.11.1

Last edited by capink; 08-17-2021 at 03:39 PM.
capink is offline   Reply With Quote
Old 08-11-2021, 03:27 AM   #641
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,012
Karma: 75555555
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is there a way to account for Power Search's dialog in an action chain?

Click image for larger version

Name:	2021-08-11 04_23_27-Power Search.png
Views:	419
Size:	7.5 KB
ID:	188633

I wanted to see if I could make a chain to search a term and then pass on the marked books to Agent Ransack.

Unfortunately even with the two "wait" options selected, it immediately tries to execute the other actions after opening the dialog and fails because there aren't any marked books yet.
ownedbycats is offline   Reply With Quote
Old 08-11-2021, 04:30 AM   #642
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I don't use the plugin so I don't know what is happening there. The wait option is intended for actions that launch progress bars.

Last edited by capink; 08-11-2021 at 04:43 AM.
capink is offline   Reply With Quote
Old 08-11-2021, 05:47 PM   #643
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,746
Karma: 30237526
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by capink View Post
@BetterRed

Here is another method of achieving what you want:

Add the following custom event to Action Chains module editor

[ . . . ]

Edit: The solution above is updated to work with auto-add. The Filetype plugin solution could work, but it will need a separate plugin, also it will invoke the chain once after each book is added instead of waiting for all books before running the chain.
I tried this and it works - but whether I'll use it is uncertain, I still have to eyeball check the results, but at the end rather than progressively, which goes against my grain.

BR
BetterRed is offline   Reply With Quote
Old 08-13-2021, 08:39 AM   #644
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,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Version 1.10.0

  • Update: Events: Add "Book List Enter Key Pressed" Event.
  • Update: Events: Rename "Library View Double Clicked" into "Book List Double Clicked". The event now responds to double clicks on the cover grid as well.
  • Update: Events: Add "Timer" event. This timer is activated every 5 minutes (can be configured by: Preferences > Plugins > Action Chains > Customize Plugin) for chains that should do automatic tasks at regular intervals.
  • Update: Chains Dialog: Pressing F2 with multiple selections when active cell is submenu will pop up an input dialog to batch change the submenu for all selected entries.

Last edited by capink; 08-13-2021 at 08:44 AM.
capink is offline   Reply With Quote
Old 08-16-2021, 08:06 AM   #645
bob.f
Connoisseur
bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!bob.f has a thesaurus and is not afraid to use it!
 
Posts: 78
Karma: 99068
Join Date: Nov 2017
Device: N/A
1.11 prevents my Calibre 5.25 from starting.
bob.f is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 PM
Action Chains Resources capink Plugins 77 06-16-2025 12:45 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 07:16 AM.


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