当前位置: 首页>>代码示例>>Python>>正文


Python QList.isEmpty方法代码示例

本文整理汇总了Python中pyqtcore.QList.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Python QList.isEmpty方法的具体用法?Python QList.isEmpty怎么用?Python QList.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyqtcore.QList的用法示例。


在下文中一共展示了QList.isEmpty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: updateBrush

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]
    def updateBrush(self, cursorPos, _list = None):
        # get the current tile layer
        currentLayer = self.currentTileLayer()
        layerWidth = currentLayer.width()
        layerHeight = currentLayer.height()
        numTiles = layerWidth * layerHeight
        paintCorner = 0
        # if we are in vertex paint mode, the bottom right corner on the map will appear as an invalid tile offset...
        if (self.mBrushMode == BrushMode.PaintVertex):
            if (cursorPos.x() == layerWidth):
                cursorPos.setX(cursorPos.x() - 1)
                paintCorner |= 1

            if (cursorPos.y() == layerHeight):
                cursorPos.setY(cursorPos.y() - 1)
                paintCorner |= 2

        # if the cursor is outside of the map, bail out
        if (not currentLayer.bounds().contains(cursorPos)):
            return
        terrainTileset = None
        terrainId = -1
        if (self.mTerrain):
            terrainTileset = self.mTerrain.tileset()
            terrainId = self.mTerrain.id()

        # allocate a buffer to build the terrain tilemap (TODO: this could be retained per layer to save regular allocation)
        newTerrain = []
        for i in range(numTiles):
            newTerrain.append(0)
            
        # allocate a buffer of flags for each tile that may be considered (TODO: this could be retained per layer to save regular allocation)
        checked = array('B')
        for i in range(numTiles):
            checked.append(0)
        # create a consideration list, and push the start points
        transitionList = QList()
        initialTiles = 0
        if (_list):
            # if we were supplied a list of start points
            for p in _list:
                transitionList.append(p)
                initialTiles += 1

        else:
            transitionList.append(cursorPos)
            initialTiles = 1

        brushRect = QRect(cursorPos, cursorPos)
        # produce terrain with transitions using a simple, relative naive approach (considers each tile once, and doesn't allow re-consideration if selection was bad)
        while (not transitionList.isEmpty()):
            # get the next point in the consideration list
            p = transitionList.takeFirst()
            x = p.x()
            y = p.y()
            i = y*layerWidth + x
            # if we have already considered this point, skip to the next
            # TODO: we might want to allow re-consideration if prior tiles... but not for now, this would risk infinite loops
            if (checked[i]):
                continue
            tile = currentLayer.cellAt(p).tile
            currentTerrain = terrain(tile)
            # get the tileset for this tile
            tileset = None
            if (terrainTileset):
                # if we are painting a terrain, then we'll use the terrains tileset
                tileset = terrainTileset
            elif (tile):
                # if we're erasing terrain, use the individual tiles tileset (to search for transitions)
                tileset = tile.tileset()
            else:
                # no tile here and we're erasing terrain, not much we can do
                continue

            # calculate the ideal tile for this position
            preferredTerrain = 0xFFFFFFFF
            mask = 0
            if (initialTiles):
                # for the initial tiles, we will insert the selected terrain and add the surroundings for consideration
                if (self.mBrushMode == BrushMode.PaintTile):
                    # set the whole tile to the selected terrain
                    preferredTerrain = makeTerrain(terrainId)
                    mask = 0xFFFFFFFF
                else:
                    # Bail out if encountering a tile from a different tileset
                    if (tile and tile.tileset() != tileset):
                        continue
                    # calculate the corner mask
                    mask = 0xFF << (3 - paintCorner)*8
                    # mask in the selected terrain
                    preferredTerrain = (currentTerrain & ~mask) | (terrainId << (3 - paintCorner)*8)

                initialTiles -= 1
                # if there's nothing to paint... skip this tile
                if (preferredTerrain == currentTerrain and (not tile or tile.tileset() == tileset)):
                    continue
            else:
                # Bail out if encountering a tile from a different tileset
                if (tile and tile.tileset() != tileset):
                    continue
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:terrainbrush.py

