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


Python Scene.removeShape方法代码示例

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


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

示例1: Controller

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import removeShape [as 别名]

#.........这里部分代码省略.........

    def slotColorChanged(self, color):
        shapes = self.selectedShapes()
        if shapes:
            for shape in shapes:
                shape.settings.setColor(color)
        else:
            self.scene.newShapeSettings.setColor(color)

    def slotThicknessChanged(self, thickness):
        shapes = self.selectedShapes()
        if shapes:
            for shape in shapes:
                shape.settings.setThickness(thickness)
        else:
            self.scene.newShapeSettings.setThickness(thickness)

    def show(self):
        self.window.show()


    def open(self):
        name = QFileDialog.getOpenFileName(self.window, self.tr("Open Image"))
        if name.isEmpty():
            return
        self.load(name)


    def grabScreenshot(self):
        pos = self.window.pos()
        self.window.hide()
        try:
            pix = grab.showDialog()
            if pix is not None:
                self.setPixmap(pix)
        finally:
            self.window.show()
            self.window.move(pos)
            KWindowSystem.forceActiveWindow(self.window.winId())


    def save(self):
        name = QFileDialog.getSaveFileName(self.window, self.tr("Save Image as"))
        if name.isEmpty():
            return

        image = self.imageFromScene()
        ok = image.save(name)
        if not ok:
            KMessageBox.error(self.window, self.tr("Failed to save image as %1").arg(name));


    def imageFromScene(self):
        # Hide elements we don't want to show
        selection = self.scene.selectedItems()
        self.scene.clearSelection()
        self.pixmapItem.setHandlesVisible(False)

        # Render
        rect = self.scene.itemsBoundingRect()
        image = QImage(int(rect.width()), int(rect.height()), QImage.Format_ARGB32)
        image.fill(Qt.transparent)
        painter = QPainter(image)
        painter.setRenderHint(QPainter.Antialiasing)
        self.scene.render(painter, QRectF(image.rect()), rect)
        painter.end()

        # Restore hidden elements
        for item in selection:
            item.setSelected(True)
        self.pixmapItem.setHandlesVisible(True)

        return image


    def load(self, fileName):
        self.setPixmap(QPixmap(fileName))


    def setPixmap(self, pix):
        self.pixmapItem.setPixmap(pix)
        self.scene.setSceneRect(QRectF(pix.rect()))


    def slotToolChanged(self, action):
        toolFromAction = {
            self.ui.actionBubble: AddBubbleTool,
            self.ui.actionLine: AddLineTool,
            }

        klass = toolFromAction.get(action)
        if klass:
            tool = klass(self.scene)
        else:
            tool = None
        self.scene.setTool(tool)

    def deleteItems(self):
        for shape in self.selectedShapes():
            self.scene.removeShape(shape)
开发者ID:agateau,项目名称:annot8,代码行数:104,代码来源:controller.py


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