當前位置: 首頁>>代碼示例>>Python>>正文


Python QList.push_back方法代碼示例

本文整理匯總了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)
#.........這裏部分代碼省略.........
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:103,代碼來源:commanddatamodel.py


注:本文中的pyqtcore.QList.push_back方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。