示例2: unifyTilesets

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]
    def unifyTilesets(self, *args):
        l = len(args)
        if l==1:
            ##
            # Makes sure the all tilesets which are used at the given \a map will be
            # present in the map document.
            #
            # To reach the aim, all similar tilesets will be replaced by the version
            # in the current map document and all missing tilesets will be added to
            # the current map document.
            #
            # \warning This method assumes that the tilesets in \a map are managed by
            #          the TilesetManager!
            ##
            map = args[0]
            undoCommands = QList()
            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()
            # Add tilesets that are not yet part of this map
            for tileset in map.tilesets():
                if (existingTilesets.contains(tileset)):
                    continue
                replacement = tileset.findSimilarTileset(existingTilesets)
                if (not replacement):
                    undoCommands.append(AddTileset(self, tileset))
                    continue

                # Merge the tile properties
                sharedTileCount = min(tileset.tileCount(), replacement.tileCount())
                for i in range(sharedTileCount):
                    replacementTile = replacement.tileAt(i)
                    properties = replacementTile.properties()
                    properties.merge(tileset.tileAt(i).properties())
                    undoCommands.append(ChangeProperties(self,
                                                             self.tr("Tile"),
                                                             replacementTile,
                                                             properties))

                map.replaceTileset(tileset, replacement)
                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)

            if (not undoCommands.isEmpty()):
                self.mUndoStack.beginMacro(self.tr("Tileset Changes"))
                for command in undoCommands:
                    self.mUndoStack.push(command)
                self.mUndoStack.endMacro()
        elif l==2:
            map, missingTilesets = args
            
            existingTilesets = self.mMap.tilesets()
            tilesetManager = TilesetManager.instance()

            for tileset in map.tilesets():
                # tileset already added
                if existingTilesets.contains(tileset):
                    continue

                replacement = tileset.findSimilarTileset(existingTilesets)

                # tileset not present and no replacement tileset found
                if not replacement:
                    if not missingTilesets.contains(tileset):
                        missingTilesets.append(tileset)
                    continue

                # replacement tileset found, change given map
                map.replaceTileset(tileset, replacement)

                tilesetManager.addReference(replacement)
                tilesetManager.removeReference(tileset)
开发者ID:theall,项目名称:Python-Tiled,代码行数:73,代码来源:mapdocument.py

示例3: MapDocument

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]

#.........这里部分代码省略.........
                        newPos = oldPos + pixelOffset
                        self.mUndoStack.push(MoveMapObject(self, newPos, oldPos))
            elif x==Layer.ImageLayerType:
                # Currently not adjusted when resizing the map
                break

        self.mUndoStack.push(ResizeMap(self, size))
        self.mUndoStack.push(ChangeSelectedArea(self, movedSelection))
        self.mUndoStack.endMacro()
        # TODO: Handle layers that don't match the map size correctly

    ##
    # Offsets the layers at \a layerIndexes by \a offset, within \a bounds,
    # and optionally wraps on the X or Y axis.
    ##
    def offsetMap(self, layerIndexes, offset, bounds, wrapX, wrapY):
        if (layerIndexes.empty()):
            return
        if (layerIndexes.size() == 1):
            self.mUndoStack.push(OffsetLayer(self, layerIndexes.first(), offset,
                                             bounds, wrapX, wrapY))
        else:
            self.mUndoStack.beginMacro(self.tr("Offset Map"))
            for layerIndex in layerIndexes:
                self.mUndoStack.push(OffsetLayer(self, layerIndex, offset,
                                                 bounds, wrapX, wrapY))

            self.mUndoStack.endMacro()

    ##
    # Flips the selected objects in the given \a direction.
    ##
    def flipSelectedObjects(self, direction):
        if (self.mSelectedObjects.isEmpty()):
            return
        self.mUndoStack.push(FlipMapObjects(self, self.mSelectedObjects, direction))

    ##
    # Rotates the selected objects.
    ##
    def rotateSelectedObjects(self, direction):
        if (self.mSelectedObjects.isEmpty()):
            return
        self.mUndoStack.beginMacro(self.tr("Rotate %n Object(s)", "", self.mSelectedObjects.size()))
        # TODO: Rotate them properly as a group
        for mapObject in self.mSelectedObjects:
            oldRotation = mapObject.rotation()
            newRotation = oldRotation
            if (direction == RotateDirection.RotateLeft):
                newRotation -= 90
                if (newRotation < -180):
                    newRotation += 360
            else:
                newRotation += 90
                if (newRotation > 180):
                    newRotation -= 360

            self.mUndoStack.push(RotateMapObject(self, mapObject, newRotation, oldRotation))

        self.mUndoStack.endMacro()

    ##
    # Adds a layer of the given type to the top of the layer stack. After adding
    # the new layer, emits editLayerNameRequested().
    ##
    def addLayer(self, layerType):
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:mapdocument.py

