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


Python QMap.isEmpty方法代码示例

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


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

示例1: RandomPicker

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import isEmpty [as 别名]
class RandomPicker():

    def __init__(self):
        self.mSum = 0.0
        self.mThresholds = QMap()

    def add(self, value, probability = 1.0):
        self.mSum += probability
        self.mThresholds.insert(self.mSum, value)
    
    def isEmpty(self):
        return self.mThresholds.isEmpty()
    
    def pick(self):
        random = (rand() / RAND_MAX) * self.mSum
        it = self.mThresholds.lowerBound(random)
        if (it != self.mThresholds.end()):
            return self.mThresholds.itemByIndex(it)[1]
        else:
            return self.mThresholds.itemByIndex(-1)[1]
    
    def clear(self):
        self.mSum = 0.0
        self.mThresholds.clear()
开发者ID:theall,项目名称:Python-Tiled,代码行数:26,代码来源:randompicker.py

示例2: GidMapper

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import isEmpty [as 别名]
class GidMapper():
    ##
    # Default constructor. Use \l insert to initialize the gid mapper
    # incrementally.
    ##
    def __init__(self, *args):
        self.mInvalidTile = None
        self.mTilesetColumnCounts = QMap()
        self.mFirstGidToTileset = QMap()
        if len(args)==1:
            ##
            # Constructor that initializes the gid mapper using the given \a tilesets.
            ##
            firstGid = 1
            tilesets = args[0]
            for tileset in tilesets:
                self.insert(firstGid, tileset)
                firstGid += tileset.tileCount()

    ##
    # Insert the given \a tileset with \a firstGid as its first global ID.
    ##
    def insert(self, firstGid, tileset):
        self.mFirstGidToTileset.insert(firstGid, tileset)

    ##
    # Clears the gid mapper, so that it can be reused.
    ##
    def clear(self):
        self.mFirstGidToTileset.clear()

    ##
    # Returns True when no tilesets are known to this gid mapper.
    ##
    def isEmpty(self):
        return self.mFirstGidToTileset.isEmpty()

    ##
    # Returns the GID of the invalid tile in case decodeLayerData() returns
    # the InvalidTile error.
    ##
    def invalidTile(self):
        return self.mInvalidTile

    ##
    # Returns the cell data matched by the given \a gid. The \a ok parameter
    # indicates whether an error occurred.
    ##
    def gidToCell(self, gid):
        result = Cell()
        # Read out the flags
        result.flippedHorizontally = (gid & FlippedHorizontallyFlag)
        result.flippedVertically = (gid & FlippedVerticallyFlag)
        result.flippedAntiDiagonally = (gid & FlippedAntiDiagonallyFlag)
        # Clear the flags
        gid &= ~(FlippedHorizontallyFlag |
                 FlippedVerticallyFlag |
                 FlippedAntiDiagonallyFlag)
        if (gid == 0):
            ok = True
        elif (self.isEmpty()):
            ok = False
        else:
            # Find the tileset containing this tile
            index = self.mFirstGidToTileset.upperBound(gid)
            if index==0:
                ok = False
            else:
                item = self.mFirstGidToTileset.itemByIndex(index-1)
                # Navigate one tileset back since upper bound finds the next
                tileId = gid - item[0]
                tileset = item[1]

                columnCount = self.mTilesetColumnCounts.value(tileset, 0)
                if (columnCount > 0 and columnCount != tileset.columnCount()):
                    # Correct tile index for changes in image width
                    row = int(tileId / columnCount)
                    column = int(tileId % columnCount)
                    tileId = row * tileset.columnCount() + column
                result.tile = tileset.tileAt(tileId)
                ok = True

        return result, ok

    ##
    # Returns the global tile ID for the given \a cell. Returns 0 when the
    # cell is empty or when its tileset isn't known.
    ##
    def cellToGid(self, cell):
        if (cell.isEmpty()):
            return 0
        tileset = cell.tile.tileset()
        # Find the first GID for the tileset
        for item in self.mFirstGidToTileset:
            if item[1] == tileset:
                gid = item[0] + cell.tile.id()
                if (cell.flippedHorizontally):
                    gid |= FlippedHorizontallyFlag
                if (cell.flippedVertically):
                    gid |= FlippedVerticallyFlag
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:gidmapper.py

