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 04-19-2021, 06:24 AM   #541
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
If you are talking about the this action, the answer is yes, but you need to modify the action to change the chain vars based on your choice.

But a better approach to this is to add a Chain Vars action to the top of your chain, add a variable called 'myvar' and check the "runtime option". Now whenever you run a chain you will have a dialog asking you to specify the value for 'myvar'. You can set conditions on the following action(s) based on the value of 'myvar'. For example:

Template:
Code:
program:
globals(myvar)
Datatype: text
Comparison: =
Condition Value: 1


You can replace 1 with whatever value you choose at runtime. You can also set multiple variables at runtime if you want.
capink is offline   Reply With Quote
Old 04-19-2021, 06:38 AM   #542
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
Chain Variations

The new chain variations feature is experimental and hidden by default. To enable it add the following tweak:

Code:
action_chains_experimental = True
After restarting you should see two menu entries "Add variations" and "Remove variations" in the add/modify chains dialog. When you press add variations, a template dialog should appear, you can add chain variants using a template functions as follows:

Code:
program:
    add_chain_variant('first variant','argument1');
    add_chain_variant('second variant','argument2',  'submenu1', 'minus.png');
The whole idea behind variations is that you have the same chain repeated several times in dropdown menu. Each variant is passed a different argument that is stored as a chain variable called "_variant_argument". The chain can check the value of this variable and take different courses depending on the value of this variable.

The example above passes static arguments to the add_chain_variant(). You can do the same thing by simply copying the chain and modifying each copy to do what you want. The real value of this feature is that you can use the template language to calculate dynamic values and pass them as arguments. e.g. lists created by set_persistent_vars(). Each time you add a new list, a menu entry can be added for it automatically. And if a list is deleted, its menu entry should be remove automatically as well.

You can think of this like the "add to list" in the Reading List plugin where you have a menu entry for each list. The same can be done for the Action Chains. e.g. If you have multiple lists stored in persistent storage using the set_persistent_vars() function, you can have a template replicating the chain for each of those lists.

The add_chain_variant() take 2 mandatory arguments + 2 optional arguments:
  1. menu_text: The name of the variant in that will appear in the dropdown menu. Variant names should be different from each other.
  2. argument: The argument that will passed to the variant and stored as _variant_argument variable. It can be accessed by action in the chain using the globals() template function.
  3. (Optional) sub_menu_text.
  4. (Optional) icon.

Finally, you can use the same function to add a separator between the variants:
Code:
program:
    add_chain_variant('separator','');

Last edited by capink; 05-13-2021 at 10:24 AM.
capink is offline   Reply With Quote
Old 04-19-2021, 12:29 PM   #543
SoccerDad91016
Enthusiast
SoccerDad91016 began at the beginning.
 
SoccerDad91016's Avatar
 
Posts: 34
Karma: 10
Join Date: Aug 2014
Device: Kindle Paperwhite, Kindle Fire HD 8, Microsoft Surface Go 3
Latest update appears to have broken TemplateBox.

I have the following line in an action chain module:

from calibre_plugins.action_chains.templates import TemplateBox, check_template, get_metadata_object

Getting the following error after the latest plugin and Cailbre updates:
calibre, version 5.16.0
ERROR: Invalid Python code: The code you created is not valid Python code, with error: cannot import name 'TemplateBox' from 'calibre_plugins.action_chains.templates' (C:\Users\xxxxxxx\AppData\Roaming\calibre\plugins\ Action Chains.zip/templates/__init__.py)

Is this something I can fix, or do I need to wait for an update to ActionsChains plugin or Calibre?
SoccerDad91016 is offline   Reply With Quote
Old 04-19-2021, 12:39 PM   #544
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: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by SoccerDad91016 View Post
Latest update appears to have broken TemplateBox.

I have the following line in an action chain module:

from calibre_plugins.action_chains.templates import TemplateBox, check_template, get_metadata_object

Getting the following error after the latest plugin and Cailbre updates:
calibre, version 5.16.0
ERROR: Invalid Python code: The code you created is not valid Python code, with error: cannot import name 'TemplateBox' from 'calibre_plugins.action_chains.templates' (C:\Users\xxxxxxx\AppData\Roaming\calibre\plugins\ Action Chains.zip/templates/__init__.py)

