Quote:
Originally Posted by fidvo
I'm trying to create a module that adds an empty book and fills in some default metadata. Everything works except that the book doesn't show up in the book list until I reload the library (for example by restarting Calibre or switching to a different library and back). Here is my code:
Code:
from calibre_plugins.action_chains.actions.base import ChainAction
from calibre.ebooks.metadata.book.base import Metadata
class TestAddEmpty(ChainAction):
name = 'Add Empty'
def run(self, gui, settings, chain):
db = gui.current_db
ids, duplicates = db.new_api.add_books([(Metadata(None), {})])
# What do I put here?
newid = ids[0]
gui.library_view.select_rows([newid])
I assume I have to add something at the # What do I put here? marker in order to make the new book show up, but I don't know what it is. Any ideas?
Thanks.
|
This template contains an example of what you put "here".
Code:
python:
def evaluate(book, context):
db = context.db
from calibre.ebooks.metadata.book.base import Metadata
ids, duplicates = db.new_api.add_books([(Metadata(None), {})])
print(ids, duplicates)
from calibre.gui2.ui import get_gui
gui = get_gui()
gui.current_db.data.refresh()
gui.library_view.model().resort()
gui.tags_view.recount()
gui.library_view.set_current_row(book_id=ids[0])
return 'a string'