当前位置: 首页>>代码示例>>Python>>正文


Python FormatsManager.get_format_path方法代码示例

本文整理汇总了Python中calibre.gui2.metadata.basic_widgets.FormatsManager.get_format_path方法的典型用法代码示例。如果您正苦于以下问题:Python FormatsManager.get_format_path方法的具体用法?Python FormatsManager.get_format_path怎么用?Python FormatsManager.get_format_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calibre.gui2.metadata.basic_widgets.FormatsManager的用法示例。


在下文中一共展示了FormatsManager.get_format_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MetadataSingleDialogBase

# 需要导入模块: from calibre.gui2.metadata.basic_widgets import FormatsManager [as 别名]
# 或者: from calibre.gui2.metadata.basic_widgets.FormatsManager import get_format_path [as 别名]

#.........这里部分代码省略.........
            widget.initialize(id_)
        if callable(self.set_current_callback):
            self.set_current_callback(id_)
        # Commented out as it doesn't play nice with Next, Prev buttons
        # self.fetch_metadata_button.setFocus(Qt.OtherFocusReason)

    # Miscellaneous interaction methods {{{
    def update_window_title(self, *args):
        title = self.title.current_val
        if len(title) > 50:
            title = title[:50] + u'\u2026'
        self.setWindowTitle(BASE_TITLE + ' - ' +
                title + ' - ' +
                _(' [%(num)d of %(tot)d]')%dict(num=self.current_row+1,
                tot=len(self.row_list)))

    def swap_title_author(self, *args):
        title = self.title.current_val
        self.title.current_val = authors_to_string(self.authors.current_val)
        self.authors.current_val = string_to_authors(title)
        self.title_sort.auto_generate()
        self.author_sort.auto_generate()

    def tags_editor(self, *args):
        self.tags.edit(self.db, self.book_id)

    def metadata_from_format(self, *args):
        mi, ext = self.formats_manager.get_selected_format_metadata(self.db,
                self.book_id)
        if mi is not None:
            self.update_from_mi(mi)

    def get_pdf_cover(self):
        pdfpath = self.formats_manager.get_format_path(self.db, self.book_id,
                                                       'pdf')
        from calibre.gui2.metadata.pdf_covers import PDFCovers
        d = PDFCovers(pdfpath, parent=self)
        if d.exec_() == d.Accepted:
            cpath = d.cover_path
            if cpath:
                with open(cpath, 'rb') as f:
                    self.update_cover(f.read(), 'PDF')
        d.cleanup()

    def cover_from_format(self, *args):
        ext = self.formats_manager.get_selected_format()
        if ext is None:
            return
        if ext == 'pdf':
            return self.get_pdf_cover()
        try:
            mi, ext = self.formats_manager.get_selected_format_metadata(self.db,
                    self.book_id)
        except (IOError, OSError) as err:
            if getattr(err, 'errno', None) == errno.EACCES:  # Permission denied
                import traceback
                fname = err.filename if err.filename else 'file'
                error_dialog(self, _('Permission denied'),
                        _('Could not open %s. Is it being used by another'
                        ' program?')%fname, det_msg=traceback.format_exc(),
                        show=True)
                return
            raise
        if mi is None:
            return
        cdata = None
开发者ID:JapaChin,项目名称:calibre,代码行数:70,代码来源:single.py

示例2: MetadataSingleDialogBase

# 需要导入模块: from calibre.gui2.metadata.basic_widgets import FormatsManager [as 别名]
# 或者: from calibre.gui2.metadata.basic_widgets.FormatsManager import get_format_path [as 别名]

#.........这里部分代码省略.........
            self.set_current_callback(id_)
        # Commented out as it doesn't play nice with Next, Prev buttons
        # self.fetch_metadata_button.setFocus(Qt.OtherFocusReason)

    # Miscellaneous interaction methods {{{
    def update_window_title(self, *args):
        title = self.title.current_val
        if len(title) > 50:
            title = title[:50] + "\u2026"
        self.setWindowTitle(
            BASE_TITLE
            + " - "
            + title
            + " - "
            + _(" [%(num)d of %(tot)d]") % dict(num=self.current_row + 1, tot=len(self.row_list))
        )

    def swap_title_author(self, *args):
        title = self.title.current_val
        self.title.current_val = authors_to_string(self.authors.current_val)
        self.authors.current_val = string_to_authors(title)
        self.title_sort.auto_generate()
        self.author_sort.auto_generate()

    def tags_editor(self, *args):
        self.tags.edit(self.db, self.book_id)

    def metadata_from_format(self, *args):
        mi, ext = self.formats_manager.get_selected_format_metadata(self.db, self.book_id)
        if mi is not None:
            self.update_from_mi(mi)

    def get_pdf_cover(self):
        pdfpath = self.formats_manager.get_format_path(self.db, self.book_id, "pdf")
        from calibre.gui2.metadata.pdf_covers import PDFCovers

        d = PDFCovers(pdfpath, parent=self)
        if d.exec_() == d.Accepted:
            cpath = d.cover_path
            if cpath:
                with open(cpath, "rb") as f:
                    self.update_cover(f.read(), "PDF")
        d.cleanup()

    def cover_from_format(self, *args):
        ext = self.formats_manager.get_selected_format()
        if ext is None:
            return
        if ext == "pdf":
            return self.get_pdf_cover()
        try:
            mi, ext = self.formats_manager.get_selected_format_metadata(self.db, self.book_id)
        except (IOError, OSError) as err:
            if getattr(err, "errno", None) == errno.EACCES:  # Permission denied
                import traceback

                fname = err.filename if err.filename else "file"
                error_dialog(
                    self,
                    _("Permission denied"),
                    _("Could not open %s. Is it being used by another" " program?") % fname,
                    det_msg=traceback.format_exc(),
                    show=True,
                )
                return
            raise
开发者ID:GaryMMugford,项目名称:calibre,代码行数:70,代码来源:single.py


注:本文中的calibre.gui2.metadata.basic_widgets.FormatsManager.get_format_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。