本文整理汇总了Python中pyqtcore.QList.push_back方法的典型用法代码示例。如果您正苦于以下问题:Python QList.push_back方法的具体用法?Python QList.push_back怎么用?Python QList.push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtcore.QList
的用法示例。
在下文中一共展示了QList.push_back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandDataModel
# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import push_back [as 别名]
class CommandDataModel(QAbstractTableModel):
NameColumn, CommandColumn, EnabledColumn = range(3)
##
# Constructs the object and parses the users settings to allow easy
# programmatic access to the command list.
##
def __init__(self, parent):
super().__init__(parent)
self.mSettings = QSettings()
self.mSaveBeforeExecute = False
self.mCommands = QList()
# Load saveBeforeExecute option
s = self.mSettings.value("saveBeforeExecute", True)
self.mSaveBeforeExecute = bool(s)
# Load command list
variant = self.mSettings.value("commandList")
commands = variant
if commands is None:
commands = []
for commandVariant in commands:
self.mCommands.append(Command.fromQVariant(commandVariant))
# Add default commands the first time the app has booted up.
# This is useful on it's own and helps demonstrate how to use the commands.
addPrefStr = "addedDefaultCommands"
addedCommands = self.mSettings.value(addPrefStr, False)
if (not addedCommands):
# Disable default commands by default so user gets an informative
# warning when clicking the command button for the first time
command = Command(False)
if sys.platform == 'linux':
command.command = "gedit %mapfile"
elif sys.platform == 'darwin':
command.command = "open -t %mapfile"
if (not command.command.isEmpty()):
command.name = self.tr("Open in text editor")
self.mCommands.push_back(command)
self.commit()
self.mSettings.setValue(addPrefStr, True)
##
# Saves the data to the users preferences.
##
def commit(self):
# Save saveBeforeExecute option
self.mSettings.setValue("saveBeforeExecute", self.mSaveBeforeExecute)
# Save command list
commands = QList()
for command in self.mCommands:
commands.append(command.toQVariant())
self.mSettings.setValue("commandList", commands)
##
# Returns whether saving before executing commands is enabled.
##
def saveBeforeExecute(self):
return self.mSaveBeforeExecute
##
# Enables or disables saving before executing commands.
##
def setSaveBeforeExecute(self, enabled):
self.mSaveBeforeExecute = enabled
##
# Returns the first enabled command in the list, or an empty
# disabled command if there are no enabled commands.
##
def firstEnabledCommand(self):
for command in self.mCommands:
if (command.isEnabled):
return command
return Command(False)
##
# Returns a list of all the commands.
##
def allCommands(self):
return QList(self.mCommands)
##
# Remove the given row or rows from the model.
##
def removeRows(self, *args):
l = len(args)
if l>1 and l<4:
row = args[0]
count = args[1]
if l==2:
parent = QModelIndex()
elif l==3:
parent = args[2]
if (row < 0 or row + count > self.mCommands.size()):
return False
self.beginRemoveRows(parent, row, row + count)
self.mCommands.erase(self.mCommands.begin() + row, self.mCommands.begin() + row + count)
#.........这里部分代码省略.........