示例#1
0
文件: base.py 项目: JohnChu/libavg
 def _renderImage(self, srcBmp, node, pos, size):
     canvas = player.createCanvas(id="stretch_canvas", size=size)
     img = avg.ImageNode(pos=pos, parent=canvas.getRootNode())
     img.setBitmap(srcBmp)
     canvas.render()
     node.setBitmap(canvas.screenshot())
     player.deleteCanvas("stretch_canvas")
示例#2
0
 def _renderImage(self, srcBmp, node, pos, size):
     canvas = player.createCanvas(id="stretch_canvas", size=size)
     img = avg.ImageNode(pos=pos, parent=canvas.getRootNode())
     img.setBitmap(srcBmp)
     canvas.render()
     node.setBitmap(canvas.screenshot())
     player.deleteCanvas("stretch_canvas")
示例#3
0
 def __createImage(self, node, bmp, sizeFactor):
     canvas = player.createCanvas(id="keycanvas", size=self.size*sizeFactor)
     canvasImage = avg.ImageNode(pos=-self.pos*sizeFactor, parent=canvas.getRootNode())
     canvasImage.setBitmap(bmp)
     canvas.render()
     node.setBitmap(canvas.screenshot())
     player.deleteCanvas('keycanvas')
示例#4
0
 def __createImage(self, node, bmp, sizeFactor):
     canvas = player.createCanvas(id="keycanvas",
                                  size=self.size * sizeFactor)
     canvasImage = avg.ImageNode(pos=-self.pos * sizeFactor,
                                 parent=canvas.getRootNode())
     canvasImage.setBitmap(bmp)
     canvas.render()
     node.setBitmap(canvas.screenshot())
     player.deleteCanvas('keycanvas')
示例#5
0
 def deleteCanvases():
     changeHRef("")
     firstNode.href = ""
     player.deleteCanvas("testcanvas1")
     #            self.assertException(lambda: changeHRef("canvas:testcanvas1"))
     changeHRef("canvas:testcanvas2")
     #            self.assertException(lambda: player.deleteCanvas("testcanvas2"))
     changeHRef("")
     player.deleteCanvas("testcanvas2")
示例#6
0
        def deleteCanvases():
            changeHRef("")
            firstNode.href = ""
            player.deleteCanvas("testcanvas1")
#            self.assertException(lambda: changeHRef("canvas:testcanvas1"))
            changeHRef("canvas:testcanvas2")
#            self.assertException(lambda: player.deleteCanvas("testcanvas2"))
            changeHRef("")
            player.deleteCanvas("testcanvas2")
示例#7
0
    def testCanvasDependencies(self):
        def makeCircularRef():
            self.offscreen1.getElementByID(
                "test1").href = "canvas:offscreencanvas2"

        def makeSelfRef1():
            avg.ImageNode(href="canvas:offscreencanvas1",
                          parent=self.offscreen1.getRootNode())

        def makeSelfRef2():
            self.offscreen1.getElementByID(
                "test1").href = "canvas:offscreencanvas1"

        def createTwoCanvases():
            self.offscreen1 = self.__createOffscreenCanvas(
                "offscreencanvas1", False)
            self.offscreen2 = self.__createOffscreenCanvas(
                "offscreencanvas2", False)
            self.node = avg.ImageNode(parent=root,
                                      href="canvas:offscreencanvas1")
            node = self.offscreen1.getElementByID("test1")
            node.href = "canvas:offscreencanvas2"
            node.size = (80, 60)

        def exchangeCanvases():
            self.offscreen1.getElementByID("test1").href = "rgb24-65x65.png"
            self.offscreen2.getElementByID(
                "test1").href = "canvas:offscreencanvas1"
            self.node.href = "canvas:offscreencanvas2"

        def loadCanvasDepString():
            player.createCanvas(id="canvas1", size=(160, 120))
            canvas2 = player.createCanvas(id="canvas2", size=(160, 120))
            avg.ImageNode(href="canvas:canvas1", parent=canvas2.getRootNode())
            player.deleteCanvas('canvas2')
            player.deleteCanvas('canvas1')

        root = self.loadEmptyScene()
        createTwoCanvases()
        self.offscreen1.getElementByID("test1").href = ""
        self.offscreen1 = None
        self.offscreen2 = None
        self.node.href = ""
        self.node = None
        player.deleteCanvas("offscreencanvas1")
        player.deleteCanvas("offscreencanvas2")
        self.start(False, (
            createTwoCanvases,
            lambda: self.compareImage("testCanvasDependencies1"),
            exchangeCanvases,
            lambda: self.compareImage("testCanvasDependencies2"),
            lambda: self.assertRaises(avg.Exception, makeCircularRef),
            lambda: self.assertRaises(avg.Exception, makeSelfRef1),
            lambda: self.assertRaises(avg.Exception, makeSelfRef2),
            loadCanvasDepString,
        ))
