Today, 06:31 AM | #16 |
Groupie
Posts: 186
Karma: 4562
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
|
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. |
Today, 07:02 AM | #17 | ||
Grand Sorcerer
Posts: 11,891
Karma: 7036723
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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:
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) 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 |
||
Today, 07:12 AM | #18 |
Grand Sorcerer
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
|
|
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 |