![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,506
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
FWIW: I'm currently implementing these changes to the base formatter.
Code:
program: ids = selected_books(); col = selected_column(); res = ''; for id in ids: with id: # prints information from the book with identifier 'id' print($title, field(col)); res = (if res then res & ',' fi) & field(col); template('program: print("inside template", $title)') htiw rof; list_remove_duplicates(res, ',') EDIT: I'm also going to implement "show_in_dialog()" that renders an html string. |
![]() |
![]() |
![]() |
#2 | |
Chalut o/
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 452
Karma: 678910
Join Date: Dec 2017
Device: Kobo
|
Quote:
Else, if retrive the seleted book ids is good, I think it would be much more useful to have a function 'search_books()' that use the search syntax. Code:
ids = search_books('series:"='&field('series')&'"') rlst = '' for id in ids: with id: rlst = rlst & character('newline') & $title htiw; rof; show_in_dialog(rlst) # show all the books in a series (this two function would also greatly benefit to have a optional argument virtual libray) Damn, it will make the GPM incredible powerfull, able to execute an return big data for a one of execution. Python template are great, but GPM is much simpler and enough for 90% of case, and the 'with' statement will make it a "complet" language in a some way. But now that I think about it, I don't think the template editor is designed for that kind use, since it executes the code at each edit... it would become a hell to creat such things. So in addition, I think it would be useful to add a new mode that only executes code on demand. Nevermind, their is the Breakpoints mode that already do that, Yes. (however, you must not select such stored template without the Breakpoints mode enable, else your cooked) |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | ||||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,506
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
ids = book_values('id', 'series:"=' & field('series') & '"', ',', '0') Quote:
Code:
ids = book_values('id', '', ',', '0') Quote:
Code:
ids = book_values(id, 'vl:foo', ',', '0') Quote:
NB: I'm also adding a way to execute the template tester where it doesn't run the template for all the selected books, ignoring all but the first book. This helps develop and use templates that iterate over selected ids, generating reports. |
||||
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,506
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
These are the changes I've submitted to Kovid. They might change during his review.
Here is an example using several of the new features. It generates a report of book sizes for the selected books. Code:
program: ids = sort_book_ids(selected_books(), 'series', 1, 'title', 1); res = '<style> th, td {padding: 2px;}</style> <h2>Book Size Report</h2><p><table>'; total = 0; def table_row(title, series, size): return strcat('<tr><td>', title, '</td>', '<td>', series, '</td>', '<td>', if size !=# 0 then human_readable(size) else '0' fi, '</td>', '</tr>', character('newline')) fed; for id in ids: with id: s = booksize(); total = total + s; res = strcat(res, table_row($title, $series, s)) htiw rof; res = strcat(res, table_row('TOTAL', '', total)); res = strcat(res, '</table>'); show_dialog(res) Last edited by chaley; Today at 09:46 AM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
The footer template (cover generation settings) | jmendes | Related Tools | 2 | 05-02-2021 08:40 AM |
Template Language | phossler | Calibre | 8 | 01-12-2016 04:37 PM |
Template Generation | BetterRed | Library Management | 4 | 10-02-2014 06:40 AM |
Help with template language | Pepin33 | Calibre | 8 | 11-11-2012 08:32 AM |
Series 'Report' Generation? | affa | Library Management | 7 | 06-20-2012 09:18 AM |