本文整理汇总了Python中PyQt4.Qt.QTreeWidgetItem类的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidgetItem类的具体用法?Python QTreeWidgetItem怎么用?Python QTreeWidgetItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTreeWidgetItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateMessageView
def updateMessageView(self, maxcount = 0):
maxcount = maxcount or 200
mt = self.ui.messageTable
items = [ (n, str(i.text(1)), mt.itemWidget(i, 0), i)
for n, i in enumerate(map(lambda n:mt.topLevelItem(n),
range(mt.topLevelItemCount()))) ]
pids = [ str(item[2].id.text()) for item in items ]
olditems = list(items)
olds = list(pids)
n = 0
self.app.icons.avatar_cache = {}
messages = self.app.db.get_messages_from_cache(maxcount)
print "* update message view", len(messages)
for _blob in messages:
blob = prepare_post(_blob.__dict__)
if str(blob.pid) in olds:
i = olds.index(str(blob.pid))
olditems.pop(i)
olds.pop(i)
if str(blob.pid) not in pids:
pids.append(blob.pid)
msg, time = self.build_message_item(blob)
i = QTreeWidgetItem(mt)
i.setText(1, time)
mt.setItemWidget(i, 0, msg)
# now remove the too old ones
items.sort(key=lambda i:i[1])
for old in list(reversed(items))[maxcount-1:] + olditems:
mt.removeItemWidget(old[3], 0)
item = old[2]
del item
示例2: __init__
def __init__(self, parent, name=None):
QTreeWidgetItem.__init__(self)
self.filterList = ('mmp', 'MMP')
if isinstance(parent, QListView):
self.p = None
if name:
self.f = name
else:
self.f = '/'
else:
self.p = parent
self.f = name
self.readable = QDir( self.fullName() ).isReadable()
if not self.readable :
self.setIcon(0, folderLockedIcon)
else:
self.setIcon(0, folderClosedIcon)
if name is not None:
self.setText(1, name)
if isinstance(parent, QTreeWidget):
parent.addTopLevelItem(self)
else:
parent.addChild(self)
示例3: create_folder
def create_folder(self, item):
text, ok = QInputDialog.getText(self, _('Folder name'), _('Enter a name for the new folder'))
if ok and unicode(text):
c = QTreeWidgetItem(item, (unicode(text),))
c.setIcon(0, QIcon(I('mimetypes/dir.png')))
for item in self.folders.selectedItems():
item.setSelected(False)
c.setSelected(True)
self.folders.setCurrentItem(c)
示例4: process_duplicates
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
示例5: create_item
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
示例6: __init__
def __init__(self, parent, device):
QTreeWidgetItem.__init__(self, parent)
self._device = device
self.setText(0, device.lvname)
mountpoint = getattr(device.format, "mountpoint", "")
if not mountpoint:
mountpoint = ""
elif not (device.format and device.format.mountable):
mountpoint = "N/A"
self.setText(1, mountpoint)
self.setText(2, "%Ld" % device.size)
示例7: create_item
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
示例8: item
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
示例9: readControlFile
def readControlFile(self, filename):
self.control = controlPoints(self.N,filename)
# obs=obsSplit(obs)
for x,y in self.control.iteritems():
#print coord
item = QTreeWidgetItem(self.treeControl)
item.setText(0, x)
item.setText(1, str(round(y.y,3)))
item.setText(2, str(round(y.x,3)))
item.setText(3, str(round(y.h,3)))
item.setCheckState(0, Qt.Checked)
示例10: __init__
def __init__(self, src, *args):
QTreeWidgetItem.__init__(self, *args)
self._src = src
# fonts
self._initFonts()
# array of actual (i.e. numeric) column values
self._values = [None] * NumColumns
# set text alignment
for icol in range(NumColumns):
self.setTextAlignment(icol, Qt.AlignLeft)
self.setTextAlignment(ColumnR, Qt.AlignRight)
self.setTextAlignment(ColumnType, Qt.AlignHCenter)
# setup source
self._highlighted = self._highlighted_visual = False
self.setSource(src)
示例11: setup_ui
def setup_ui(self):
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.msg = m = QLabel(self.msg or _(
'Choose the folder into which the files will be placed'))
l.addWidget(m)
m.setWordWrap(True)
self.folders = f = QTreeWidget(self)
f.setHeaderHidden(True)
f.itemDoubleClicked.connect(self.accept)
l.addWidget(f)
f.setContextMenuPolicy(Qt.CustomContextMenu)
f.customContextMenuRequested.connect(self.show_context_menu)
self.root = QTreeWidgetItem(f, ('/',))
def process(node, parent):
parent.setIcon(0, QIcon(I('mimetypes/dir.png')))
for child in sorted(node, key=sort_key):
c = QTreeWidgetItem(parent, (child,))
process(node[child], c)
process(create_folder_tree(current_container()), self.root)
self.root.setSelected(True)
f.expandAll()
l.addWidget(self.bb)
示例12: ChooseFolder
class ChooseFolder(Dialog): # {{{
def __init__(self, msg=None, parent=None):
self.msg = msg
Dialog.__init__(self, _('Choose folder'), 'choose-folder', parent=parent)
def setup_ui(self):
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.msg = m = QLabel(self.msg or _(
'Choose the folder into which the files will be placed'))
l.addWidget(m)
m.setWordWrap(True)
self.folders = f = QTreeWidget(self)
f.setHeaderHidden(True)
f.itemDoubleClicked.connect(self.accept)
l.addWidget(f)
self.root = QTreeWidgetItem(f, ('/',))
def process(node, parent):
parent.setIcon(0, QIcon(I('mimetypes/dir.png')))
for child in sorted(node, key=sort_key):
c = QTreeWidgetItem(parent, (child,))
process(node[child], c)
process(create_folder_tree(current_container()), self.root)
self.root.setSelected(True)
f.expandAll()
l.addWidget(self.bb)
def folder_path(self, item):
ans = []
while item is not self.root:
ans.append(unicode(item.text(0)))
item = item.parent()
return tuple(reversed(ans))
@property
def chosen_folder(self):
try:
return '/'.join(self.folder_path(self.folders.selectedItems()[0]))
except IndexError:
return ''
示例13: showConversation
def showConversation(self, item, _):
mt = self.ui.messageTable
msg = mt.itemWidget(item, 0)
if item.isExpanded():
msg.replyLabel.setVisible(True)
return # allready added
if not msg.replyLabel.isVisible():
return # no conversation
msg.replyLabel.setVisible(False)
if item.childCount(): return # allready added
messages = self.app.db.get_conversation_messages(int(msg.id.text()))
for _blob in messages:
blob = prepare_post(_blob.__dict__)
msg, time = self.build_message_item(blob)
msg.replyLabel.setVisible(False) # no conversation trees possible
i = QTreeWidgetItem(item)
i.setText(1, time)
mt.setItemWidget(i, 0, msg)
示例14: updateProv
def updateProv(self):
self.treeProvis.clear()
for x,y in self.provis.iteritems():
item = QTreeWidgetItem(self.treeProvis)
item.setText(0, x)
item.setText(1, str(round(y.y,3)))
item.setText(2, str(round(y.x,3)))
item.setText(3, str(round(y.h,3)))
示例15: process_node
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)