示例#8
0
 def __renderImage(self, srcBmp, node, offset):
     if self._orientation == Orientation.HORIZONTAL:
         pos = (-offset,0)
     else:
         pos = (0, -offset)
     canvas = player.createCanvas(id="accordion_canvas", size=node.size)
     img = avg.ImageNode(pos=pos, parent=canvas.getRootNode())
     img.setBitmap(srcBmp)
     canvas.render()
     node.setBitmap(canvas.screenshot())
     player.deleteCanvas("accordion_canvas")
    def testCanvasDependencies(self):
        def makeCircularRef():
            self.offscreen1.getElementByID("test1").href = "canvas:offscreencanvas2"
            
        def makeSelfRef1():
            avg.ImageNode(href="canvas:offscreencanvas1", 
                    parent=self.offscreen1.getRootNode())

        def makeSelfRef2():
            self.offscreen1.getElementByID("test1").href = "canvas:offscreencanvas1"

        def createTwoCanvases():
            self.offscreen1 = self.__createOffscreenCanvas("offscreencanvas1", False)
            self.offscreen2 = self.__createOffscreenCanvas("offscreencanvas2", False)
            self.node = avg.ImageNode(parent=root, 
                    href="canvas:offscreencanvas1")
            node = self.offscreen1.getElementByID("test1")
            node.href = "canvas:offscreencanvas2"
            node.size = (80, 60)
            
        def exchangeCanvases():
            self.offscreen1.getElementByID("test1").href = "rgb24-65x65.png"
            self.offscreen2.getElementByID("test1").href = "canvas:offscreencanvas1"
            self.node.href = "canvas:offscreencanvas2"
            
        def loadCanvasDepString():
            player.createCanvas(id="canvas1", size=(160, 120))
            canvas2 = player.createCanvas(id="canvas2", size=(160, 120))
            avg.ImageNode(href="canvas:canvas1", parent=canvas2.getRootNode())
            player.deleteCanvas('canvas2')
            player.deleteCanvas('canvas1')

        root = self.loadEmptyScene()
        createTwoCanvases()
        self.offscreen1.getElementByID("test1").href = ""
        self.offscreen1 = None
        self.offscreen2 = None
        self.node.href = ""
        self.node = None
        player.deleteCanvas("offscreencanvas1")
        player.deleteCanvas("offscreencanvas2")
        self.start(False,
                (createTwoCanvases,
                 lambda: self.compareImage("testCanvasDependencies1"),
                 exchangeCanvases,
                 lambda: self.compareImage("testCanvasDependencies2"),
                 lambda: self.assertRaises(avg.Exception, makeCircularRef),
                 lambda: self.assertRaises(avg.Exception, makeSelfRef1),
                 lambda: self.assertRaises(avg.Exception, makeSelfRef2),
                 loadCanvasDepString,
                ))
 def deleteCanvases():
     changeHRef("")
     firstNode.href = ""
     player.deleteCanvas("testcanvas1")
     self.assertRaises(avg.Exception, lambda: changeHRef("canvas:testcanvas1"))
     changeHRef("canvas:testcanvas2")
     self.assertRaises(avg.Exception, lambda: player.deleteCanvas("testcanvas2"))
     changeHRef("")
     player.deleteCanvas("testcanvas2")
     self.assertRaises(avg.Exception, lambda: player.deleteCanvas("foo"))
示例#11
0
 def deleteCanvases():
     changeHRef("")
     firstNode.href = ""
     player.deleteCanvas("testcanvas1")
     self.assertRaises(avg.Exception, lambda: changeHRef("canvas:testcanvas1"))
     changeHRef("canvas:testcanvas2")
     self.assertRaises(avg.Exception, lambda: player.deleteCanvas("testcanvas2"))
     changeHRef("")
     player.deleteCanvas("testcanvas2")
     self.assertRaises(avg.Exception, lambda: player.deleteCanvas("foo"))
示例#12
0
 def deleteCanvases():
     changeHRef("")
     firstNode.href = ""
     player.deleteCanvas("testcanvas1")
     self.assertRaises(RuntimeError, lambda: changeHRef("canvas:testcanvas1"))
     changeHRef("canvas:testcanvas2")
     self.assertRaises(RuntimeError, lambda: player.deleteCanvas("testcanvas2"))
     changeHRef("")
     player.deleteCanvas("testcanvas2")
     self.assertRaises(RuntimeError, lambda: player.deleteCanvas("foo"))
示例#13
0
 def deleteCanvas():
     img1.unlink(True)
     img2.unlink(True)
     player.deleteCanvas("canvas")
示例#14
0
 def loadCanvasDepString():
     player.createCanvas(id="canvas1", size=(160, 120))
     canvas2 = player.createCanvas(id="canvas2", size=(160, 120))
     avg.ImageNode(href="canvas:canvas1", parent=canvas2.getRootNode())
     player.deleteCanvas('canvas2')
     player.deleteCanvas('canvas1')
示例#15
0
 def deleteCanvas():
     player.deleteCanvas("testcanvas")
     self.__offscreenCanvas = None
 def deleteCanvas():
     player.deleteCanvas("testcanvas")
     self.__offscreenCanvas = None
示例#17
0
 def deleteCanvas():
     img1.unlink(True)
     img2.unlink(True)
     player.deleteCanvas("canvas")
 def loadCanvasDepString():
     player.createCanvas(id="canvas1", size=(160, 120))
     canvas2 = player.createCanvas(id="canvas2", size=(160, 120))
     avg.ImageNode(href="canvas:canvas1", parent=canvas2.getRootNode())
     player.deleteCanvas('canvas2')
     player.deleteCanvas('canvas1')