本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setAnimated方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setAnimated方法的具体用法?Python QTreeWidget.setAnimated怎么用?Python QTreeWidget.setAnimated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setAnimated方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ErrorsTree
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class ErrorsTree(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
IDE.register_service("errors_tree", self)
box = QVBoxLayout(self)
box.setContentsMargins(0, 0, 0, 0)
self._tree = QTreeWidget()
self._tree.header().setHidden(True)
self._tree.setAnimated(True)
box.addWidget(self._tree)
def refresh(self, errors, path):
self._tree.clear()
parent = QTreeWidgetItem(self._tree, [path])
for lineno, msg in errors.items():
item = QTreeWidgetItem(parent, [msg])
self._tree.addTopLevelItem(item)
def display_name(self):
return 'Errors'
示例2: AddToProject
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class AddToProject(QDialog):
def __init__(self, pathProjects, parent=None):
#pathProjects must be a list
super(AddToProject, self).__init__(parent)
self.setWindowTitle(_translate("AddToProject", "Add File to Project"))
self.pathSelected = ''
vbox = QVBoxLayout(self)
self._tree = QTreeWidget()
self._tree.header().setHidden(True)
self._tree.setSelectionMode(QTreeWidget.SingleSelection)
self._tree.setAnimated(True)
vbox.addWidget(self._tree)
hbox = QHBoxLayout()
btnAdd = QPushButton(_translate("AddToProject", "Add here!"))
btnCancel = QPushButton(_translate("AddToProject", "Cancel"))
hbox.addWidget(btnCancel)
hbox.addWidget(btnAdd)
vbox.addLayout(hbox)
#load folders
self._root = None
self._loading_items = {}
self.loading_projects(pathProjects)
self._thread_execution = ThreadExecution(
self._thread_load_projects, args=[pathProjects])
self._thread_execution.finished.connect(self._callback_load_project)
self._thread_execution.start()
btnCancel.clicked['bool'].connect(self.close)
btnAdd.clicked['bool'].connect(self._select_path)
def loading_projects(self, projects):
for project in projects:
loadingItem = LoadingItem()
item = loadingItem.add_item_to_tree(project, self._tree,
parent=self)
self._loading_items[project] = item
def _thread_load_projects(self, projects):
structures = []
for pathProject in projects:
folderStructure = file_manager.open_project(pathProject)
structures.append((folderStructure, pathProject))
self._thread_execution.storage_values = structures
def _callback_load_project(self):
structures = self._thread_execution.storage_values
if structures:
for structure, path in structures:
item = self._loading_items.pop(path, None)
if item is not None:
index = self._tree.indexOfTopLevelItem(item)
self._tree.takeTopLevelItem(index)
self._load_project(structure, path)
def _select_path(self):
item = self._tree.currentItem()
if item:
self.pathSelected = item.toolTip(0)
self.close()
def _load_project(self, folderStructure, folder):
if not folder:
return
name = file_manager.get_basename(folder)
item = QTreeWidgetItem(self._tree)
item.setText(0, name)
item.setToolTip(0, folder)
item.setIcon(0, QIcon(resources.IMAGES['tree-folder']))
if folderStructure[folder][1] is not None:
folderStructure[folder][1].sort()
self._load_folder(folderStructure, folder, item)
item.setExpanded(True)
self._root = item
def _load_folder(self, folderStructure, folder, parentItem):
items = folderStructure[folder]
if items[1] is not None:
items[1].sort()
for _file in items[1]:
if _file.startswith('.'):
continue
subfolder = QTreeWidgetItem(parentItem)
subfolder.setText(0, _file)
subfolder.setToolTip(0, os.path.join(folder, _file))
subfolder.setIcon(0, QIcon(resources.IMAGES['tree-folder']))
self._load_folder(folderStructure,
os.path.join(folder, _file), subfolder)
示例3: ImperiumWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class ImperiumWidget(QWidget):
def __init__(self, parent=None):
super(ImperiumWidget, self).__init__(parent)
# objects, sub-windows
self._world = XNovaWorld_instance()
self._layout = None
self._layout_topbuttons = None
self._tree = None
self._btn_reload = None
# initialization
self.setup_ui()
def setup_ui(self):
self._layout = QVBoxLayout()
self.setLayout(self._layout)
# create layout for top line of buttons
self._layout_topbuttons = QHBoxLayout()
self._layout.addLayout(self._layout_topbuttons)
# create reload button
self._btn_reload = QPushButton(self.tr('Refresh imperium'), self)
self._btn_reload.setIcon(QIcon(':i/reload.png'))
self._btn_reload.clicked.connect(self.on_btn_refresh_imperium)
self._layout_topbuttons.addWidget(self._btn_reload)
# finalize top buttons layout
self._layout_topbuttons.addStretch()
# create tree
self._tree = QTreeWidget(self)
self._tree.setAnimated(False)
self._tree.setExpandsOnDoubleClick(True)
self._tree.setHeaderHidden(False)
self._tree.setItemsExpandable(True)
self._tree.setRootIsDecorated(True)
self._tree.setSortingEnabled(False)
self._tree.setColumnCount(1)
self._tree.setHeaderLabels(['None'])
self._layout.addWidget(self._tree)
self._tree.show()
# called once after full world load
def update_planets(self):
def additem_helper(item_texts, twi_parent=None, align_flag=0):
# align_flag = Qt::AlignLeft / Qt::AlignRight / Qt::AlignHCenter
if align_flag == 0:
align_flag = Qt.AlignHCenter | Qt.AlignVCenter
twi = QTreeWidgetItem(item_texts)
for it_col in range(len(item_texts)):
if it_col > 0:
# void QTreeWidgetItem::setTextAlignment(int column, int alignment)
twi.setTextAlignment(it_col, align_flag)
if twi_parent is None:
self._tree.addTopLevelItem(twi)
else:
twi_parent.addChild(twi)
return True
self._tree.clear() # clear the tree first
planets = self._world.get_planets() # get planets from the world
#
# setup header and its labels
header_labels = ['-']
for i in range(len(planets)):
header_labels.append(planets[i].name)
header_labels.append(self.tr('Total')) # last column - totals
self._tree.setHeaderLabels(header_labels)
# alignment of text in header labels
self._tree.header().setDefaultAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
# default column widths
for i in range(len(planets)):
if i < 1:
self._tree.setColumnWidth(i, 150)
else:
self._tree.setColumnWidth(i, 75)
#
# planets names
item_strings = [self.tr('Name')]
for pl in planets:
item_strings.append(pl.name)
additem_helper(item_strings)
#
# planets coords
item_strings = [self.tr('Coords')]
for pl in planets:
item_strings.append('[{0}:{1}:{2}]'.format(pl.coords.galaxy, pl.coords.system, pl.coords.position))
additem_helper(item_strings)
#
# planets fields
item_strings = [self.tr('Fields')]
total_busy = 0
total_fields = 0
for pl in planets:
total_busy += pl.fields_busy
total_fields = pl.fields_total
item_strings.append('{0} / {1}'.format(pl.fields_busy, pl.fields_total))
item_strings.append('{0} / {1}'.format(total_busy, total_fields))
additem_helper(item_strings)
#
# resources
res_root = QTreeWidgetItem([self.tr('Resources')])
item_strings = [self.tr('Metal')]
total_res = 0
#.........这里部分代码省略.........
示例4: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class Preferences(QDialog):
#
configuration = {}
weight = 0
#
savePreferences = pyqtSignal()
#
def __init__(self, parent=None):
super(Preferences, self).__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(QSize(900, 600))
vbox = QVBoxLayout(self)
hbox = QHBoxLayout()
vbox.setContentsMargins(0, 0, 5, 5)
hbox.setContentsMargins(0, 0, 0, 0)
#
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setHorizontalScrollMode(
QAbstractItemView.ScrollPerPixel)
self.tree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
self.tree.header().setStretchLastSection(False)
self.tree.setFixedWidth(200)
self.stacked = QStackedLayout()
hbox.addWidget(self.tree)
hbox.addLayout(self.stacked)
vbox.addLayout(hbox)
#
hbox_footer = QHBoxLayout()
self._btnSave = QPushButton(translations.TR_SAVE)
self._btnCancel = QPushButton(translations.TR_CANCEL)
hbox_footer.addSpacerItem(QSpacerItem(1, 0, QSizePolicy.Expanding))
hbox_footer.addWidget(self._btnCancel)
hbox_footer.addWidget(self._btnSave)
vbox.addLayout(hbox_footer)
#
self.tree.itemSelectionChanged.connect(self._change_current)
self._btnCancel.clicked['bool'].connect(self.close)
self._btnSave.clicked['bool'].connect(self._save_preferences)
#
self.load_ui()
self.tree.setCurrentItem(self.tree.topLevelItem(0))
#
def _save_preferences(self):
self.savePreferences.emit()
self.close()
#
def load_ui(self):
sections = sorted(
list(Preferences.configuration.keys()),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
#
#Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(list(subcontent.keys()),
key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
#
self.tree.expandAll()
#
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
self.stacked.setCurrentIndex(index)
#
@classmethod
def register_configuration(cls, section, widget, text, weight=None,
subsection=None):
if weight is None:
Preferences.weight += 1
weight = Preferences.weight
if not subsection:
Preferences.configuration[section] = {'widget': widget,
'weight': weight,
#.........这里部分代码省略.........
示例5: FontsColors
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class FontsColors(preferences.Page):
def __init__(self, dialog):
super(FontsColors, self).__init__(dialog)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
self.scheme = SchemeSelector(self)
layout.addWidget(self.scheme)
self.printScheme = QCheckBox()
layout.addWidget(self.printScheme)
hbox = QHBoxLayout()
self.tree = QTreeWidget(self)
self.tree.setHeaderHidden(True)
self.tree.setAnimated(True)
self.stack = QStackedWidget(self)
hbox.addWidget(self.tree)
hbox.addWidget(self.stack)
layout.addLayout(hbox)
hbox = QHBoxLayout()
self.fontLabel = QLabel()
self.fontChooser = QFontComboBox()
self.fontSize = QDoubleSpinBox()
self.fontSize.setRange(6.0, 32.0)
self.fontSize.setSingleStep(0.5)
self.fontSize.setDecimals(1)
hbox.addWidget(self.fontLabel)
hbox.addWidget(self.fontChooser, 1)
hbox.addWidget(self.fontSize)
layout.addLayout(hbox)
# add the items to our list
self.baseColorsItem = i = QTreeWidgetItem()
self.tree.addTopLevelItem(i)
self.defaultStylesItem = i = QTreeWidgetItem()
self.tree.addTopLevelItem(i)
self.defaultStyles = {}
for name in textformats.defaultStyles:
self.defaultStyles[name] = i = QTreeWidgetItem()
self.defaultStylesItem.addChild(i)
i.name = name
self.defaultStylesItem.setExpanded(True)
self.allStyles = {}
for group, styles in ly.colorize.default_mapping():
i = QTreeWidgetItem()
children = {}
self.allStyles[group] = (i, children)
self.tree.addTopLevelItem(i)
i.group = group
for name, base, clss in styles:
j = QTreeWidgetItem()
j.name = name
j.base = base
i.addChild(j)
children[name] = j
self.baseColorsWidget = BaseColors(self)
self.customAttributesWidget = CustomAttributes(self)
self.emptyWidget = QWidget(self)
self.stack.addWidget(self.baseColorsWidget)
self.stack.addWidget(self.customAttributesWidget)
self.stack.addWidget(self.emptyWidget)
self.tree.currentItemChanged.connect(self.currentItemChanged)
self.tree.setCurrentItem(self.baseColorsItem)
self.scheme.currentChanged.connect(self.currentSchemeChanged)
self.scheme.changed.connect(self.changed)
self.baseColorsWidget.changed.connect(self.baseColorsChanged)
self.customAttributesWidget.changed.connect(self.customAttributesChanged)
self.fontChooser.currentFontChanged.connect(self.fontChanged)
self.fontSize.valueChanged.connect(self.fontChanged)
self.printScheme.clicked.connect(self.printSchemeChanged)
app.translateUI(self)
def translateUI(self):
self.printScheme.setText(_("Use this scheme for printing"))
self.fontLabel.setText(_("Font:"))
self.baseColorsItem.setText(0, _("Base Colors"))
self.defaultStylesItem.setText(0, _("Default Styles"))
self.defaultStyleNames = defaultStyleNames()
self.allStyleNames = allStyleNames()
for name in textformats.defaultStyles:
self.defaultStyles[name].setText(0, self.defaultStyleNames[name])
for group, styles in ly.colorize.default_mapping():
try:
n = self.allStyleNames[group][0]
except KeyError:
n = group
self.allStyles[group][0].setText(0, n)
for name, base, clss in styles:
try:
#.........这里部分代码省略.........
示例6: Shortcuts
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class Shortcuts(preferences.Page):
def __init__(self, dialog):
super(Shortcuts, self).__init__(dialog)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(layout)
self.scheme = SchemeSelector(self)
layout.addWidget(self.scheme)
self.searchEntry = LineEdit()
self.searchEntry.setPlaceholderText(_("Search..."))
layout.addWidget(self.searchEntry)
self.tree = QTreeWidget(self)
self.tree.setHeaderLabels([_("Command"), _("Shortcut")])
self.tree.setRootIsDecorated(False)
self.tree.setColumnCount(2)
self.tree.setAllColumnsShowFocus(True)
self.tree.setAnimated(True)
layout.addWidget(self.tree)
self.edit = QPushButton(icons.get("preferences-desktop-keyboard-shortcuts"), '')
layout.addWidget(self.edit)
# signals
self.searchEntry.textChanged.connect(self.updateFilter)
self.scheme.currentChanged.connect(self.slotSchemeChanged)
self.scheme.changed.connect(self.changed)
self.tree.currentItemChanged.connect(self.slotCurrentItemChanged)
self.tree.itemDoubleClicked.connect(self.editCurrentItem)
self.edit.clicked.connect(self.editCurrentItem)
# make a dict of all actions with the actions as key and the names as
# value, with the collection prepended (for loading/saving)
win = dialog.parent()
allactions = {}
for collection in actioncollectionmanager.manager(win).actionCollections():
for name, action in collection.actions().items():
allactions[action] = (collection, name)
# keep a list of actions not in the menu structure
left = list(allactions.keys())
def add_actions(menuitem, actions):
"""Add actions to a QTreeWidgetItem."""
for a in actions:
if a.menu():
item = build_menu_item(a)
if item.childCount():
menuitem.addChild(item)
elif a in left:
left.remove(a)
menuitem.addChild(ShortcutItem(a, *allactions[a]))
menuitem.setFlags(Qt.ItemIsEnabled) # disable selection
def build_menu_item(action):
"""Return a QTreeWidgetItem with children for all the actions in the submenu."""
menuitem = QTreeWidgetItem()
text = qutil.removeAccelerator(action.text())
menuitem.setText(0, _("Menu {name}").format(name=text))
add_actions(menuitem, action.menu().actions())
return menuitem
# present the actions nicely ordered as in the menus
for a in win.menuBar().actions():
menuitem = build_menu_item(a)
if menuitem.childCount():
self.tree.addTopLevelItem(menuitem)
# sort leftover actions
left.sort(key=lambda i: i.text())
# show actions that are left, grouped by collection
titlegroups = {}
for a in left[:]: # copy
collection, name = allactions[a]
if collection.title():
titlegroups.setdefault(collection.title(), []).append(a)
left.remove(a)
for title in sorted(titlegroups):
item = QTreeWidgetItem(["{0}:".format(title)])
for a in titlegroups[title]:
item.addChild(ShortcutItem(a, *allactions[a]))
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
# show other actions that were not in the menus
item = QTreeWidgetItem([_("Other commands:")])
for a in left:
if a.text() and not a.menu():
item.addChild(ShortcutItem(a, *allactions[a]))
if item.childCount():
self.tree.addTopLevelItem(item)
item.setFlags(Qt.ItemIsEnabled) # disable selection
self.tree.expandAll()
item = self.tree.topLevelItem(0).child(0)
if _lastaction:
# find the previously selected item
#.........这里部分代码省略.........
示例7: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setAnimated [as 别名]
class Preferences(QDialog):
configuration = {}
weight = 0
# Signals
savePreferences = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent, Qt.Dialog)
self.setWindowTitle(translations.TR_PREFERENCES_TITLE)
self.setMinimumSize(900, 650)
box = QVBoxLayout(self)
box.setContentsMargins(3, 3, 3, 3)
self.setAutoFillBackground(True)
# Header
self._header_label = QLabel("")
header_font = self._header_label.font()
header_font.setBold(True)
header_font.setPointSize(header_font.pointSize() + 4)
self._header_label.setFont(header_font)
hbox = QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
self.tree = QTreeWidget()
self.tree.header().setHidden(True)
self.tree.setSelectionMode(QTreeWidget.SingleSelection)
self.tree.setAnimated(True)
self.tree.header().setSectionResizeMode(
0, QHeaderView.ResizeToContents)
self.tree.setFixedWidth(200)
hbox.addWidget(self.tree)
self.stacked = QStackedLayout()
header_layout = QVBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(self._header_label)
header_layout.addLayout(self.stacked)
hbox.addLayout(header_layout)
box.addLayout(hbox)
# Footer buttons
button_box = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
box.addWidget(button_box)
# Connections
button_box.rejected.connect(self.close)
button_box.accepted.connect(self._save_preferences)
self.tree.selectionModel().currentRowChanged.connect(
self._change_current)
self.load_ui()
@pyqtSlot()
def _save_preferences(self):
self.savePreferences.emit()
self.close()
def load_ui(self):
sections = sorted(
Preferences.configuration.keys(),
key=lambda item: Preferences.configuration[item]['weight'])
for section in sections:
text = Preferences.configuration[section]['text']
Widget = Preferences.configuration[section]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
item = QTreeWidgetItem([text])
item.setData(0, Qt.UserRole, index)
self.tree.addTopLevelItem(item)
# Sort Item Children
subcontent = Preferences.configuration[section].get(
'subsections', {})
subsections = sorted(
subcontent.keys(), key=lambda item: subcontent[item]['weight'])
for sub in subsections:
text = subcontent[sub]['text']
Widget = subcontent[sub]['widget']
widget = Widget(self)
area = QScrollArea()
area.setWidgetResizable(True)
area.setWidget(widget)
self.stacked.addWidget(area)
index = self.stacked.indexOf(area)
subitem = QTreeWidgetItem([text])
subitem.setData(0, Qt.UserRole, index)
item.addChild(subitem)
self.tree.expandAll()
self.tree.setCurrentIndex(self.tree.model().index(0, 0))
def _change_current(self):
item = self.tree.currentItem()
index = item.data(0, Qt.UserRole)
#.........这里部分代码省略.........