Quote:
Originally Posted by chaley
Another safer way to insert data: implement "globals" in the formatter
|
Again, what you are offering here is much cleaner way of doing things, which would make me do away with the whole update_metadata thing

.
Just to be sure we are on the same page, I will define a global dict for each chain, which have some predefined values and also allows the user to insert his own arbitrary variables
Code:
self.global = {
_chain_name: ....,
_action_name: ....,
user_var1: ......,
......
}
Some of the above variables will be overwritten for each action. And this global dict will be used for condition testing as well.
The user can access this using a template like this:
Code:
program: globals('user_var1')
Whenever a template is being evaluated, I should pass this dict to the formatter, may something like this:
Code:
template_output = SafeFormat().safe_format(template, mi, TEMPLATE_ERROR, mi, chain_loop.global)
When testing for conditions, if an action does not define any condition it will always execute. For actions that define conditions, they must be evaluated against the value in the global dict, and if they match, the action will run, otherwise it will be skipped.
One problem here is that since this is a name/value pair, to test conditions you should have two corresponding columns, one for name and another for value. I much prefer that it is one column whose value is tested against a predefined name in the global dict e.g. _condition. Adding multiple columns is confusing, one column with keywords is more accessible IMO. I am open to feedback from others on this.
Edit: striked out since it would not work with one column.
Quote:
Originally Posted by chaley
Note: some formatter functions check if mi is a ProxyMetadata object and refuse to work if it is not. For that reason, and also for performance, you probably want to use get_proxy_metadata() instead of get_metadata().
|
I didn't know about this. I will modify it for the next release.
Quote:
Originally Posted by chaley
It would be almost identical to "Single Field Edit"
|
I think a table widget with two columns is more suitable since number and names of variables are not preset. Somewhat similar to table widgets used for chains and actions, with ability to add/remove rows (except for protected name like _chain_name).
Quote:
Originally Posted by chaley
There is already a formatter function to retrieve the device name, connected_device_name(). I can add a function to get the device UUID if that is something useful.
|
I never use devices with calibre (non rootable kindle, only email one book at a time since collections are useless), so my knowledge here is very limited. I only went for device_uuid as way to prevent name clashes if the user has two similar devices. I will defer to others decide whether a device_uuid is needed.