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


Python QTreeWidgetItem.setData方法代码示例

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


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

示例1: process_duplicates

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
    def process_duplicates(self, db, duplicates):
        ta = _('%(title)s by %(author)s')
        bf = QFont(self.dup_list.font())
        bf.setBold(True)
        itf = QFont(self.dup_list.font())
        itf.setItalic(True)

        for mi, cover, formats in duplicates:
            item = QTreeWidgetItem([ta%dict(
                title=mi.title, author=mi.format_field('authors')[1])] , 0)
            item.setCheckState(0, Qt.Checked)
            item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable)
            item.setData(0, Qt.FontRole, bf)
            item.setData(0, Qt.UserRole, (mi, cover, formats))
            matching_books = db.books_with_same_title(mi)

            def add_child(text):
                c = QTreeWidgetItem([text], 1)
                c.setFlags(Qt.ItemIsEnabled)
                item.addChild(c)
                return c

            add_child(_('Already in calibre:')).setData(0, Qt.FontRole, itf)

            for book_id in matching_books:
                aut = [a.replace('|', ',') for a in (db.authors(book_id,
                    index_is_id=True) or '').split(',')]
                add_child(ta%dict(
                    title=db.title(book_id, index_is_id=True),
                    author=authors_to_string(aut)))
            add_child('')

            yield item
开发者ID:john-peterson,项目名称:calibre,代码行数:35,代码来源:duplicates.py

示例2: create_item

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
        def create_item(name, linear=None):
            imt = container.mime_map.get(name, guess_type(name))
            icat = get_category(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
            item.setFlags(flags)
            item.setStatusTip(0, _('Full path: ') + name)
            item.setData(0, NAME_ROLE, name)
            item.setData(0, CATEGORY_ROLE, category)
            set_display_name(name, item)
            # TODO: Add appropriate tooltips based on the emblems
            emblems = []
            if name in {cover_page_name, cover_image_name}:
                emblems.append('default_cover.png')
            if name not in manifested_names and name not in ok_to_be_unmanifested:
                emblems.append('dialog_question.png')
            if linear is False:
                emblems.append('arrow-down.png')
            if linear is None and icat == 'text':
                # Text item outside spine
                emblems.append('dialog_warning.png')
            if category == 'text' and name in processed:
                # Duplicate entry in spine
                emblems.append('dialog_warning.png')

            render_emblems(item, emblems)
            return item
开发者ID:michaelbrawn,项目名称:calibre,代码行数:32,代码来源:file_list.py

示例3: create_item

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
 def create_item(self, f, parent):
     name = f.name
     ans = QTreeWidgetItem(parent, [name])
     ans.setData(0, Qt.UserRole, '/'.join(f.full_path[1:]))
     ans.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
     ans.setCheckState(0,
         Qt.Unchecked if self.dev.is_folder_ignored(f.storage_id, f.full_path[1:]) else Qt.Checked)
     ans.setData(0, Qt.DecorationRole, file_icon_provider().icon_from_ext('dir'))
     return ans
开发者ID:089git,项目名称:calibre,代码行数:11,代码来源:mtp_folder_browser.py

示例4: process_node

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
 def process_node(toc, parent):
     for child in toc:
         node = QTreeWidgetItem(parent)
         node.setText(0, child.title or '')
         node.setData(0, DEST_ROLE, child.dest or '')
         node.setData(0, FRAG_ROLE, child.frag or '')
         tt = _('File: {0}\nAnchor: {1}').format(
             child.dest or '', child.frag or _('Top of file'))
         node.setData(0, Qt.ToolTipRole, tt)
         process_node(child, node)
开发者ID:089git,项目名称:calibre,代码行数:12,代码来源:toc.py

示例5: item

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
def item(f, parent):
    name = f.name
    if not f.is_folder:
        name += ' [%s]'%f.last_mod_string
    ans = QTreeWidgetItem(parent, [name])
    ans.setData(0, Qt.UserRole, f.full_path)
    if f.is_folder:
        ext = 'dir'
    else:
        ext = f.name.rpartition('.')[-1]
    ans.setData(0, Qt.DecorationRole, file_icon_provider().icon_from_ext(ext))

    return ans
开发者ID:yeyanchao,项目名称:calibre,代码行数:15,代码来源:mtp_folder_browser.py

示例6: process_duplicates

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
    def process_duplicates(self, db, duplicates):
        ta = _('%(title)s by %(author)s [%(formats)s]')
        bf = QFont(self.dup_list.font())
        bf.setBold(True)
        itf = QFont(self.dup_list.font())
        itf.setItalic(True)

        for mi, cover, formats in duplicates:
            # formats is a list of file paths
            # Grab just the extension and display to the user
            # Based only off the file name, no file type tests are done.
            incoming_formats = ', '.join(os.path.splitext(path)[-1].replace('.', '').upper() for path in formats)
            item = QTreeWidgetItem([ta%dict(
                title=mi.title, author=mi.format_field('authors')[1],
                formats=incoming_formats)] , 0)
            item.setCheckState(0, Qt.Checked)
            item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable)
            item.setData(0, Qt.FontRole, bf)
            item.setData(0, Qt.UserRole, (mi, cover, formats))
            matching_books = db.books_with_same_title(mi)

            def add_child(text):
                c = QTreeWidgetItem([text], 1)
                c.setFlags(Qt.ItemIsEnabled)
                item.addChild(c)
                return c

            add_child(_('Already in calibre:')).setData(0, Qt.FontRole, itf)

            for book_id in matching_books:
                aut = [a.replace('|', ',') for a in (db.authors(book_id,
                    index_is_id=True) or '').split(',')]
                add_child(ta%dict(
                    title=db.title(book_id, index_is_id=True),
                    author=authors_to_string(aut),
                    formats=db.formats(book_id, index_is_id=True,
                                       verify_formats=False)))
            add_child('')

            yield item
