View Single Post
Old 12-24-2020, 09:30 AM   #174
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
Version 0.3.99
  • Update: Add option to disable wait cursor for calibre actions.
  • Update: Add new action "Chain Variables".
  • Update: Add support for conditional executions of actions.
  • Update: Add support for conditional executions of chains.
  • Update: Add support for the new global template function.
  • Fix: predefined template error with marked field.

This version only works with the latest calibre version as it makes use of the new "globals" template function. The main change in this version is that it enables setting conditions that determines whether a chain, or an action inside a chain, is going to run. The conditions are set using calibre's template language. Simple examples are illustrated below on how to do this.

This version does change the config file of the plugin to accommodate a change made to Calibre Actions, so you are advised to backup the "Actions Chains.json" file in your plugin folder, just in case. Also the order and width of columns in the add actions dialog will be reset.

Special thanks for @chaley, as most of these features where ideas of his. He was also generous enough to add a new template function that made these new features possible.

@ownedbycats: This version addresses some problems you were having with the plugin.
  • You now have a checkbox to turn off the wait cursor for calibre actions.
  • The new contaning_folder() template function means you can now use a "copy to clipboard" action to get the containing folder, by using the below template:

    Code:
    program: contaning_folder()
    Note that this template makes use of a template function defined by the Action Chains plugin, so it will not work outside the plugin.
  • Now you can make the chain run only if a certain device is attached. This can be done using the new Chain Conditions dialog, by entering this following in the dialog:

    Code:
    template = program: connected_device_name('main')
    datatype = text
    comparison = "="
    condition value = your device name
    In case you have multiple devices with similar names, you can use the newly added connected_device_uuid function instead to prevent name clashes.
  • Also, to make chains enabled only if one book is selected, use the Chain Conditions dialog as follows

    Code:
    template = program: selection_count()
    datatype = number
    comparison = "="
    condition value = 1
    Again, this makes use of new function selection_count(), which is defined by the plugin and will not work outside Action Chains.

@compurandom: See the examples above for conditional execution of chains. The exact dialog is available for single actions as well. Also, a new chains variables action is available, where you can set chain variables, either as constant values, or values calculated by templates. You have some predefined variables that you can access from a template using the new globals function. For example if you want to mark books after each action, you can use this template:

Code:
program:
    c = globals(_chain_name);
    i = globals(_chain_iteration);
    a = globals(_action_name);
    i2 = globals(_action_index);
    strcat(c, '_', i, '_', a, '_', i2)
You add the previous template in a Single Field Edit template, and the choose the "marked" column. By using the _chain_iteration you make sure that you will not have clashes from books marked by a previous run of the same chain.

At the end of your chain, you can show all books marked by this chain, by using a custom action that constructs a search from templates. In the settings of this custom action, use this template to show all books marked by the chain:

Code:
program:
    c = globals(_chain_name);
    i = globals(_chain_iteration);
    strcat('marked:"', c, '_', i, '"')

You can define your own values using the Chains Variables actions, or if you writing custom action and want to define your own variables, you can use this in your code:

Code:
chain.set_chain_vars({'myvar': 'myval'})
Note that only strings are supported. Any other type will be discarded (with a message if running in debug mode).

Also, there is the ability to support book specific variables (see the example above about containing_folder). To to this, you add this to your custom action:

Code:
chain.set_book_vars(book_id, {'bookvar': 'bookval'})
Finally, when you are evaluating a template, to be able to make use of all the variables set, you should use this:

Code:
template_result = chain.evaluate_template('your template code', book_id)
@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.

Last edited by capink; 05-05-2021 at 09:30 AM.
capink is offline   Reply With Quote