示例4: ObjectGroup

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]

#.........这里部分代码省略.........
        object.setObjectGroup(None)

    ##
    # Moves \a count objects starting at \a from to the index given by \a to.
    #
    # The \a to index may not lie within the range of objects that is
    # being moved.
    ##
    def moveObjects(self, _from, to, count):
        # It's an error when 'to' lies within the moving range of objects
        # Nothing to be done when 'to' is the start or the end of the range, or
        # when the number of objects to be moved is 0.
        if (to == _from or to == _from + count or count == 0):
            return
        movingObjects = self.mObjects[_from:_from+count]
        self.mObjects.erase(_from, _from + count)
        if (to > _from):
            to -= count
        for i in range(count):
            self.mObjects.insert(to + i, movingObjects[i])

    ##
    # Returns the bounding rect around all objects in this object group.
    ##
    def objectsBoundingRect(self):
        boundingRect = QRectF()
        for object in self.mObjects:
            boundingRect = boundingRect.united(object.bounds())
        return boundingRect

    ##
    # Returns whether this object group contains any objects.
    ##
    def isEmpty(self):
        return self.mObjects.isEmpty()

    ##
    # Computes and returns the set of tilesets used by this object group.
    ##
    def usedTilesets(self):
        tilesets = QSet()
        for object in self.mObjects:
            tile = object.cell().tile
            if tile:
                tilesets.insert(tile.sharedTileset())
        return tilesets

    ##
    # Returns whether any tile objects in this object group reference tiles
    # in the given tileset.
    ##
    def referencesTileset(self, tileset):
        for object in self.mObjects:
            tile = object.cell().tile
            if (tile and tile.tileset() == tileset):
                return True

        return False

    ##
    # Replaces all references to tiles from \a oldTileset with tiles from
    # \a newTileset.
    ##
    def replaceReferencesToTileset(self, oldTileset, newTileset):
        for object in self.mObjects:
            tile = object.cell().tile
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:objectgroup.py

示例5: AutoMapper

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]