示例3: MapScene

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import isEmpty [as 别名]
class MapScene(QGraphicsScene):
    selectedObjectItemsChanged = pyqtSignal()

    ##
    # Constructor.
    ##
    def __init__(self, parent):
        super().__init__(parent)
        self.mMapDocument = None
        self.mSelectedTool = None
        self.mActiveTool = None
        self.mObjectSelectionItem = None
        self.mUnderMouse = False
        self.mCurrentModifiers = Qt.NoModifier,
        self.mDarkRectangle = QGraphicsRectItem()
        self.mDefaultBackgroundColor = Qt.darkGray

        self.mLayerItems = QVector()
        self.mObjectItems = QMap()
        self.mObjectLineWidth = 0.0
        self.mSelectedObjectItems = QSet()
        self.mLastMousePos = QPointF()
        self.mShowTileObjectOutlines = False
        self.mHighlightCurrentLayer = False
        self.mGridVisible = False

        self.setBackgroundBrush(self.mDefaultBackgroundColor)
        tilesetManager = TilesetManager.instance()
        tilesetManager.tilesetChanged.connect(self.tilesetChanged)
        tilesetManager.repaintTileset.connect(self.tilesetChanged)
        prefs = preferences.Preferences.instance()
        prefs.showGridChanged.connect(self.setGridVisible)
        prefs.showTileObjectOutlinesChanged.connect(self.setShowTileObjectOutlines)
        prefs.objectTypesChanged.connect(self.syncAllObjectItems)
        prefs.highlightCurrentLayerChanged.connect(self.setHighlightCurrentLayer)
        prefs.gridColorChanged.connect(self.update)
        prefs.objectLineWidthChanged.connect(self.setObjectLineWidth)
        self.mDarkRectangle.setPen(QPen(Qt.NoPen))
        self.mDarkRectangle.setBrush(Qt.black)
        self.mDarkRectangle.setOpacity(darkeningFactor)
        self.addItem(self.mDarkRectangle)
        self.mGridVisible = prefs.showGrid()
        self.mObjectLineWidth = prefs.objectLineWidth()
        self.mShowTileObjectOutlines = prefs.showTileObjectOutlines()
        self.mHighlightCurrentLayer = prefs.highlightCurrentLayer()
        # Install an event filter so that we can get key events on behalf of the
        # active tool without having to have the current focus.
        QCoreApplication.instance().installEventFilter(self)

    ##
    # Destructor.
    ##
    def __del__(self):
        if QCoreApplication.instance():
            QCoreApplication.instance().removeEventFilter(self)

    ##
    # Returns the map document this scene is displaying.
    ##
    def mapDocument(self):
        return self.mMapDocument

    ##
    # Sets the map this scene displays.
    ##
    def setMapDocument(self, mapDocument):
        if (self.mMapDocument):
            self.mMapDocument.disconnect()
            if (not self.mSelectedObjectItems.isEmpty()):
                self.mSelectedObjectItems.clear()
                self.selectedObjectItemsChanged.emit()

        self.mMapDocument = mapDocument
        if (self.mMapDocument):
            renderer = self.mMapDocument.renderer()
            renderer.setObjectLineWidth(self.mObjectLineWidth)
            renderer.setFlag(RenderFlag.ShowTileObjectOutlines, self.mShowTileObjectOutlines)
            self.mMapDocument.mapChanged.connect(self.mapChanged)
            self.mMapDocument.regionChanged.connect(self.repaintRegion)
            self.mMapDocument.tileLayerDrawMarginsChanged.connect(self.tileLayerDrawMarginsChanged)
            self.mMapDocument.layerAdded.connect(self.layerAdded)
            self.mMapDocument.layerRemoved.connect(self.layerRemoved)
            self.mMapDocument.layerChanged.connect(self.layerChanged)
            self.mMapDocument.objectGroupChanged.connect(self.objectGroupChanged)
            self.mMapDocument.imageLayerChanged.connect(self.imageLayerChanged)
            self.mMapDocument.currentLayerIndexChanged.connect(self.currentLayerIndexChanged)
            self.mMapDocument.tilesetTileOffsetChanged.connect(self.tilesetTileOffsetChanged)
            self.mMapDocument.objectsInserted.connect(self.objectsInserted)
            self.mMapDocument.objectsRemoved.connect(self.objectsRemoved)
            self.mMapDocument.objectsChanged.connect(self.objectsChanged)
            self.mMapDocument.objectsIndexChanged.connect(self.objectsIndexChanged)
            self.mMapDocument.selectedObjectsChanged.connect(self.updateSelectedObjectItems)

        self.refreshScene()

    ##
    # Returns whether the tile grid is visible.
    ##
    def isGridVisible(self):
        return self.mGridVisible
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:mapscene.py

