02-20-2021, 06:01 AM | #346 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
Here is a new beta containing the latest changes. I will wait for few days before releasing this version.
The change in the bullet point no. 3 only affect people who write custom actions, and set book specific variables using chain_loop.set_book_vars. I suspect zero people are using this. But just in case, these variables are now accessed in template using the new function like this: Code:
program: book_vars('my_var_name') |
02-20-2021, 06:09 AM | #347 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
There was a problem with the beta I posted in the previous post. I uploaded a new one now.
|
Advert | |
|
02-20-2021, 07:20 AM | #348 | |||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Thank you for this. I think that these additions increase flexibility, allowing someone to solve a problem the way they think about it.
Quote:
Suggestion: move the "Iterate" checkbox to the second column. It took me a while to find it. I didn't think of scrolling. Quote:
Quote:
A note: book_vars() (and a possible set_book_vars()) uses a different syntax than globals() and set_globals(). book_vars() requires you to pass an expression that is usually a constant string. The globals() and set_globals() functions require that the arguments be variable names; they cannot be expressions. I think this difference is confusing. I don't see a way to unify the syntax of book_vars() and globals() other than by changing the formatter to return the variable name as a string if that variable isn't defined. If I did that then book_vars(aaa) would be identical to book_vars('aaa'). On the other hand the following template would return the book title instead of raising an undefined variable error: Code:
program: field(title) Code:
program: strcat(hello, ' ', there) Code:
program: hello = 'foo'; strcat(hello, ' ', there) Perhaps I am overthinking it, but it seems to me that the three "groups" in the dialog are executed in order. VLs are cleared if that box is checked, a search is done (or not), resulting in selected books, and then the options are applied. |
|||
02-20-2021, 07:55 AM | #349 | |||||||
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
I have no problem with adding the option to not change selection. But I don't think it will used much except except maybe to display a search at the end of the chain without selecting any books. If you combine a search with this new option, the current library view will change to reflect the new search, but no book will be selected. You have to combine the search with "choose all books in current view" or any other option to have books be selected. Edit: I will do it because it might have some uses. Last edited by capink; 02-20-2021 at 08:01 AM. |
|||||||
02-20-2021, 08:31 AM | #350 | ||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
I think that adding these two options cover all the possibilities:
Note that clearing the selection sort-of does select the first book. The "title" field is lightly highlighted. If you run Quickview docked then when the selection is cleared Quickview shows the information for the Author of the first book. Hitting the down-arrow button does an actual selection of the second book. Maybe this implies that the second option above is the best choice. Last edited by chaley; 02-20-2021 at 10:13 AM. |
||
Advert | |
|
02-20-2021, 08:57 AM | #351 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
I will add both.
|
02-20-2021, 12:07 PM | #352 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
New beta version here with the following changes:
|
02-20-2021, 03:04 PM | #353 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
Action chains template functions
The Action chains defines some extra template functions that can be used only within the plugin, to supplement and offer new functionality to calibre's template language. There are two classes of these template functions:
Last edited by capink; 11-16-2022 at 10:17 AM. |
02-21-2021, 01:48 PM | #354 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
@chaley: I am having a little problem with the for loop, relating to a new template function I've added to the plugin. The function is called category_items(). It works as follows
Code:
program: category_items('#genre') It can also take second optional arg to limit the result to set of book_ids Code:
program: book_ids = from_selection('id'); category_items('#genre',book_ids) The problem arise when I run the new function on a field containing names like 'authors'. I have to return a list separated with an ampersand, because author names can have commas in them. The documentation says the for loop will only accept a comma separated list of values. Can this modified to allow the user to somehow choose a different separator, maybe by setting a variable before running the for loop. Another thing: I started making another function top_category_items() that is the same to the above function, but only extracts the top hierarchy level. I then starting having doubt, because I thought maybe combining the category_items() with subitem() would be a better way to achieve this and also offers more possibilities. The problem here is with that approach, I have to remove duplicates myself. It can be done using template but a lot of hassle. I ran recently into this problem in this template. The solution would be to add a uniq() template that removes duplicates from a list. I can easily add this, but I think it might be better to be included in the template builtin functions. Would you be willing to add something like this? I not, I will add to the plugin. |
02-21-2021, 02:16 PM | #355 | |||
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
['lookup_name': set_of_values, ...] Quote:
Code:
'for' varname 'in' expression ['separator' expression] ':' Quote:
Code:
list_union('', list_to_remove_duplicates, sep) Code:
list_remove_duplicates(list, sep) |
|||
02-21-2021, 02:35 PM | #356 | ||
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
Quote:
Quote:
Definitely. It is better not to force people to specify the separator every time unnecessarily. Yours seems more descriptive and better. |
||
02-21-2021, 05:53 PM | #357 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Should list_remove_duplicates be case sensitive or case insensitive? Almost everything else in calibre is case insensitive so that is where I lean.
Note that in the case of case-insensitive matching, the last one in the list wins. Example: the input list 'A, A, a, a, b, B' produces the answer 'a, B' |
02-22-2021, 02:25 AM | #358 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
I think it should follow the pattern of being case insensitive.
|
02-22-2021, 04:10 AM | #359 |
Wizard
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
|
Version 1.3.0
Version 1.2.3
Version 1.2.4
Version 1.3.0
This is how to use the new category_items() template function: Code:
program: category_items('#genre') It can also take second optional arg to limit the result to set of book_ids Code:
program: book_ids = from_selection('id'); category_items('#genre',book_ids) The resulting items are separated by one of the following characters(s):
Also note that the previously intoduced book_vars() template function is now used to access book specific variables, instead of the old way of accessing them using the globals function. The both work differently; book_vars() requires you to pass an expression that is usually a constant string. The globals() function require that the arguments be variable names. This can be illustrated by the following examples: Code:
program: globals(my_var) Code:
program: book_vars('my_var') |
02-22-2021, 07:05 AM | #360 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@capink: specifying a separator in a for statement and the function list_remove_duplicates(l, sep) are now available in master source.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Editor Plugin] Editor Chains | capink | Plugins | 83 | Today 07:44 PM |
Action Chains Resources | capink | Plugins | 54 | 01-29-2024 11:24 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 |