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 Today, 06:31 AM   #16
foosion
Groupie
foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.foosion is fluent in JavaScript as well as Klingon.
 
Posts: 186
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by chaley View Post
Which one of those two? They are implemented very differently.
Is there documentation which shows these functions (these two and the ones in the function you posted)? Or do I need to browse the source code?

It would be good to learn how to write things myself.

In the meanwhile, whichever is easier.

Last edited by foosion; Today at 06:33 AM.
foosion is offline   Reply With Quote
Old Today, 07:02 AM   #17
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: 11,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by foosion View Post
Is there documentation which shows these functions (these two and the ones in the function you posted)? Or do I need to browse the source code?

It would be good to learn how to write things myself.
Some of the API is documented in https://manual.calibre-ebook.com/dev...rts-of-calibre.

However, for the kinds of things you are trying to do it is usually best to look at existing code that does something similar.

Quote:
In the meanwhile, whichever is easier.
Here is code to do both. The bit you want replaces the two "view_action" lines.
Code:
		# select the random row in the booklist
		view = gui.current_view()
		view.select_rows(set((random_id,)))

		# display a dialog
		mi = db.new_api.get_proxy_metadata(random_id)
		from calibre.gui2 import info_dialog
		data_to_show = (
			f"Series: {mi.format_field('series')[1]}",
			f"Tags: {mi.format_field('tags')[1]}",
			f"My Bool: {mi.format_field('#mybool')[1]}"
		)
		msg = '<br>'.join(data_to_show)
		info_dialog(gui, f"Random book: {mi.get('title')}", msg, show=True)
You can use the template tester in python mode to play, which is easier and faster than creating template actions or altering calibre source. For example, here is the code from above usable as a python template. It is only the rist few lines that are different.

Code:
python:
def evaluate(book, context):
	db = context.db
	from calibre.gui2.ui import get_gui
	gui = get_gui()
	db = gui.current_db
	ids = list(db.new_api.search('#mybool:true and formats:epub'))
	if ids:
		import random
		random_id = random.choice(ids)
#		view_action = gui.iactions['View']
#		view_action.view_format_by_id(random_id, 'EPUB', open_at=None)

		# select the random row.
		view = gui.current_view()
		view.select_rows(set((random_id,)))

		# display a dialog
		mi = db.new_api.get_proxy_metadata(random_id)
		from calibre.gui2 import info_dialog
		data_to_show = (
			f"Series: {mi.format_field('series')[1]}",
			f"Tags: {mi.format_field('tags')[1]}",
			f"My Book: {mi.format_field('#mybool')[1]}"
		)
		msg = '<br>'.join(data_to_show)
		info_dialog(gui, f"Random book: {mi.get('title')} ({str(random_id)})", msg, show=True)		
	return 'a string'

Last edited by chaley; Today at 07:13 AM. Reason: Typo
chaley is offline   Reply With Quote
Old Today, 07:12 AM   #18
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: 11,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Another bit of important documentation: the book Metadata object api: https://manual.calibre-ebook.com/gen...tadata-objects
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign Pick a Random Book to a keyboard combination? jamesgl Calibre 3 05-14-2022 05:54 PM
Pick multiple random books? BookJunkieLI Library Management 5 05-24-2020 11:10 AM
"Pick Random Book" - not so random?? Chris_Snow Library Management 3 09-15-2013 06:44 PM
Adding "Pick a Random Book" in Sharing over the net ippopom Recipes 2 01-13-2013 04:32 AM
Do you pick the book first or do you look for books available on your device? Bob Russell Which one should I buy? 21 09-08-2008 12:34 PM


All times are GMT -4. The time now is 09:12 AM.


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