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


Python QVector.fill方法代碼示例

本文整理匯總了Python中pyqtcore.QVector.fill方法的典型用法代碼示例。如果您正苦於以下問題:Python QVector.fill方法的具體用法?Python QVector.fill怎麽用?Python QVector.fill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyqtcore.QVector的用法示例。


在下文中一共展示了QVector.fill方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TileStampManager

# 需要導入模塊: from pyqtcore import QVector [as 別名]
# 或者: from pyqtcore.QVector import fill [as 別名]
class TileStampManager(QObject):
    setStamp = pyqtSignal(TileStamp)

    def __init__(self, toolManager, parent = None):
        super().__init__(parent)
        
        self.mStampsByName = QMap()
        self.mQuickStamps = QVector()
        for i in range(TileStampManager.quickStampKeys().__len__()):
            self.mQuickStamps.append(0)
        
        self.mTileStampModel = TileStampModel(self)
        self.mToolManager = toolManager

        prefs = preferences.Preferences.instance()
        prefs.stampsDirectoryChanged.connect(self.stampsDirectoryChanged)
        self.mTileStampModel.stampAdded.connect(self.stampAdded)
        self.mTileStampModel.stampRenamed.connect(self.stampRenamed)
        self.mTileStampModel.stampChanged.connect(self.saveStamp)
        self.mTileStampModel.stampRemoved.connect(self.deleteStamp)
        self.loadStamps()

    def __del__(self):
        # needs to be over here where the TileStamp type is complete
        pass
        
    ##
    # Returns the keys used for quickly accessible tile stamps.
    # Note: To store a tile layer <Ctrl> is added. The given keys will work
    # for recalling the stored values.
    ##
    def quickStampKeys():
        keys=[Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5, Qt.Key_6, Qt.Key_7, Qt.Key_8, Qt.Key_9]
        return keys
        
    def tileStampModel(self):
        return self.mTileStampModel
        
    def createStamp(self):
        stamp = self.tampFromContext(self.mToolManager.selectedTool())
        if (not stamp.isEmpty()):
            self.mTileStampModel.addStamp(stamp)
        return stamp
    
    def addVariation(self, targetStamp):
        stamp = stampFromContext(self.mToolManager.selectedTool())
        if (stamp.isEmpty()):
            return
        if (stamp == targetStamp): # avoid easy mistake of adding duplicates
            return
        for variation in stamp.variations():
            self.mTileStampModel.addVariation(targetStamp, variation)

    def selectQuickStamp(self, index):
        stamp = self.mQuickStamps.at(index)
        if (not stamp.isEmpty()):
            self.setStamp.emit(stamp)
    
    def createQuickStamp(self, index):
        stamp = stampFromContext(self.mToolManager.selectedTool())
        if (stamp.isEmpty()):
            return
        self.setQuickStamp(index, stamp)
    
    def extendQuickStamp(self, index):
        quickStamp = self.mQuickStamps[index]
        if (quickStamp.isEmpty()):
            self.createQuickStamp(index)
        else:
            self.addVariation(quickStamp)
    
    def stampsDirectoryChanged(self):
        # erase current stamps
        self.mQuickStamps.fill(TileStamp())
        self.mStampsByName.clear()
        self.mTileStampModel.clear()
        self.loadStamps()

    def eraseQuickStamp(self, index):
        stamp = self.mQuickStamps.at(index)
        if (not stamp.isEmpty()):
            self.mQuickStamps[index] = TileStamp()
            if (not self.mQuickStamps.contains(stamp)):
                self.mTileStampModel.removeStamp(stamp)

    def setQuickStamp(self, index, stamp):
        stamp.setQuickStampIndex(index)
        # make sure existing quickstamp is removed from stamp model
        self.eraseQuickStamp(index)
        self.mTileStampModel.addStamp(stamp)
        self.mQuickStamps[index] = stamp
    
    def loadStamps(self):
        prefs = preferences.Preferences.instance()
        stampsDirectory = prefs.stampsDirectory()
        stampsDir = QDir(stampsDirectory)
        iterator = QDirIterator(stampsDirectory,
                              ["*.stamp"],
                              QDir.Files | QDir.Readable)
        while (iterator.hasNext()):
#.........這裏部分代碼省略.........
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:103,代碼來源:tilestampmanager.py


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