View Single Post
Old 09-25-2025, 07:16 AM   #13
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,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Example: tooltip showing the note associated with a publisher

This template generates a tooltip showing the note for the publisher, if any. It also shows the count of books by that publisher and a link to search for the publisher in the current library.

Note: Links can be clicked only in the "dialog" version of the tooltip. If you want to be able to click links then I recommend you give that dialog a shortcut in Preferences / Shortcuts / Column tooltips / Show item tooltip in a dialog. You can also add "Column tooltips" to the tool bar, menu bar, or context menu.

The template:
Code:
program:
	if ! $publisher then
		# Nothing to do here
		return 'No publisher'
	fi;
	# Generate the HTML for the tooltip. First, the name of the publisher.
	tt = f_string("<div>Publisher: {$publisher}");

	# Generate the search string used to get the publisher count and to do the search
	search_for = f_string('publisher:"""={$publisher}"""');

	# Add the publisher count to the HTML
	tt = f_string("{tt}<br>Count of books published by {$publisher}: {book_count(search_for, 0)}");

	# Add the calibre search link to the HTML
	tt = f_string('{tt}<br><a href="calibre://search/_?eq={to_hex(search_for)}">' &
                  'Show books in this calibre library published by {$publisher}</a>');

	# Add the note if it exists to the HTML
	n = get_note("publisher", $publisher, "");
	if n then
		tt = f_string('{tt}<p><div>{n}</div></p>')
	fi;

	# Add the closing </div>
	tt = f_string('{tt}</div>');

	# Return the generated HTML
	tt
The result, shown in a dialog:
Click image for larger version

Name:	Clipboard01.jpg
Views:	27
Size:	97.1 KB
ID:	218267

Last edited by chaley; 09-26-2025 at 04:55 AM. Reason: Was released in calibre 6.11
chaley is offline   Reply With Quote