Quote:
Originally Posted by chaley
Using a template_action would set 'v', a "global variable" in action chains. Subsequent actions would be conditioned by the value of 'v', specified in a column. This way the template returns a value that controls subsequent actions without worrying about changes of state. Any new template_action() would reset that value, permitting expressions like
|
An action that resets a chain variable, and compared to per action values stored in an extra column, is much better than the jump idea, as it allows finer control over actions. It also presents a visual representation of what action will run under which conditions, and as you said, provides better maintenance when adding/moving actions. Only drawback is that it can be a bit confusing when trying to document/instruct the users on how to use it.
Quote:
Originally Posted by chaley
A template cannot reference more than one book.
|
Actually I was thinking of not (just) using templates on book metadata, since mi objects can accept extra information I can do something like this:
Code:
device_uuid = get_device_uuid()
cmeta1 = {'datatype': 'text', 'is_multiple': {}, 'name': '#device_uuid'}
mi.set_user_metadata('#device_uuid', cmeta1)
mi.set('#device_uuid', device_uuid)
Using this method, we can insert multiple fields storing global state values enabling the user can define conditions using the familiar template language:
And now the user can flag actions with the device_uuid (or alternatively device_name if there is such a thing?) and they will only run if the device is attached. This also presents the question of what extra information to inject into the mi object that can be useful for conditional actions?
By the way, the above technique is already used in the plugin. Any action that implements an update_metadata(self, mi) method, is called on every mi object and given the chance to modify it. I have a custom action that inserts a calculated file path, that is not stored in calibre, into the mi object as a #path_to_file field, this field is used by the template feature of the open with action to open the file/folder. Since the file(s) location changes from time to time, I have it mapped into a automatically updated json file (uuid to location mapping).
Finally, when fetching mi object in case we have multiple books selected, which one do we use? the current index? would the metadata for that one book provide value for conditional execution of actions?
@compurandom: See whether the above point about update_metadata() method satisfies your needs, also the code snippet above it on how to insert arbitrary fields into mi objects