开发者ID:089git,项目名称:calibre,代码行数:42,代码来源:duplicates.py

示例7: build_dictionaries

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
    def build_dictionaries(self, reread=False):
        all_dictionaries = builtin_dictionaries() | custom_dictionaries(reread=reread)
        languages = defaultdict(lambda : defaultdict(set))
        for d in all_dictionaries:
            for locale in d.locales | {d.primary_locale}:
                languages[locale.langcode][locale.countrycode].add(d)
        bf = QFont(self.dictionaries.font())
        bf.setBold(True)
        itf = QFont(self.dictionaries.font())
        itf.setItalic(True)
        self.dictionaries.clear()

        for lc in sorted(languages, key=lambda x:sort_key(calibre_langcode_to_name(x))):
            i = QTreeWidgetItem(self.dictionaries, LANG)
            i.setText(0, calibre_langcode_to_name(lc))
            i.setData(0, Qt.UserRole, lc)
            best_country = getattr(best_locale_for_language(lc), 'countrycode', None)
            for countrycode in sorted(languages[lc], key=lambda x: country_map()['names'].get(x, x)):
                j = QTreeWidgetItem(i, COUNTRY)
                j.setText(0, country_map()['names'].get(countrycode, countrycode))
                j.setData(0, Qt.UserRole, countrycode)
                if countrycode == best_country:
                    j.setData(0, Qt.FontRole, bf)
                pd = get_dictionary(DictionaryLocale(lc, countrycode))
                for dictionary in sorted(languages[lc][countrycode], key=lambda d:d.name):
                    k = QTreeWidgetItem(j, DICTIONARY)
                    pl = calibre_langcode_to_name(dictionary.primary_locale.langcode)
                    if dictionary.primary_locale.countrycode:
                        pl += '-' + dictionary.primary_locale.countrycode.upper()
                    k.setText(0, dictionary.name or (_('<Builtin dictionary for {0}>').format(pl)))
                    k.setData(0, Qt.UserRole, dictionary)
                    if dictionary.name:
                        k.setFlags(k.flags() | Qt.ItemIsEditable)
                    if pd == dictionary:
                        k.setData(0, Qt.FontRole, itf)

        self.dictionaries.expandAll()
开发者ID:charliehower,项目名称:calibre,代码行数:39,代码来源:spell.py

示例8: build

# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setData [as 别名]
    def build(self, container):
        self.clear()
        self.root = self.invisibleRootItem()
        self.root.setFlags(Qt.ItemIsDragEnabled)
        self.categories = {}
        for category, text, icon in (
            ('text', _('Text'), 'keyboard-prefs.png'),
            ('styles', _('Styles'), 'lookfeel.png'),
            ('images', _('Images'), 'view-image.png'),
            ('fonts', _('Fonts'), 'font.png'),
            ('misc', _('Miscellaneous'), 'mimetypes/dir.png'),
        ):
            self.categories[category] = i = QTreeWidgetItem(self.root, 0)
            i.setText(0, text)
            i.setIcon(0, QIcon(I(icon)))
            f = i.font(0)
            f.setBold(True)
            i.setFont(0, f)
            i.setData(0, NAME_ROLE, category)
            flags = Qt.ItemIsEnabled
            if category == 'text':
                flags |= Qt.ItemIsDropEnabled
            i.setFlags(flags)

        processed, seen = set(), {}

        def get_display_name(name, item):
            parts = name.split('/')
            text = parts[-1]
            while text in seen and parts:
                text = parts.pop() + '/' + text
            seen[text] = item
            return text

        for name, linear in container.spine_names:
            processed.add(name)
            i = QTreeWidgetItem(self.categories['text'], 1)
            prefix = '' if linear else '[nl] '
            if not linear:
                i.setIcon(self.non_linear_icon)
            i.setText(0, prefix + get_display_name(name, i))
            i.setStatusTip(0, _('Full path: ') + name)
            i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable)
            i.setData(0, NAME_ROLE, name)

        font_types = {guess_type('a.'+x)[0] for x in ('ttf', 'otf', 'woff')}

        def get_category(mt):
            category = 'misc'
            if mt.startswith('image/'):
                category = 'images'
            elif mt in font_types:
                category = 'fonts'
            elif mt in OEB_STYLES:
                category = 'styles'
            return category

        all_files = list(container.manifest_type_map.iteritems())
        all_files.append((guess_type('a.opf')[0], [container.opf_name]))

        for name in container.name_path_map:
            if name in processed:
                continue
            processed.add(name)
            imt = container.mime_map.get(name, guess_type(name)[0])
            icat = get_category(imt)
            i = QTreeWidgetItem(self.categories[icat], 1)
            i.setText(0, get_display_name(name, i))
            i.setStatusTip(0, _('Full path: ') + name)
            i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
            i.setData(0, NAME_ROLE, name)

        for c in self.categories.itervalues():
            self.expandItem(c)
开发者ID:shootstar,项目名称:calibre,代码行数:76,代码来源:file_list.py


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