示例4: EditPolygonTool

# 需要导入模块: from pyqtcore import QMap [as 别名]
# 或者: from pyqtcore.QMap import isEmpty [as 别名]
class EditPolygonTool(AbstractObjectTool):
    NoMode, Selecting, Moving = range(3)

    def __init__(self, parent = None):
        super().__init__(self.tr("Edit Polygons"),
              QIcon(":images/24x24/tool-edit-polygons.png"),
              QKeySequence(self.tr("E")),
              parent)

        self.mSelectedHandles = QSet()
        self.mModifiers = Qt.KeyboardModifiers()
        self.mScreenStart = QPoint()
        self.mOldHandlePositions = QVector()
        self.mAlignPosition = QPointF()
        ## The list of handles associated with each selected map object
        self.mHandles = QMapList()
        self.mOldPolygons = QMap()
        self.mStart = QPointF()

        self.mSelectionRectangle = SelectionRectangle()
        self.mMousePressed = False
        self.mClickedHandle = None
        self.mClickedObjectItem = None
        self.mMode = EditPolygonTool.NoMode

    def __del__(self):
        del self.mSelectionRectangle

    def tr(self, sourceText, disambiguation = '', n = -1):
        return QCoreApplication.translate('EditPolygonTool', sourceText, disambiguation, n)

    def activate(self, scene):
        super().activate(scene)
        self.updateHandles()
        # TODO: Could be more optimal by separating the updating of handles from
        # the creation and removal of handles depending on changes in the
        # selection, and by only updating the handles of the objects that changed.
        self.mapDocument().objectsChanged.connect(self.updateHandles)
        scene.selectedObjectItemsChanged.connect(self.updateHandles)
        self.mapDocument().objectsRemoved.connect(self.objectsRemoved)

    def deactivate(self, scene):
        try:
            self.mapDocument().objectsChanged.disconnect(self.updateHandles)
            scene.selectedObjectItemsChanged.disconnect(self.updateHandles)
        except:
            pass
        # Delete all handles
        self.mHandles.clear()
        self.mSelectedHandles.clear()
        self.mClickedHandle = None
        super().deactivate(scene)

    def mouseEntered(self):
        pass
    def mouseMoved(self, pos, modifiers):
        super().mouseMoved(pos, modifiers)
        if (self.mMode == EditPolygonTool.NoMode and self.mMousePressed):
            screenPos = QCursor.pos()
            dragDistance = (self.mScreenStart - screenPos).manhattanLength()
            if (dragDistance >= QApplication.startDragDistance()):
                if (self.mClickedHandle):
                    self.startMoving()
                else:
                    self.startSelecting()

        x = self.mMode
        if x==EditPolygonTool.Selecting:
            self.mSelectionRectangle.setRectangle(QRectF(self.mStart, pos).normalized())
        elif x==EditPolygonTool.Moving:
            self.updateMovingItems(pos, modifiers)
        elif x==EditPolygonTool.NoMode:
            pass

    def mousePressed(self, event):
        if (self.mMode != EditPolygonTool.NoMode): # Ignore additional presses during select/move
            return
        x = event.button()
        if x==Qt.LeftButton:
            self.mMousePressed = True
            self.mStart = event.scenePos()
            self.mScreenStart = event.screenPos()
            items = self.mapScene().items(self.mStart,
                                                                   Qt.IntersectsItemShape,
                                                                   Qt.DescendingOrder,
                                                                   viewTransform(event))
            self.mClickedObjectItem = first(items, MapObjectItem)
            self.mClickedHandle = first(items, PointHandle)
        elif x==Qt.RightButton:
            items = self.mapScene().items(event.scenePos(),
                                                                   Qt.IntersectsItemShape,
                                                                   Qt.DescendingOrder,
                                                                   viewTransform(event))
            clickedHandle = first(items)
            if (clickedHandle or not self.mSelectedHandles.isEmpty()):
                self.showHandleContextMenu(clickedHandle,
                                      event.screenPos())
            else:
                super().mousePressed(event)
        else:
#.........这里部分代码省略.........
开发者ID:theall,项目名称:Python-Tiled,代码行数:103,代码来源:editpolygontool.py


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