#.........这里部分代码省略.........
                if (isNotList):
                    self.mInputRules[index][name].listNo.append(layer.asTileLayer())
                else:
                    self.mInputRules[index][name].listYes.append(layer.asTileLayer())
                continue

            if layerName.lower().startswith("output"):
                if (layer.isTileLayer()):
                    self.mTouchedTileLayers.insert(name)
                else:
                    self.mTouchedObjectGroups.insert(name)
                type = layer.layerType()
                layerIndex = self.mMapWork.indexOfLayer(name, type)
                found = False
                for translationTable in self.mLayerList:
                    if (translationTable.index == index):
                        translationTable.insert(layer, layerIndex)
                        found = True
                        break

                if (not found):
                    self.mLayerList.append(RuleOutput())
                    self.mLayerList.last().insert(layer, layerIndex)
                    self.mLayerList.last().index = index

                continue

            error += self.tr("Layer '%s' is not recognized as a valid layer for Automapping.\n"%layerName)

        if (not self.mLayerInputRegions):
            error += self.tr("No 'regions' or 'regions_input' layer found.\n")
        if (not self.mLayerOutputRegions):
            error += self.tr("No 'regions' or 'regions_output' layer found.\n")
        if (self.mInputRules.isEmpty()):
            error += self.tr("No input_<name> layer found!\n")
        # no need to check for mInputNotRules.size() == 0 here.
        # these layers are not necessary.
        if error != '':
            error = self.mRulePath + '\n' + error
            self.mError += error
            return False

        return True

    ##
    # Checks if all needed layers in the working map are there.
    # If not, add them in the correct order.
    ##
    def setupMissingLayers(self):
        # make sure all needed layers are there:
        for name in self.mTouchedTileLayers:
            if (self.mMapWork.indexOfLayer(name, Layer.TileLayerType) != -1):
                continue
            index = self.mMapWork.layerCount()
            tilelayer = TileLayer(name, 0, 0, self.mMapWork.width(), self.mMapWork.height())
            self.mMapDocument.undoStack().push(AddLayer(self.mMapDocument, index, tilelayer))
            self.mAddedTileLayers.append(name)

        for name in self.mTouchedObjectGroups:
            if (self.mMapWork.indexOfLayer(name, Layer.ObjectGroupType) != -1):
                continue
            index = self.mMapWork.layerCount()
            objectGroup = ObjectGroup(name, 0, 0,
                                                       self.mMapWork.width(),
                                                       self.mMapWork.height())
            self.mMapDocument.undoStack().push(AddLayer(self.mMapDocument, index, objectGroup))
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:automapper.py

示例6: DocumentManager

# 需要导入模块: from pyqtcore import QList [as 别名]
# 或者: from pyqtcore.QList import isEmpty [as 别名]

#.........这里部分代码省略.........
    # Returns whether the map loaded successfully.
    ##
    def reloadDocumentAt(self, index):
        oldDocument = self.mDocuments.at(index)
        
        newDocument, error = MapDocument.load(oldDocument.fileName(), oldDocument.readerFormat())
        if (not newDocument):
            self.reloadError.emit(self.tr("%s:\n\n%s"%(oldDocument.fileName(), error)))
            return False

        # Remember current view state
        mapView = self.viewForDocument(oldDocument)
        layerIndex = oldDocument.currentLayerIndex()
        scale = mapView.zoomable().scale()
        horizontalPosition = mapView.horizontalScrollBar().sliderPosition()
        verticalPosition = mapView.verticalScrollBar().sliderPosition()
        # Replace old tab
        self.addDocument(newDocument)
        self.closeDocumentAt(index)
        self.mTabWidget.moveTab(self.mDocuments.size() - 1, index)
        # Restore previous view state
        mapView = self.currentMapView()
        mapView.zoomable().setScale(scale)
        mapView.horizontalScrollBar().setSliderPosition(horizontalPosition)
        mapView.verticalScrollBar().setSliderPosition(verticalPosition)
        if (layerIndex > 0 and layerIndex < newDocument.map().layerCount()):
            newDocument.setCurrentLayerIndex(layerIndex)
        return True

    ##
    # Close all documents. Will not ask the user whether to save any changes!
    ##
    def closeAllDocuments(self):
        while (not self.mDocuments.isEmpty()):
            self.closeCurrentDocument()

    ##
    # Returns all open map documents.
    ##
    def documents(self):
        return self.mDocuments

    ##
    # Centers the current map on the tile coordinates \a x, \a y.
    ##
    def centerViewOn(self, *args):
        l = len(args)
        if l==2:
            x, y = args
            view = self.currentMapView()
            if (not view):
                return
            view.centerOn(self.currentDocument().renderer().pixelToScreenCoords(x, y))
        elif l==1:
            pos = args[0]
            self.centerViewOn(pos.x(), pos.y())

    def switchToLeftDocument(self):
        tabCount = self.mTabWidget.count()
        if (tabCount < 2):
            return
        currentIndex = self.mTabWidget.currentIndex()
        if currentIndex > 0:
            x = currentIndex
        else:
            x = tabCount
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:documentmanager.py


注:本文中的pyqtcore.QList.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。