本文整理汇总了Python中calibre.ebooks.metadata.opf2.OPF.set_null方法的典型用法代码示例。如果您正苦于以下问题:Python OPF.set_null方法的具体用法?Python OPF.set_null怎么用?Python OPF.set_null使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.ebooks.metadata.opf2.OPF
的用法示例。
在下文中一共展示了OPF.set_null方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paste_metadata
# 需要导入模块: from calibre.ebooks.metadata.opf2 import OPF [as 别名]
# 或者: from calibre.ebooks.metadata.opf2.OPF import set_null [as 别名]
def paste_metadata(self):
rows = self.gui.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0:
return error_dialog(self.gui, _('Cannot paste metadata'),
_('No books selected'), show=True)
c = QApplication.clipboard()
md = c.mimeData()
if not md.hasFormat('application/calibre-book-metadata'):
return error_dialog(self.gui, _('Cannot paste metadata'),
_('No copied metadata available'), show=True)
if len(rows) > 1:
if not confirm(_(
'You are pasting metadata onto <b>multiple books</b> ({num_of_books}). Are you'
' sure you want to do that?').format(num_of_books=len(rows)), 'paste-onto-multiple', parent=self.gui):
return
data = bytes(md.data('application/calibre-book-metadata'))
mi = OPF(BytesIO(data), populate_spine=False, read_toc=False, try_to_guess_cover=False).to_book_metadata()
mi.application_id = mi.uuid_id = None
exclude = set(tweaks['exclude_fields_on_paste'])
paste_cover = 'cover' not in exclude
cover = md.imageData() if paste_cover else None
exclude.discard('cover')
for field in exclude:
mi.set_null(field)
db = self.gui.current_db
book_ids = {db.id(r.row()) for r in rows}
title_excluded = 'title' in exclude
authors_excluded = 'authors' in exclude
for book_id in book_ids:
if title_excluded:
mi.title = db.new_api.field_for('title', book_id)
if authors_excluded:
mi.authors = db.new_api.field_for('authors', book_id)
db.new_api.set_metadata(book_id, mi, ignore_errors=True)
if cover:
db.new_api.set_cover({book_id: cover for book_id in book_ids})
self.refresh_books_after_metadata_edit(book_ids)