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 07-13-2021, 06:17 AM   #616
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Hortensia View Post
I am attaching an image for easier explaination: the custom action you refers to is equivalent to clicking on the option I framed in red (that is at least what I understand) while I want a custom action equivalent to clicking on the option I framed in blue.

With the custom action you suggest, I have a cover I do not want in the ebook and I set this cover as the ebook cover. I need to generate the cover.
Try this:

Code:
from calibre.ebooks.covers import generate_cover
from calibre.gui2.covers import CoverSettingsWidget
from calibre_plugins.action_chains.actions.base import ChainAction

class ConfigWidget(CoverSettingsWidget):
    def __init__(self, plugin_action):
        CoverSettingsWidget.__init__(self)
        self.plugin_action = plugin_action
        self.gui = plugin_action.gui
        self.db = self.gui.current_db

    def load_settings(self, settings):
        self.apply_prefs(settings)

    def save_settings(self):
        return self.prefs_for_rendering

class GenerateCover(ChainAction):

    name = 'Generate Cover'
    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:
            mi = db.get_metadata(book_id, index_is_id=True)
            cdata = generate_cover(mi, settings)
            db.new_api.set_cover({book_id:cdata})

    def config_widget(self):
        return ConfigWidget

Last edited by capink; 07-13-2021 at 06:45 AM.
capink is offline   Reply With Quote
Old 07-13-2021, 06:41 AM   #617
Hortensia
Enthusiast
Hortensia began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Jul 2021
Device: Kindle Paperwhite, Kobo Libra 2
Quote:
Originally Posted by capink View Post
Try this:
It works perfectly
Hortensia is offline   Reply With Quote
Advert
Old 07-13-2021, 03:01 PM   #618
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
A possible slight bug:

While exporting a chain, I noticed that "current time" actually renders like this:

Code:
            {
              "action_name": "Single Field Edit",
              "action_settings": {
                "col_name": "#lastread",
                "value": [
                  {
                    "__class__": "datetime.datetime",
                    "__value__": "2021-03-30T00:13:43.637933+00:00"
                  },
                  true
                ],
                "value_type": "predefined"
              },
              "comment": "Set #lastread to current time"
            },
It's not letting me re-import it so I'm not sure if it's still checked as current time afterwards or not.
Attached Files
File Type: zip view.zip (927 Bytes, 337 views)
ownedbycats is offline   Reply With Quote
Old 07-13-2021, 03:44 PM   #619
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
A possible slight bug:

While exporting a chain, I noticed that "current time" actually renders like this:

Code:
            {
              "action_name": "Single Field Edit",
              "action_settings": {
                "col_name": "#lastread",
                "value": [
                  {
                    "__class__": "datetime.datetime",
                    "__value__": "2021-03-30T00:13:43.637933+00:00"
                  },
                  true
                ],
                "value_type": "predefined"
              },
              "comment": "Set #lastread to current time"
            },
It's not letting me re-import it so I'm not sure if it's still checked as current time afterwards or not.
The part highlighted in red will make sure it always sets to current time. Also this is an old chain (created by an older version), if you re-create it you will see it will not render the date anymore and will place a null instead.
capink is offline   Reply With Quote
Old 07-13-2021, 03:45 PM   #620
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks
ownedbycats is offline   Reply With Quote
Advert
Old 07-23-2021, 08:25 PM   #621
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
A strange bug I discovered, if you're able to replicate it:

While adding an icon for a chain, I renamed it to library.png. After doing this though it instead displayed the library.png that Calibre has in its resources/images folder. Upon a restart, it changed back to the icon I'd added.
ownedbycats is offline   Reply With Quote
Old 07-24-2021, 03:44 AM   #622
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
A strange bug I discovered, if you're able to replicate it:

While adding an icon for a chain, I renamed it to library.png. After doing this though it instead displayed the library.png that Calibre has in its resources/images folder. Upon a restart, it changed back to the icon I'd added.
Action Chains icon management is based on Open With Plugin. As such, it places new icons in calibre's image folder, so it is better to use unique names that does not clash with calibre stock icon names.

I have no intention of changing this right now, maybe I will revisit it in the future.
capink is offline   Reply With Quote
Old 07-24-2021, 04:42 AM   #623
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks.

New question: I added an action to my "mark fanfic as read on device" to remove the book from a certain reading list. To prevent it constantly popping up messages about books not being on the list, I attached this condition to it:

Code:
program:

	if
		$#readorder == 'To Be Read: In-Progress Fanfics'
	then
		'True'
	fi
Code:
text = True

Which... removed every book from that list. Oops. How do I change the template (and other gpms) to also specify only selected books?