Is this something I can fix, or do I need to wait for an update to ActionsChains plugin or Calibre?
Try
Code:
from calibre_plugins.action_chains.templates.dialogs import TemplateBox
from calibre_plugins.action_chains.templates import check_template, get_metadata_object
chaley is offline   Reply With Quote
Old 04-19-2021, 12:54 PM   #545
SoccerDad91016
Enthusiast
SoccerDad91016 began at the beginning.
 
SoccerDad91016's Avatar
 
Posts: 34
Karma: 10
Join Date: Aug 2014
Device: Kindle Paperwhite, Kindle Fire HD 8, Microsoft Surface Go 3
Quote:
Originally Posted by chaley View Post
Try
Code:
from calibre_plugins.action_chains.templates.dialogs import TemplateBox
from calibre_plugins.action_chains.templates import check_template, get_metadata_object
Worked great and fixed it. Looks like they moved TemplateBox down a level in the templates.

Are these types of changes documented somewhere?
SoccerDad91016 is offline   Reply With Quote
Old 04-19-2021, 01:28 PM   #546
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 SoccerDad91016 View Post
Worked great and fixed it. Looks like they moved TemplateBox down a level in the templates.

Are these types of changes documented somewhere?
That particular module has outgrown what it was originally intended for. I assumed that no one was using it and went ahead with the modifications. Will be more careful in the future and document if anything similar changes in the release notes.

I did post a custom action here that depends on this particular import, but this action has been included in the plugin as a builtin action called "Search Using Templates". If that was the action you are using, you should move to the builtin version.
capink is offline   Reply With Quote
Old 04-20-2021, 10:32 PM   #547
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: 10,976
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Can an action have more than one condition?

I switched my "View" action conditional to program: view_manager_last_view() != Physical Books, but I'd like to also keep the {formats} != PAPERBOOK conditional.

Last edited by ownedbycats; 04-20-2021 at 10:44 PM.
ownedbycats is offline   Reply With Quote
Old 04-20-2021, 10:48 PM   #548
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
Yes. See below.

Quote:
Originally Posted by capink View Post
Note that you can set multiple conditions using one template. As an example, this template tests for two conditions (selection_count + book format). The following boolean template functions can be useful for setting multiple conditions: and(), or(), not().
capink is offline   Reply With Quote
Old 04-20-2021, 10:55 PM   #549
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: 10,976
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
OK that's good. I will try to figure that out.
ownedbycats is offline   Reply With Quote
Old 04-20-2021, 10:55 PM   #550
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
template:
Code:
program:
$formats != 'PAPERBOOK' && view_manager_last_view() != 'Physical Books'
Datatype: text
Comparison: =
Condition Value: 1
capink is offline   Reply With Quote
Old 04-20-2021, 11:18 PM   #551
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: 10,976
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works.
ownedbycats is offline   Reply With Quote
Old 04-22-2021, 02:58 PM   #552
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.8.0
Update: New template functions: sanitize_path(), cover_path().
Update: Events: New "Calibre Initialized" Event.
Update: Experimental: New chain variation feature.
Update: Open With: Template GPM can be used for command arguments.
Fix: Crash if you delete a row from the actions table with editor open but no action selected.

You can read more about chain variations here.
capink is offline   Reply With Quote
Old 04-22-2021, 04:50 PM   #553
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: 10,976
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I think I know what cover_path() is, but what does sanitize_path() do?
ownedbycats is offline   Reply With Quote
Old 04-22-2021, 05:02 PM   #554
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
You can see how both are used in the chain posted here. If you want to save a file using the plugin based on a template like {authors}\{title}, there are chances they contain illegal characters not supported by OS for filenames. sanitize_path() removes these illegal characters.
capink is offline   Reply With Quote
Old 04-22-2021, 05:23 PM   #555
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: 10,976
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That's good. I once had a cross-platform program mistakenly save a file with a colon, which is illegal in Windows. I had to use a Linux boot disk to get rid of the damn thing.
ownedbycats 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 10:49 AM.


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