View Single Post
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,128
Karma: 1954142
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