Ejemplo n.º 1
0
        def create_item(name, linear=None):
            imt = container.mime_map.get(name, guess_type(name))
            icat = get_category(name, imt)
            category = 'text' if linear is not None else ({'text':'misc'}.get(icat, icat))
            item = QTreeWidgetItem(self.categories['text' if linear is not None else category], 1)
            flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
            if category == 'text':
                flags |= Qt.ItemIsDragEnabled
            if name not in cannot_be_renamed:
                flags |= Qt.ItemIsEditable
            item.setFlags(flags)
            item.setStatusTip(0, _('Full path: ') + name)
            item.setData(0, NAME_ROLE, name)
            item.setData(0, CATEGORY_ROLE, category)
            item.setData(0, LINEAR_ROLE, bool(linear))
            item.setData(0, MIME_ROLE, imt)
            set_display_name(name, item)
            tooltips = []
            emblems = []
            if name in {cover_page_name, cover_image_name}:
                emblems.append('default_cover.png')
                tooltips.append(_('This file is the cover %s for this book') % (_('image') if name == cover_image_name else _('page')))
            if name in container.opf_name:
                emblems.append('metadata.png')
                tooltips.append(_('This file contains all the metadata and book structure information'))
            if imt == ncx_mime or name in nav_items:
                emblems.append('toc.png')
                tooltips.append(_('This file contains the metadata table of contents'))
            if name not in manifested_names and not container.ok_to_be_unmanifested(name):
                emblems.append('dialog_question.png')
                tooltips.append(_('This file is not listed in the book manifest'))
            if linear is False:
                emblems.append('arrow-down.png')
                tooltips.append(_('This file is marked as non-linear in the spine\nDrag it to the top to make it linear'))
            if linear is None and icat == 'text':
                # Text item outside spine
                emblems.append('dialog_warning.png')
                tooltips.append(_('This file is a text file that is not referenced in the spine'))
            if category == 'text' and name in processed:
                # Duplicate entry in spine
                emblems.append('dialog_error.png')
                tooltips.append(_('This file occurs more than once in the spine'))
            if category == 'fonts' and name.rpartition('.')[-1].lower() in ('ttf', 'otf'):
                fname = self.get_font_family_name(name)
                if fname:
                    tooltips.append(fname)
                else:
                    emblems.append('dialog_error.png')
                    tooltips.append(_('Not a valid font'))

            render_emblems(item, emblems)
            if tooltips:
                item.setData(0, Qt.ToolTipRole, '\n'.join(tooltips))
            return item
Ejemplo n.º 2
0
        def create_item(name, linear=None):
            imt = container.mime_map.get(name, guess_type(name))
            icat = get_category(name, imt)
            category = "text" if linear is not None else ({"text": "misc"}.get(icat, icat))
            item = QTreeWidgetItem(self.categories["text" if linear is not None else category], 1)
            flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
            if category == "text":
                flags |= Qt.ItemIsDragEnabled
            if name not in cannot_be_renamed:
                flags |= Qt.ItemIsEditable
            item.setFlags(flags)
            item.setStatusTip(0, _("Full path: ") + name)
            item.setData(0, NAME_ROLE, name)
            item.setData(0, CATEGORY_ROLE, category)
            item.setData(0, LINEAR_ROLE, bool(linear))
            item.setData(0, MIME_ROLE, imt)
            set_display_name(name, item)
            tooltips = []
            emblems = []
            if name in {cover_page_name, cover_image_name}:
                emblems.append("default_cover.png")
                tooltips.append(
                    _("This file is the cover %s for this book")
                    % (_("image") if name == cover_image_name else _("page"))
                )
            if name in container.opf_name:
                emblems.append("metadata.png")
                tooltips.append(_("This file contains all the metadata and book structure information"))
            if imt == ncx_mime or name in nav_items:
                emblems.append("toc.png")
                tooltips.append(_("This file contains the metadata table of contents"))
            if name not in manifested_names and not container.ok_to_be_unmanifested(name):
                emblems.append("dialog_question.png")
                tooltips.append(_("This file is not listed in the book manifest"))
            if linear is False:
                emblems.append("arrow-down.png")
                tooltips.append(
                    _("This file is marked as non-linear in the spine\nDrag it to the top to make it linear")
                )
            if linear is None and icat == "text":
                # Text item outside spine
                emblems.append("dialog_warning.png")
                tooltips.append(_("This file is a text file that is not referenced in the spine"))
            if category == "text" and name in processed:
                # Duplicate entry in spine
                emblems.append("dialog_error.png")
                tooltips.append(_("This file occurs more than once in the spine"))

            render_emblems(item, emblems)
            if tooltips:
                item.setData(0, Qt.ToolTipRole, "\n".join(tooltips))
            return item