本文整理汇总了Python中PyQt5.QtWidgets.QTreeWidget.setCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setCurrentItem方法的具体用法?Python QTreeWidget.setCurrentItem怎么用?Python QTreeWidget.setCurrentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTreeWidget
的用法示例。
在下文中一共展示了QTreeWidget.setCurrentItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigurationWidget
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
#.........这里部分代码省略.........
if page is not None:
self.configStack.addWidget(page)
pageData[-1] = page
try:
page.setMode(self.displayMode)
except AttributeError:
pass
return page
def showConfigurationPageByName(self, pageName, setCurrent=True):
"""
Public slot to show a named configuration page.
@param pageName name of the configuration page to show (string)
@param setCurrent flag indicating to set the current item (boolean)
"""
if pageName == "empty" or pageName not in self.configItems:
page = self.emptyPage
else:
pageData = self.configItems[pageName]
if pageData[-1] is None and pageData[2] is not None:
# the page was not loaded yet, create it
page = self.__initPage(pageData)
else:
page = pageData[-1]
if page is None:
page = self.emptyPage
elif setCurrent:
items = self.configList.findItems(
pageData[0],
Qt.MatchFixedString | Qt.MatchRecursive)
for item in items:
if item.data(0, Qt.UserRole) == pageName:
self.configList.setCurrentItem(item)
self.configStack.setCurrentWidget(page)
ssize = self.scrollArea.size()
if self.scrollArea.horizontalScrollBar():
ssize.setHeight(
ssize.height() -
self.scrollArea.horizontalScrollBar().height() - 2)
if self.scrollArea.verticalScrollBar():
ssize.setWidth(
ssize.width() -
self.scrollArea.verticalScrollBar().width() - 2)
psize = page.minimumSizeHint()
self.configStack.resize(max(ssize.width(), psize.width()),
max(ssize.height(), psize.height()))
if page != self.emptyPage:
page.polishPage()
self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(True)
self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(True)
else:
self.buttonBox.button(QDialogButtonBox.Apply).setEnabled(False)
self.buttonBox.button(QDialogButtonBox.Reset).setEnabled(False)
# reset scrollbars
for sb in [self.scrollArea.horizontalScrollBar(),
self.scrollArea.verticalScrollBar()]:
if sb:
sb.setValue(0)
self.__currentConfigurationPageName = pageName
def getConfigurationPageName(self):
"""
示例2: MiscTab
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
class MiscTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.name = self.tr("Misc")
self.markColorLabel = QLabel(self.tr("Default flag colors:"), self)
# TODO: enforce duplicate names avoidance
self.markColorWidget = QTreeWidget(self)
self.markColorWidget.setHeaderLabels(
(self.tr("Color"), self.tr("Name")))
self.markColorWidget.setRootIsDecorated(False)
self.markColorWidget.setSelectionBehavior(
QAbstractItemView.SelectRows)
# TODO: make this work correctly, top-level items only
# self.markColorWidget.setDragDropMode(QAbstractItemView.InternalMove)
self.addItemButton = QPushButton("+", self)
self.addItemButton.clicked.connect(self.addItem)
self.removeItemButton = QPushButton("−", self)
self.removeItemButton.clicked.connect(self.removeItem)
self.loadRecentFileBox = QCheckBox(
self.tr("Load most recent file on start"), self)
layout = QGridLayout(self)
l = 0
layout.addWidget(self.markColorLabel, l, 0, 1, 3)
l += 1
layout.addWidget(self.markColorWidget, l, 0, 1, 3)
l += 1
layout.addWidget(self.addItemButton, l, 0)
layout.addWidget(self.removeItemButton, l, 1)
l += 1
layout.addWidget(self.loadRecentFileBox, l, 0, 1, 3)
self.setLayout(layout)
self.readSettings()
def addItem(self):
def mangleNewName():
name = self.tr("New")
index = 0
while self.markColorWidget.findItems(name, Qt.MatchExactly, 1):
index += 1
name = "{0} ({1})".format(name, index)
return name
# TODO: not DRY with ctor
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(QColor(Qt.white))
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, mangleNewName())
self.markColorWidget.setCurrentItem(item)
self.markColorWidget.editItem(item, 1)
self.removeItemButton.setEnabled(True)
def removeItem(self):
i = self.markColorWidget.selectionModel().currentIndex().row()
self.markColorWidget.takeTopLevelItem(i)
if not self.markColorWidget.topLevelItemCount():
self.removeItemButton.setEnabled(False)
def readSettings(self):
entries = settings.readMarkColors()
for name, color in entries.items():
item = QTreeWidgetItem(self.markColorWidget)
item.setFlags(item.flags() | Qt.ItemIsEditable)
widget = ColorVignette(self)
widget.setColor(color)
widget.setMargins(2, 2, 2, 2)
widget.setMayClearColor(False)
self.markColorWidget.setItemWidget(item, 0, widget)
item.setText(1, name)
if not len(entries):
self.removeItemButton.setEnabled(False)
loadRecentFile = settings.loadRecentFile()
self.loadRecentFileBox.setChecked(loadRecentFile)
def writeSettings(self):
markColors = OrderedDict()
for i in range(self.markColorWidget.topLevelItemCount()):
item = self.markColorWidget.topLevelItem(i)
name = item.text(1)
color = self.markColorWidget.itemWidget(item, 0).color()
markColors[name] = color
settings.writeMarkColors(markColors)
loadRecentFile = self.loadRecentFileBox.isChecked()
settings.setLoadRecentFile(loadRecentFile)
示例3: DebugViewer
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
#.........这里部分代码省略.........
self.framenr = frmnr
self.debugServer.remoteClientVariables(0, self.localsFilter, frmnr)
if self.__autoViewSource:
self.__showSource()
def __setGlobalsFilter(self):
"""
Private slot to set the global variable filter.
"""
filter = self.globalsFilterEdit.text()
self.debugServer.remoteClientSetFilter(1, filter)
self.debugServer.remoteClientVariables(2, self.globalsFilter)
def __setLocalsFilter(self):
"""
Private slot to set the local variable filter.
"""
filter = self.localsFilterEdit.text()
self.debugServer.remoteClientSetFilter(0, filter)
if self.currentStack:
self.debugServer.remoteClientVariables(
0, self.localsFilter, self.framenr)
def handleDebuggingStarted(self):
"""
Public slot to handle the start of a debugging session.
This slot sets the variables filter expressions.
"""
self.__setGlobalsFilter()
self.__setLocalsFilter()
self.showVariablesTab(False)
def currentWidget(self):
"""
Public method to get a reference to the current widget.
@return reference to the current widget (QWidget)
"""
return self.__tabWidget.currentWidget()
def setCurrentWidget(self, widget):
"""
Public slot to set the current page based on the given widget.
@param widget reference to the widget (QWidget)
"""
self.__tabWidget.setCurrentWidget(widget)
def showThreadList(self, currentID, threadList):
"""
Public method to show the thread list.
@param currentID id of the current thread (integer)
@param threadList list of dictionaries containing the thread data
"""
citm = None
self.__threadList.clear()
for thread in threadList:
if thread['broken']:
state = self.tr("waiting at breakpoint")
else:
state = self.tr("running")
itm = QTreeWidgetItem(self.__threadList,
["{0:d}".format(thread['id']),
thread['name'], state])
if thread['id'] == currentID:
citm = itm
self.__threadList.header().resizeSections(QHeaderView.ResizeToContents)
self.__threadList.header().setStretchLastSection(True)
if citm:
self.__doThreadListUpdate = False
self.__threadList.setCurrentItem(citm)
self.__doThreadListUpdate = True
def __threadSelected(self, current, previous):
"""
Private slot to handle the selection of a thread in the thread list.
@param current reference to the new current item (QTreeWidgetItem)
@param previous reference to the previous current item
(QTreeWidgetItem)
"""
if current is not None and self.__doThreadListUpdate:
tid = int(current.text(0))
self.debugServer.remoteSetThread(tid)
def __callStackFrameSelected(self, frameNo):
"""
Private slot to handle the selection of a call stack entry of the
call stack viewer.
@param frameNo frame number (index) of the selected entry (integer)
"""
if frameNo >= 0:
self.stackComboBox.setCurrentIndex(frameNo)
示例4: SessionsManager
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
class SessionsManager(QDialog):
"""Session Manager, to load different configurations of ninja."""
def __init__(self, parent=None):
super(SessionsManager, self).__init__(parent, Qt.Dialog)
self._ninja = parent
self.setModal(True)
self.setWindowTitle(translations.TR_SESSIONS_TITLE)
self.setMinimumWidth(550)
self.setMinimumHeight(450)
self._manager = _SessionManager(parent)
self._load_ui()
def install(self):
self._manager.load_sessions()
def _load_ui(self):
main_layout = QVBoxLayout(self)
main_layout.addWidget(QLabel(translations.TR_SESSIONS_DIALOG_BODY))
main_hbox = QHBoxLayout()
# Session list
session_layout = QVBoxLayout()
self._session_list = QTreeWidget()
self._session_list.setHeaderLabels(["Session", "Last Modified"])
session_layout.addWidget(self._session_list)
# Content frame
content_frame = QFrame()
content_frame.hide()
frame_layout = QVBoxLayout(content_frame)
content_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
session_layout.addWidget(content_frame)
frame_layout.setContentsMargins(0, 0, 0, 0)
self._content_list = QTreeWidget()
self._content_list.setHeaderHidden(True)
frame_layout.addWidget(self._content_list)
# Separator line
line_frame = QFrame()
line_frame.setFrameStyle(QFrame.VLine | QFrame.Sunken)
# Buttons
btn_layout = QVBoxLayout()
btn_create = QPushButton(translations.TR_SESSIONS_BTN_CREATE)
btn_activate = QPushButton(translations.TR_SESSIONS_BTN_ACTIVATE)
btn_update = QPushButton(translations.TR_SESSIONS_BTN_UPDATE)
btn_delete = QPushButton(translations.TR_SESSIONS_BTN_DELETE)
btn_details = QPushButton(translations.TR_SESSIONS_BTN_DETAILS)
btn_details.setCheckable(True)
# Add buttons to layout
btn_layout.addWidget(btn_create)
btn_layout.addWidget(btn_activate)
btn_layout.addWidget(btn_update)
btn_layout.addWidget(btn_delete)
btn_layout.addStretch()
btn_layout.addWidget(btn_details)
# Add widgets and layouts to the main layout
main_layout.addLayout(main_hbox)
main_hbox.addLayout(session_layout)
main_hbox.addWidget(line_frame)
main_hbox.addLayout(btn_layout)
main_hbox.setSizeConstraint(QLayout.SetFixedSize)
btn_details.toggled[bool].connect(content_frame.setVisible)
# Connections
self._session_list.itemSelectionChanged.connect(
self.load_session_content)
btn_activate.clicked.connect(self.open_session)
btn_update.clicked.connect(self.save_session)
btn_create.clicked.connect(self.create_session)
btn_delete.clicked.connect(self.delete_session)
def __load_sessions(self):
for session_name in self._manager.sessions:
item = QTreeWidgetItem()
item.setText(0, session_name)
item.setText(1, "FIXME: manage this!")
self._session_list.addTopLevelItem(item)
self._session_list.setCurrentItem(
self._session_list.topLevelItem(0))
def load_session_content(self):
"""Load the selected session, replacing the current session."""
item = self._session_list.currentItem()
self._content_list.clear()
if item is not None:
key = item.text(0)
files, projects = self._manager.get_session(key)
files_parent = QTreeWidgetItem(
self._content_list, [translations.TR_FILES])
for ffile in files:
QTreeWidgetItem(files_parent, [ffile[0]])
projects_parent = QTreeWidgetItem(
self._content_list, [translations.TR_PROJECT])
for project in projects:
QTreeWidgetItem(projects_parent, [project])
files_parent.setExpanded(True)
projects_parent.setExpanded(True)
def create_session(self):
"""Create a new Session."""
session_info = QInputDialog.getText(
None, translations.TR_SESSIONS_CREATE_TITLE,
#.........这里部分代码省略.........
示例5: EditorConfiguration
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
#.........这里部分代码省略.........
# End of line, Stop Scrolling At Last Line, Trailing space, Word wrap
vboxg6 = QVBoxLayout(group6)
vboxg6.setContentsMargins(5, 15, 5, 5)
self._checkEndOfLine = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_END_OF_LINE)
self._checkEndOfLine.setChecked(settings.USE_PLATFORM_END_OF_LINE)
vboxg6.addWidget(self._checkEndOfLine)
self._checkEndAtLastLine = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_END_AT_LAST_LINE)
self._checkEndAtLastLine.setChecked(settings.END_AT_LAST_LINE)
vboxg6.addWidget(self._checkEndAtLastLine)
self._checkTrailing = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_REMOVE_TRAILING)
self._checkTrailing.setChecked(settings.REMOVE_TRAILING_SPACES)
vboxg6.addWidget(self._checkTrailing)
self._allowWordWrap = QCheckBox(
translations.TR_PREFERENCES_EDITOR_CONFIG_WORD_WRAP)
self._allowWordWrap.setChecked(settings.ALLOW_WORD_WRAP)
vboxg6.addWidget(self._allowWordWrap)
formFeatures.addWidget(group6, 3, 1)
# pack all the groups
vbox.addWidget(container_widget_with_all_preferences)
vbox.addItem(QSpacerItem(0, 10, QSizePolicy.Expanding,
QSizePolicy.Expanding))
self._preferences.savePreferences.connect(self.save)
def _add_code_pep8(self):
item = QTreeWidgetItem()
item.setFlags(item.flags() | Qt.ItemIsEditable)
self._listIgnoreViolations.addTopLevelItem(item)
self._listIgnoreViolations.setCurrentItem(item)
self._listIgnoreViolations.editItem(item, 0)
def _remove_code_pep8(self):
index = self._listIgnoreViolations.indexOfTopLevelItem(
self._listIgnoreViolations.currentItem())
self._listIgnoreViolations.takeTopLevelItem(index)
def _enable_check_inline(self, val):
"""Method that takes a value to enable the inline style checking"""
if val == Qt.Checked:
self._checkStyle.setChecked(True)
def _enable_errors_inline(self, val):
"""Method that takes a value to enable the inline errors checking"""
if val == Qt.Checked:
self._checkErrors.setChecked(True)
def _disable_check_style(self, val):
"""Method that takes a value to disable the inline style checking"""
if val == Qt.Unchecked:
self._checkStyleOnLine.setChecked(False)
def _disable_show_errors(self, val):
"""Method that takes a value to disable the inline errors checking"""
if val == Qt.Unchecked:
self._showErrorsOnLine.setChecked(False)
def save(self):
"""Method to save settings"""
qsettings = IDE.ninja_settings()
settings.USE_TABS = bool(self._checkUseTabs.currentIndex())
qsettings.setValue('preferences/editor/useTabs',
示例6: Preferences
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [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,
#.........这里部分代码省略.........
示例7: FontsColors
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [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:
#.........这里部分代码省略.........
示例8: Shortcuts
# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setCurrentItem [as 别名]
#.........这里部分代码省略.........
# 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
for i in self.items():
if i.name == _lastaction:
item = i
break
self.tree.setCurrentItem(item)
self.tree.resizeColumnToContents(0)
def items(self):
"""Yield all the items in the actions tree."""
def children(item):
for i in range(item.childCount()):
c = item.child(i)
if c.childCount():
for c1 in children(c):
yield c1
else:
yield c
for c in children(self.tree.invisibleRootItem()):
yield c
def item(self, collection, name):
for item in self.items():
if item.collection.name == collection and item.name == name:
return item
def saveSettings(self):
self.scheme.saveSettings("shortcut_scheme", "shortcut_schemes", "shortcuts")
for item in self.items():
for scheme in self.scheme.schemes():
item.save(scheme)
item.clearSettings()
item.switchScheme(self.scheme.currentScheme())
def loadSettings(self):
self.scheme.loadSettings("shortcut_scheme", "shortcut_schemes")
# clear the settings in all the items
for item in self.items():