Last edited by ownedbycats; 07-24-2021 at 04:50 AM.
ownedbycats is offline   Reply With Quote
Old 07-24-2021, 05:44 AM   #624
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I do not use Reading List so I do not follow what you are trying to do here. But here is a couple of points to consider:
  • As mentioned previously, the condition evaluator does not have access to all books metadata. Only the currently selected (active) book. So whatever test you are doing there will depend on the currently selected book. If the currently selected book meets the condition the action will run regardless of whether other books meets the condition or not.

    The condition evaluator is meant to test general conditions like selection_count ... etc. If you want it test against multiple book metadata you will have to use Chain Variables with the multiple check on, and then pass whatever results you want to the condition evaluator. But that is complicated enough so there no need to cover this now.
  • To solve the above problem, you can set a scope that limits to books meeting whatever criteria you want. For example using a search like this:
    Code:
    #readorder:"=To Be Read: In-Progress Fanfics"

Edit: Scopes do not work with Calibre Actions. Use the Selection Modifier instead.

Last edited by capink; 07-24-2021 at 06:00 AM.
capink is offline   Reply With Quote
Old 07-24-2021, 08:00 AM   #625
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I ran the chain against one book but for some reason all the books on that list got removed. I'll do some more testing when I'm less tired to see if it wasn't some user error.
ownedbycats is offline   Reply With Quote
Old 08-02-2021, 04:33 PM   #626
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Ok I did some more testing and wasn't able to replicate the "adding all books to the reading list" thing again. So I'm thinking I accidentally had all the books selected when it happened.

But a new queston: how do I make a condition on a Calibre action evaluate each book individually? I have an action to add a book to a Reading List under certain circumstances. It only works if I run it on one book at a time, though, or I suppose if all the books match (I've not had a chance to test that though).

Code:
{
              "action_name": "Calibre Actions",
              "action_settings": {
                "disable_busy_cursor": false,
                "selection": [
                  {
                    "display": "Add to list: To Be Read",
                    "path": [
                      "Reading List",
                      "Add to list",
                      "Add to list: To Be Read"
                    ]
                  }
                ],
                "wait_jobs": false,
                "wait_progress": false
              },
              "comment": "Add updated fanfics to reading list (TEMPLATE)",
              "condition_settings": {
                "affect_validation": false,
                "cmp_type": "=",
                "datatype": "text",
                "icon": "",
                "template": "program:\n\n\tif\n\t\t\t$#fanficcat\n\t\t&&\n\t\t\t$#currentlyreading\n\t\t&&\n\t\t\t$#readinglist != 'To Be Read'\n\t\t&&\n\t\t\t$$#percentread == '100'\n\tthen\n\t\t'True'\n\tfi",
                "tooltip": "",
                "value": "True"
              }
            },
Here's the condition without all the newlines:

Code:
program:

	if
			$#fanficcat
		&&
			$#currentlyreading
		&&
			$#readinglist != 'To Be Read'
		&&
			$$#percentread == '100'
	then
		'True'
	fi
Attached Files
File Type: zip SendToDevice.zip (6.1 KB, 326 views)

Last edited by ownedbycats; 08-02-2021 at 04:46 PM.
ownedbycats is offline   Reply With Quote
Old 08-02-2021, 04:42 PM   #627
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Don't use conditions, use the following search in the Selection Modifier to limit the view to the books meeting the criteria:

Code:
#fanficcat:true and #currentlyreading:true and #percentread:"=100" and not #readinglist:"=To Be Read"
capink is offline   Reply With Quote
Old 08-02-2021, 04:50 PM   #628
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Will putting a "select books modified since the start of this chain" after the action select all the books I'd originally selected, or only those that have actually changed?
ownedbycats is offline   Reply With Quote
Old 08-02-2021, 05:50 PM   #629
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Will putting a "select books modified since the start of this chain" after the action select all the books I'd originally selected, or only those that have actually changed?
It will select only the books that have been changed. If you want to act on selected books meeting certain criteria and then reverting back to original selections, you can achieve this this way (see attached chain):
  • Using chain variables you store book_ids for currently selected books (in a variable called book_ids).
  • In the same chain variables action, you define another variable (called new_sel) that iterates over selected books, and only add books that match the criteria you want.
  • Add a new action "Search using templates" that select all the books in the variable defined above (new_sel).
  • Continue with the rest of your chain
  • (Optional) Restore the original selections if you want using "Search using templates" action, and using the book_ids variable defined in the first step.

Edit: You need to remove or rename the original chain before importing the modified version because they have the same name.
Attached Files
File Type: zip modified send to device.zip (6.4 KB, 316 views)

Last edited by capink; 08-02-2021 at 06:17 PM.
capink is offline   Reply With Quote
Old 08-02-2021, 06:35 PM   #630
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,054
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks.

I noticed that re-importing an exported chain didn't work before. I think it might make sense if it could automatically be appended with a number, Send to Device 01 for instance.
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Action Chains Resources capink Plugins 78 08-05-2025 04:01 AM
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 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:57 AM.


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