Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 10:13 AM   #1
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,506
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
Else, I worked of the idea and so here my proposal:
[/SPOILER]
FWIW: I'm currently implementing these changes to the base formatter.
  • ids = selected_books()
  • name = selected_cell(). Returns the lookup name.
  • A 'with' statement that changes the book the template is using for the statement's block. The same local variables are available to the inner and outer block.
Example:
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, ',')
Internal template functions and stored templates called from inside the 'with' block use the book with id 'id'.

EDIT: I'm also going to implement "show_in_dialog()" that renders an html string.
chaley is offline   Reply With Quote
Old Yesterday, 02:45 PM   #2
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 452
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Quote:
Originally Posted by chaley View Post
FWIW: I'm currently implementing these changes to the base formatter.
  • ids = selected_books()
  • name = selected_cell(). Returns the lookup name.
  • A 'with' statement that changes the book the template is using for the statement's block. The same local variables are available to the inner and outer block.

EDIT: I'm also going to implement "show_in_dialog()" that renders an html string.
Oh, it would be inded quite usefull to test all the selected books inside the singular Template call of the condition settings. But that dosn't solve the issue to perform some actions only on a specific subset on seleted books.

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
And let's even be bold, adding a 'all_ids_books()', that way, we can run the entire library.
(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)
un_pogaz is offline   Reply With Quote
Advert
Old Yesterday, 06:35 PM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,506
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
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
Use the function book_values(), as in
Code:
ids = book_values('id', 'series:"=' & field('series') & '"', ',', '0')
Quote:
And let's even be bold, adding a 'all_ids_books()', that way, we can run the entire library.
Use this. The null search expression matches everything.
Code:
ids = book_values('id', '', ',', '0')
Quote:
(this two function would also greatly benefit to have a optional argument virtual libray)
The fourth parameter tells book_values() whether or not to use the current VL. If you want to use an arbitrary VL then put it in the search expression. For example, this expression returns the ids of all the books in the 'foo' VL:
Code:
ids = book_values(id, 'vl:foo', ',', '0')
Quote:
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)
Yes, editing a template without breakpoints enabled is painful. I always have it on even when I'm not actually using breakpoints.

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.
chaley is offline   Reply With Quote
Old Today, 09:37 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
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.
  • A "with" statement in the template language that for the duration of the associated code block changes the "current book" to the one specified by the book id.
  • A formatter function selected_books() that returns the book ids of the currently selected books
  • A formatter function selected_column() that returns the lookup name of the column containing the selected cell.
  • A formatter function sort_book_ids() that sorts the books specified by book_ids.
  • A formatter function show_dialog() that opens a dialog to display plain text or html.
  • Add check boxes to the template tester to control "run as you type" and to restrict test runs to the first selected book. These are very useful if generating reports using selected books.

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)
EDIT: The above changes are now in calibre source

Last edited by chaley; Today at 09:46 AM.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 03:05 PM.


MobileRead.com is a privately owned, operated and funded community.