本文整理汇总了Python中PyQt4.Qt.QTreeWidgetItem.setFlags方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem.setFlags方法的具体用法?Python QTreeWidgetItem.setFlags怎么用?Python QTreeWidgetItem.setFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QTreeWidgetItem
的用法示例。
在下文中一共展示了QTreeWidgetItem.setFlags方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_item
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [as 别名]
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)
# 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
示例2: process_duplicates
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [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
示例3: create_item
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [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
示例4: process_duplicates
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [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
示例5: build_dictionaries
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [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()
示例6: add_child
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [as 别名]
def add_child(text):
c = QTreeWidgetItem([text], 1)
c.setFlags(Qt.ItemIsEnabled)
item.addChild(c)
return c
示例7: build
# 需要导入模块: from PyQt4.Qt import QTreeWidgetItem [as 别名]
# 或者: from PyQt4.Qt.QTreeWidgetItem import setFlags [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)