示例#1
0
 def createDictNode(p, s):
     return avg.ImageNode(pos=p, size=s, href="rgb24-64x64.png")
示例#2
0
 def createOffscreenCanvas():
     self.__createOffscreenCanvas("offscreencanvas", False)
     self.node = avg.ImageNode(parent=root,
                               href="canvas:offscreencanvas")
示例#3
0
 def createCanvas():
     canvas = self.__createOffscreenCanvas("testcanvas", False)
     avg.ImageNode(href="canvas:testcanvas", parent=root)
     return canvas
示例#4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libavg import avg, player

canvas = player.createMainCanvas(size=(160, 120))
rootNode = canvas.getRootNode()
avg.ImageNode(pos=(40, 30),
              size=(80, 60),
              href="rgb24-64x64.png",
              parent=rootNode)
player.play()
示例#5
0
 def testMultiWindowBase(self):
     root = self.loadEmptyScene()
     avg.ImageNode(pos=(0, 0), href="rgb24-64x64.png", parent=root)
     player.setWindowConfig("avgwindowconfig.xml")
     self.start(False, (lambda: self.compareImage("testMultiWindow1"), ))
示例#6
0
    def onInit(self):
        # images
        orig = avg.ImageNode(href='../test/media/hsl.png', parent=self)
        huesat = avg.ImageNode(href='../test/media/hsl.png',
                               pos=(orig.size.x + 10, 0),
                               parent=self)

        # effect
        self._fx = avg.HueSatFXNode(colorize=False)
        huesat.setEffect(self._fx)

        y = orig.size.y + 10

        # hue slider
        self._hueTxt = avg.WordsNode(text='hue: %d' % self._fx.hue,
                                     fontsize=12,
                                     pos=(0, y),
                                     parent=self)
        y += self._hueTxt.height
        self._hueSld = widget.Slider(range=(-180, 180),
                                     thumbPos=self._fx.hue,
                                     width=self.width,
                                     pos=(0, y),
                                     parent=self)
        self._hueSld.subscribe(widget.Slider.THUMB_POS_CHANGED,
                               self._onSliderHue)

        y += self._hueSld.height

        # saturation slider
        self._satTxt = avg.WordsNode(text='saturation: %d' %
                                     self._fx.saturation,
                                     fontsize=12,
                                     pos=(0, y),
                                     parent=self)
        y += self._satTxt.height
        self._satSld = widget.Slider(range=(-100, 100),
                                     thumbPos=self._fx.saturation,
                                     width=self.width,
                                     pos=(0, y),
                                     parent=self)
        self._satSld.subscribe(widget.Slider.THUMB_POS_CHANGED,
                               self._onSliderSat)

        y += self._satSld.height

        # lightness slider
        self._lightTxt = avg.WordsNode(text='lightness: %d' %
                                       self._fx.lightness,
                                       fontsize=12,
                                       pos=(0, y),
                                       parent=self)
        y += self._lightTxt.height
        self._lightSld = widget.Slider(range=(-100, 100),
                                       thumbPos=self._fx.lightness,
                                       width=self.width,
                                       pos=(0, y),
                                       parent=self)
        self._lightSld.subscribe(widget.Slider.THUMB_POS_CHANGED,
                                 self._onSliderLight)

        y += self._lightSld.height

        # colorize check box
        widget.Skin.default.defaultCheckBoxCfg['font'].color = 'FFFFFF'
        self._colCbox = widget.CheckBox(text='colorize',
                                        checked=self._fx.colorize,
                                        pos=(0, y),
                                        parent=self)
        self._colCbox.subscribe(widget.CheckBox.TOGGLED, self._onCheckBoxCol)
示例#7
0
    def testEventCapture(self):
        def onMainMouseDown(Event):
            self.mainMouseDownCalled = True

        def onMouseDown(Event):
            self.mouseDownCalled = True

        def captureEvent():
            self.mouseDownCalled = False
            self.mainMouseDownCalled = False
            self.img.setEventCapture()

        def noCaptureEvent():
            self.mouseDownCalled = False
            self.mainMouseDownCalled = False
            self.img.releaseEventCapture()

        def doubleCaptureEvent():
            self.mouseDownCalled = False
            self.mainMouseDownCalled = False
            self.img.setEventCapture()
            self.img.setEventCapture()
            self.img.releaseEventCapture()

        def releaseTooMuch():
            self.img.releaseEventCapture()
            self.assertException(self.img.releaseEventCapture)

        self.mouseDownCalled = False
        self.mainMouseDownCalled = False

        root = self.loadEmptyScene()
        root.setEventHandler(avg.Event.CURSOR_DOWN, avg.Event.MOUSE,
                             onMainMouseDown)
        self.img = avg.ImageNode(pos=(0, 0),
                                 href="rgb24-65x65.png",
                                 parent=root)
        self.img.setEventHandler(avg.Event.CURSOR_DOWN, avg.Event.MOUSE,
                                 onMouseDown)

        self.start(False, (
            lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 10, 10),
            lambda: self.assert_(self.mouseDownCalled),
            lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 10, 10),
            captureEvent,
            lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 100, 10),
            lambda: self.assert_(self.mouseDownCalled and self.
                                 mainMouseDownCalled),
            lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 100, 10),
            noCaptureEvent,
            lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 100, 10),
            lambda: self.assert_(not (self.mouseDownCalled) and self.
                                 mainMouseDownCalled),
            lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 100, 10),
            doubleCaptureEvent,
            lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 100, 10),
            lambda: self.assert_(self.mouseDownCalled and self.
                                 mainMouseDownCalled),
            releaseTooMuch,
            lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 100, 10),
        ))
        self.img = None
示例#8
0
 def __init__(self, parent):
     self.__imgA = avg.ImageNode(href='ground.jpg', parent=parent)
     self.__imgB = avg.ImageNode(href='ground.jpg',
                                 pos=(0, -self.__imgA.height),
                                 parent=parent)
示例#9
0
 def invalidCreateNode():
     avg.ImageNode(1, 2, 3)
示例#10
0
 def createDictNode(root, p):
     node = avg.ImageNode(pos=p, href="rgb24-32x32.png", parent=root)
     self.assertEqual(node.getMediaSize(), avg.Point2D(32, 32))
     self.assertEqual(node.size, avg.Point2D(32, 32))
     return node
示例#11
0
 def createDictNode(root, p):
     return avg.ImageNode(pos=p, href="rgb24-32x32.png", parent=root)
示例#12
0
 def testResize():
     srcBmp = avg.Bitmap('media/rgb24-32x32.png')
     destBmp = srcBmp.getResized((64, 64))
     self.assert_(destBmp.getSize() == (64, 64))
     node = avg.ImageNode(pos=(128, 0), size=(32, 32), parent=root)
     node.setBitmap(destBmp)
示例#13
0
 def testCropRect():
     bmp = avg.Bitmap('media/rgb24-65x65.png')
     bmp1 = avg.Bitmap(bmp, (32, 32), (64, 64))
     self.assert_(bmp1.getSize() == (32, 32))
     node = avg.ImageNode(pos=(96, 0), parent=root)
     node.setBitmap(bmp1)
示例#14
0
    def testBitmap(self):
        def getBitmap(node):
            bmp = node.getBitmap()
            self.assertEqual(bmp.getSize(), (65, 65))
            self.compareBitmapToFile(bmp, "rgb24-65x65")
            self.assert_(bmp.getFormat() == avg.R8G8B8X8
                         or bmp.getFormat() == avg.B8G8R8X8)
            node.setBitmap(bmp)
            self.assertEqual(node.getMediaSize(), (65, 65))

        def immediateGetBitmap():
            node = avg.ImageNode(href="rgb24-65x65.png",
                                 size=(32, 32),
                                 parent=root)
            bmp = node.getBitmap()
            self.compareBitmapToFile(bmp, "rgb24-65x65")
            node.unlink(True)
            node = avg.ImageNode(href="rgb24-65x65.png",
                                 size=(32, 32),
                                 parent=root)
            node.unlink()
            root.appendChild(node)
            bmp = node.getBitmap()
            self.compareBitmapToFile(bmp, "rgb24-65x65")
            node.unlink(True)

        def loadFromBitmap(p, orighref):
            node = avg.ImageNode(pos=p, size=(32, 32), href=orighref)
            bmp = avg.Bitmap('media/rgb24-65x65.png')
            self.assertEqual(bmp.getSize(), (65, 65))
            node.setBitmap(bmp)
            self.assertEqual(node.getMediaSize(), (65, 65))
            root.appendChild(node)

        def testStringConversion():
            bmp = avg.Bitmap('media/rgb24-65x65.png')

            for isCopy in (False, True):
                s = bmp.getPixels(isCopy)
                bmp1 = avg.Bitmap(bmp.getSize(), bmp.getFormat(), "sample")
                bmp1.setPixels(s)
                self.assert_(self.areSimilarBmps(bmp, bmp1, 0.01, 0.01))

            self.assertRaises(avg.Exception, lambda: bmp1.setPixels(13)),

        def testCropRect():
            bmp = avg.Bitmap('media/rgb24-65x65.png')
            bmp1 = avg.Bitmap(bmp, (32, 32), (64, 64))
            self.assert_(bmp1.getSize() == (32, 32))
            node = avg.ImageNode(pos=(96, 0), parent=root)
            node.setBitmap(bmp1)

        def testBlt():
            srcBmp = avg.Bitmap('media/rgb24-65x65.png')
            destBmp = avg.Bitmap((65, 65), srcBmp.getFormat(), "bmp")
            destBmp.blt(srcBmp, (0, 0))
            destBmp.blt(srcBmp, (32, 32))
            node = avg.ImageNode(pos=(96, 32), size=(32, 32), parent=root)
            node.setBitmap(destBmp)

        def testResize():
            srcBmp = avg.Bitmap('media/rgb24-32x32.png')
            destBmp = srcBmp.getResized((64, 64))
            self.assert_(destBmp.getSize() == (64, 64))
            node = avg.ImageNode(pos=(128, 0), size=(32, 32), parent=root)
            node.setBitmap(destBmp)

        def testUnicode():
            if self._isCurrentDirWriteable():
                # Can't check unicode filenames into svn or the windows client breaks.
                # So we rename the file locally.
                shutil.copyfile("media/oe.png", u"media/ö.png")
                avg.Bitmap(u"media/ö.png")
                os.remove(u"media/ö.png")

        def testGetPixel():
            bmp = avg.Bitmap('media/rgb24-65x65.png')
            self.assertEqual(bmp.getPixel((1, 1)), (255, 0, 0, 255))
            self.assertEqual(bmp.getPixel((33, 1)), (0, 255, 0, 255))
            bmp = avg.Bitmap('media/rgb24alpha-64x64.png')
            self.assertEqual(bmp.getPixel((1, 1)), (0, 0, 0, 0))
            self.assertEqual(bmp.getPixel((63, 1)), (83, 255, 83, 142))
            bmp = avg.Bitmap('media/greyscale.png')
            self.assertEqual(bmp.getPixel((1, 1)), (255, 255, 255, 255))
            self.assertEqual(bmp.getPixel((1, 63)), (0, 0, 0, 255))
            self.assertRaises(avg.Exception, lambda: bmp.getPixel((64, 0)))

        def setNullBitmap():
            node.setBitmap(None)

        def testSubBitmap():
            srcBmp = avg.Bitmap('media/rgb24-32x32.png')
            destBmp = avg.Bitmap(srcBmp, (16, 16), (32, 32))
            self.assertEqual(srcBmp.getPixel((16, 16)), destBmp.getPixel(
                (0, 0)))
            self.assertRaises(avg.Exception,
                              lambda: avg.Bitmap(srcBmp, (16, 16), (16, 32)))

        node = avg.ImageNode(href="media/rgb24-65x65.png", size=(32, 32))
        getBitmap(node)

        root = self.loadEmptyScene()
        node = avg.ImageNode(pos=(0, 0), size=(32, 32), href="rgb24-65x65.png")
        root.appendChild(node)
        getBitmap(node)
        self.assertEqual(node.size, (32, 32))
        loadFromBitmap((32, 0), "")
        loadFromBitmap((64, 0), "rgb24alpha-64x64.png")
        testStringConversion()
        testUnicode()
        self.start(False, (
            lambda: getBitmap(node),
            immediateGetBitmap,
            lambda: loadFromBitmap((32, 32), ""),
            lambda: loadFromBitmap((64, 32), "rgb24alpha-64x64.png"),
            lambda: self.compareImage("testBitmap1"),
            testCropRect,
            lambda: self.compareImage("testBitmap2"),
            testBlt,
            lambda: self.compareImage("testBitmap3"),
            testResize,
            lambda: self.compareImage("testBitmap4"),
            testGetPixel,
            lambda: self.assertRaises(avg.Exception, setNullBitmap),
            testSubBitmap,
        ))
示例#15
0
 def emptyImageFX():
     node = avg.ImageNode(parent=root, href="", pos=(64,0))
     node.setEffect(avg.NullFXNode())
示例#16
0
    def testCropImage(self):
        def moveTLCrop():
            node = player.getElementByID("img")
            node.x = -20
            node.y = -20
        
        def moveBRCrop():
            node = player.getElementByID("img")
            node.x = 60
            node.y = 40
        
        def moveTLNegative():
            node = player.getElementByID("img")
            node.x = -60
            node.y = -50
        
        def moveBRGone():
            node = player.getElementByID("img")
            node.x = 140
            node.y = 100
        
        def rotate():
            node = player.getElementByID("img")
            node.x = 10
            node.y = 10
            player.getElementByID("nestedavg").angle = 1.0
            player.getElementByID("bkgd").angle = 1.0
        
        root = self.loadEmptyScene()
        avg.ImageNode(id="bkgd", href="crop_bkgd.png", parent=root)
        root.appendChild(
                player.createNode("""
                  <div id="nestedavg" x="40" y="30" width="80" height="60" crop="True">
                    <div id="nestedavg2" crop="True">
                      <div id="nestedavg3" crop="True">
                        <image id="img" x="10" y="10" width="40" height="40" 
                                href="rgb24-64x64.png"/>
                      </div>
                    </div>
                  </div>
                """))
        self.start(False,
                (lambda: self.compareImage("testCropImage1"),
                 moveTLCrop,
                 lambda: self.compareImage("testCropImage2"),
                 moveBRCrop,
                 lambda: self.compareImage("testCropImage3"),
                 moveTLNegative,
                 lambda: self.compareImage("testCropImage4"),
                 moveBRGone,
                 lambda: self.compareImage("testCropImage5"),

                 rotate,
                 lambda: self.compareImage("testCropImage6"),
                 moveTLCrop,
                 lambda: self.compareImage("testCropImage7"),
                 moveBRCrop,
                 lambda: self.compareImage("testCropImage8"),
                 moveTLNegative,
                 lambda: self.compareImage("testCropImage9"),
                 moveBRGone,
                 lambda: self.compareImage("testCropImage10")
               ))
示例#17
0
 def __createOffscreenCanvas(self):
     canvas = player.createCanvas(id="offscreen", size=(160,120), mediadir="media")
     root = canvas.getRootNode()
     avg.ImageNode(href="rgb24-32x32.png", parent=root)
     avg.ImageNode(id="test", pos=(32,0), href="rgb24alpha-32x32.png", parent=root)
     return canvas
示例#18
0
    def testCropMovie(self):
        def playMovie():
            node = player.getElementByID("movie")
            node.play()
        
        def moveTLCrop():
            node = player.getElementByID("movie")
            node.x = -20
            node.y = -20
        
        def moveBRCrop():
            node = player.getElementByID("movie")
            node.x = 60
            node.y = 40
        
        def moveTLNegative():
            node = player.getElementByID("movie")
            node.x = -60
            node.y = -50
        
        def moveBRGone():
            node = player.getElementByID("movie")
            node.x = 140
            node.y = 100
        
        def rotate():
            node = player.getElementByID("movie")
            node.x = 10
            node.y = 10
            player.getElementByID("nestedavg").angle = 1.0
            player.getElementByID("bkgd").angle = 1.0
        
        player.setFakeFPS(30)
        root = self.loadEmptyScene()
        avg.ImageNode(id="bkgd", href="crop_bkgd.png", parent=root)
        root.appendChild(
                player.createNode("""
                  <div id="nestedavg" x="40" y="30" width="80" height="60" crop="True">
                    <video id="movie" x="10" y="10" width="40" height="40" 
                            threaded="false" href="mpeg1-48x48.mov"
                            fps="30"/>
                  </div>
                """))
        self.start(False,
                (playMovie,
                 lambda: self.compareImage("testCropMovie1"),
                 moveTLCrop,
                 lambda: self.compareImage("testCropMovie2"),
                 moveBRCrop,
                 lambda: self.compareImage("testCropMovie3"),
                 moveTLNegative,
                 lambda: self.compareImage("testCropMovie4"),
                 moveBRGone,
                 lambda: self.compareImage("testCropMovie5"),

                 rotate,
                 lambda: self.compareImage("testCropMovie6"),
                 moveTLCrop,
                 lambda: self.compareImage("testCropMovie7"),
                 moveBRCrop,
                 lambda: self.compareImage("testCropMovie8"),
                 moveTLNegative,
                 lambda: self.compareImage("testCropMovie9"),
                 moveBRGone,
                 lambda: self.compareImage("testCropMovie10")
                ))
示例#19
0
    def testPublisher(self):
        def onDown(event):
            self.assert_(event.type == avg.Event.CURSOR_DOWN)
            curEvent = player.getCurrentEvent()
            self.assert_(curEvent.type == avg.Event.CURSOR_DOWN)
            self.assert_(curEvent.when == event.when)
            self.downCalled = True

        def unsubscribe():
            self.assert_(self.img.isSubscribed(avg.Node.CURSOR_DOWN, onDown))
            self.img.unsubscribe(avg.Node.CURSOR_DOWN, onDown)
            self.assert_(not (
                self.img.isSubscribed(avg.Node.CURSOR_DOWN, onDown)))
            self.assert_(self.img.getNumSubscribers(avg.Node.CURSOR_DOWN) == 0)
            self.downCalled = False
            self.assertException(
                lambda: self.img.unsubscribe(avg.Node.CURSOR_DOWN, onDown))

        def initUnsubscribeInEvent(useMessageID):
            self.subscriberID = self.img.subscribe(
                avg.Node.CURSOR_DOWN,
                lambda event: onDownUnsubscribe(event, useMessageID))

        def onDownUnsubscribe(event, useMessageID):
            if useMessageID:
                self.img.unsubscribe(avg.Node.CURSOR_DOWN, self.subscriberID)
                self.assertException(lambda: self.img.unsubscribe(
                    avg.Node.CURSOR_DOWN, self.subscriberID))
            else:
                self.img.unsubscribe(self.subscriberID)
                self.assertException(
                    lambda: self.img.unsubscribe(self.subscriberID))

            self.downCalled = True

        def onFrame():
            self.onFrameCalled = True

        self.downCalled = False
        self.onFrameCalled = False
        root = self.loadEmptyScene()
        player.subscribe(player.ON_FRAME, onFrame)
        self.img = avg.ImageNode(pos=(0, 0),
                                 href="rgb24-65x65.png",
                                 parent=root)
        self.img.subscribe(avg.Node.CURSOR_DOWN, onDown)
        self.assertException(lambda: self.img.subscribe(23, onDown))
        self.assertException(
            lambda: self.img.unsubscribe(avg.Node.CURSOR_DOWN, 23))
        self.start(False, (
            lambda: self.fakeClick(10, 10),
            lambda: self.assert_(self.downCalled),
            lambda: self.assert_(self.onFrameCalled),
            unsubscribe,
            lambda: self.fakeClick(10, 10),
            lambda: self.assert_(not (self.downCalled)),
            lambda: initUnsubscribeInEvent(True),
            lambda: self.fakeClick(10, 10),
            lambda: self.assert_(self.downCalled),
            lambda: initUnsubscribeInEvent(False),
            lambda: self.fakeClick(10, 10),
            lambda: self.assert_(self.downCalled),
        ))
示例#20
0
 def changeParent():
     div = avg.DivNode()
     img = avg.ImageNode(href="additive/rgb24-64x64.png", parent=div)
     root.appendChild(img)
示例#21
0
    def testMouseOver(self):
        def onImg2MouseOver(Event):
            self.img2MouseOverCalled = True

        def onImg2MouseOut(Event):
            self.img2MouseOutCalled = True

        def onDivMouseOver(Event):
            self.divMouseOverCalled = True

        def onDivMouseOut(Event):
            self.divMouseOutCalled = True

        def onAVGMouseOver(Event):
            self.avgMouseOverCalled = True

        def onImg1MouseOver(Event):
            self.img1MouseOverCalled = True

        def printState():
            print "----"
            print "img2MouseOverCalled=", self.img2MouseOverCalled
            print "img2MouseOutCalled=", self.img2MouseOutCalled
            print "divMouseOverCalled=", self.divMouseOverCalled
            print "divMouseOutCalled=", self.divMouseOutCalled
            print "avgMouseOverCalled=", self.avgMouseOverCalled
            print "img1MouseOverCalled=", self.img1MouseOverCalled

        def resetState():
            self.img2MouseOverCalled = False
            self.img2MouseOutCalled = False
            self.divMouseOverCalled = False
            self.divMouseOutCalled = False
            self.avgMouseOverCalled = False
            self.img1MouseOverCalled = False

        def killNodeUnderCursor():
            Parent = img1.parent
            Parent.removeChild(Parent.indexOf(img1))

        root = self.loadEmptyScene()
        img1 = avg.ImageNode(href="rgb24-65x65.png", parent=root)
        div = avg.DivNode(pos=(65, 0), parent=root)
        img3 = avg.ImageNode(href="rgb24-65x65.png", parent=div)
        img2 = avg.ImageNode(pos=(0, 65), href="rgb24-65x65.png", parent=div)

        img2.setEventHandler(avg.Event.CURSOR_OVER, avg.Event.MOUSE,
                             onImg2MouseOver)
        img2.setEventHandler(avg.Event.CURSOR_OUT, avg.Event.MOUSE,
                             onImg2MouseOut)
        div.setEventHandler(avg.Event.CURSOR_OVER, avg.Event.MOUSE,
                            onDivMouseOver)
        div.setEventHandler(avg.Event.CURSOR_OUT, avg.Event.MOUSE,
                            onDivMouseOut)
        root.setEventHandler(avg.Event.CURSOR_OVER, avg.Event.MOUSE,
                             onAVGMouseOver)
        img1.setEventHandler(avg.Event.CURSOR_OVER, avg.Event.MOUSE,
                             onImg1MouseOver)
        self.start(
            False,
            (resetState,
             lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 70, 70),
             lambda: self.assert_(
                 self.img2MouseOverCalled and self.divMouseOverCalled and self.
                 avgMouseOverCalled and not (self.img2MouseOutCalled) and not (
                     self.divMouseOutCalled) and not (self.img1MouseOverCalled)
             ), lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 70, 70),
             resetState,
             lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 70, 10),
             lambda: self.assert_(not (self.img2MouseOverCalled) and not (
                 self.divMouseOverCalled) and not (self.avgMouseOverCalled) and
                                  self.img2MouseOutCalled and not (
                                      self.divMouseOutCalled) and not (
                                          self.img1MouseOverCalled)),
             lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 70, 10),
             resetState,
             lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 10, 10),
             lambda: self.assert_(not (self.img2MouseOverCalled) and not (
                 self.divMouseOverCalled) and not (
                     self.avgMouseOverCalled) and not (
                         self.img2MouseOutCalled) and self.divMouseOutCalled
                                  and self.img1MouseOverCalled), resetState,
             killNodeUnderCursor,
             lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 10, 10),
             lambda: self.assert_(not (self.img2MouseOverCalled) and not (
                 self.divMouseOverCalled) and not (self.avgMouseOverCalled) and
                                  not (self.img2MouseOutCalled) and not (
                                      self.divMouseOutCalled) and not (
                                          self.img1MouseOverCalled)),
             lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 10, 10),
             resetState, lambda: img2.setEventCapture(),
             lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 70, 70),
             lambda: self.assert_(
                 self.img2MouseOverCalled and self.divMouseOverCalled and not (
                     self.avgMouseOverCalled) and not (self.img2MouseOutCalled)
                 and not (self.divMouseOutCalled) and not (
                     self.img1MouseOverCalled)),
             lambda: self._sendMouseEvent(avg.Event.CURSOR_DOWN, 70, 70),
             resetState,
             lambda: self._sendMouseEvent(avg.Event.CURSOR_UP, 10, 10),
             lambda: self.assert_(not (self.img2MouseOverCalled) and not (
                 self.divMouseOverCalled) and not (
                     self.avgMouseOverCalled) and self.img2MouseOutCalled and
                                  self.divMouseOutCalled and not (
                                      self.img1MouseOverCalled))))
示例#22
0
    def __draw_main_view(self, fake=False):
        """
        Draws the main vis view.

        :param fake: Should the fake or the original data set be loaded?
        :type fake: bool
        """
        if self.__touch_test_view:
            self.__touch_test_view.unlink(True)
            self.__touch_test_view = None

        self.__wall_divico = WallDivico(
            parent=self,
            size=self.size,
            map_image_info=config_app.maps_images[config_app.map_image],
            data_file=config_app.sql_result_dump_filename[
                config_app.data_mode_string],
            grid_groups=self.__grid_groups,
            grid_labels=self.__grid_labels)

        self.__task_text_view_canvas = player.createCanvas(
            id="task_text_view",
            autorender=True,
            multisamplesamples=8,
            size=(self.size[0], self.size[1] / 12))
        text = [
            "{} ({})".format(self._study_handler.current_block_name,
                             self._study_handler.current_phase)
        ] if self._study_handler else []
        self.__task_text_view = TextView2(
            text_elements=text,
            alignment="center",
            font_size=42,
            element_size=900,
            parent=self.__task_text_view_canvas.getRootNode(),
            size=(self.size[0], self.size[1] / 12),
            padding_top=20,
            padding_bottom=20,
            element_offset=50,
            # elementoutlinecolor="f00"
        )
        self.__task_text_view_image_top = avg.ImageNode(
            parent=self,
            size=(self.size[0], self.size[1] / 12),
            href="canvas:task_text_view")
        self.__task_text_view_image_bottom = avg.ImageNode(
            parent=self,
            pos=(0, self.size[1] * 11 / 12),
            size=(self.size[0], self.size[1] / 12),
            href="canvas:task_text_view")
        self.__phase_block_label = avg.WordsNode(
            parent=self,
            pos=(3, self.size[1] - 20),
            fontsize=15,
            color="555",
            alignment="left",
            variant="bold",
            rawtextmode=True,
            text="#{} - {}: {}".format(config_app.SESSION,
                                       self._study_handler.current_phase,
                                       self._study_handler.current_block_name)
            if self._study_handler else "")
        self.__interaction_activation_label = avg.WordsNode(parent=self,
                                                            pos=(3, 3),
                                                            fontsize=15,
                                                            color="555",
                                                            alignment="left",
                                                            variant="bold",
                                                            rawtextmode=True,
                                                            text="")

        self.__create_touch_vis_view()

        # initialize StudyLogging
        if config_app.study_mode:
            StudyLog.get_instance().write_event_log(
                "initialized view and divico control")

            self.subscribe(
                avg.Node.CURSOR_DOWN, lambda event: self.__log_touch(
                    event, event_type="CURSOR_DOWN"))
            self.subscribe(
                avg.Node.CURSOR_MOTION,
                lambda event: self.__log_touch(event,
                                               event_type="CURSOR_MOTION"))
            self.subscribe(
                avg.Node.CURSOR_UP,
                lambda event: self.__log_touch(event, event_type="CURSOR_UP"))
示例#23
0
 def __createImageNode(self, bmp):
     node = avg.ImageNode()
     node.setBitmap(bmp)
     return node
示例#24
0
    def testComplexPublisher(self):
        def setupUnsubscribe():
            self.downCalled = [False, False]
            self.msgIDs = []
            for i in range(0, 2):
                self.msgIDs.append(
                    self.img.subscribe(
                        avg.Node.CURSOR_DOWN,
                        lambda event, i=i: onUnsubscribeDown(i)))

        def onUnsubscribeDown(i):
            self.downCalled[i] = True
            for j in range(0, 2):
                self.img.unsubscribe(avg.Node.CURSOR_DOWN, self.msgIDs[j])

        def assertCorrectUnsubscribe():
            # Exactly one of the two callbacks should have been invoked
            self.assert_(self.downCalled[0] != self.downCalled[1])

        def setupSubscribe():
            self.downCalled = [False, False]
            self.msgIDs = []
            self.msgIDs.append(
                self.img.subscribe(avg.Node.CURSOR_DOWN,
                                   lambda event: onSubscribeDown()))

        def onSubscribeDown():
            self.downCalled[0] = True
            self.msgIDs.append(
                self.img.subscribe(avg.Node.CURSOR_DOWN,
                                   lambda event: onSecondSubscribeDown()))

        def onSecondSubscribeDown():
            self.downCalled[1] = True

        def setupCallableUnsubscribe():
            self.msgIDs = []
            for i in range(0, 2):
                self.msgIDs.append(
                    self.img.subscribe(avg.Node.CURSOR_DOWN,
                                       onUnsubscribeCallableDown))

        def onUnsubscribeCallableDown(event):
            self.assertRaises(
                avg.Exception, lambda: self.img.unsubscribe(
                    avg.Node.CURSOR_DOWN, onUnsubscribeCallableDown))
            for j in range(0, 2):
                self.img.unsubscribe(avg.Node.CURSOR_DOWN, self.msgIDs[j])

        def assertDownsCalled(expectedState):
            self.assert_(self.downCalled == expectedState)

        root = self.loadEmptyScene()
        self.img = avg.ImageNode(pos=(0, 0),
                                 href="rgb24-65x65.png",
                                 parent=root)

        self.start(
            False,
            (  # Subscribe twice to an event, unsubscribe both during processing of the 
                # first. Second shouldn't be called anymore.
                setupUnsubscribe,
                lambda: self.fakeClick(10, 10),
                assertCorrectUnsubscribe,

                # Subscribe twice to an event. unsubscribe using callable should
                # fail because it's unclear which subscriber should be unsubscribed.
                setupCallableUnsubscribe,
                lambda: self.fakeClick(10, 10),

                # Subscribe to an event, subscribe again during event processing.
                # The second one shouldn't be called immediately.
                setupSubscribe,
                lambda: self.fakeClick(10, 10),
                lambda: assertDownsCalled([True, False]),
                lambda: self.fakeClick(10, 10),
                lambda: assertDownsCalled([True, True]),
            ))
示例#25
0
    def testVideoWriter(self):
        def startWriter(fps, syncToPlayback):
            self.videoWriter = avg.VideoWriter(canvas, "test.mov", fps, 3, 5,
                                               syncToPlayback)

        def stopWriter():
            self.videoWriter.stop()

        def killWriter():
            self.videoWriter = None

        def pauseWriter():
            self.videoWriter.pause()

        def playWriter():
            self.videoWriter.play()

        def hideVideo():
            videoNode.opacity = 0

        def showVideo():
            videoNode.opacity = 1

        def checkVideo(numFrames):
            savedVideoNode = avg.VideoNode(href="../test.mov",
                                           pos=(48, 0),
                                           threaded=False,
                                           parent=root)
            savedVideoNode.pause()
            self.assertEqual(savedVideoNode.getVideoCodec(), "mjpeg")
            self.assertEqual(savedVideoNode.getNumFrames(), numFrames)
            self.assertEqual(savedVideoNode.getStreamPixelFormat(), "yuvj420p")

        def testCreateException():
            self.assertRaises(
                avg.Exception, lambda: avg.VideoWriter(
                    player.getMainCanvas(), "nonexistentdir/test.mov", 30))

        if not (self._isCurrentDirWriteable()):
            self.skip("Current dir not writeable.")
            return
        if player.isUsingGLES():
            self.skip("VideoWriter not supported under GLES.")
            return

        self.assertRaises(
            avg.Exception, lambda: avg.VideoWriter(player.getMainCanvas(
            ), "test.mov", 30, 3, 5, False))

        for useCanvas in (False, True):
            player.setFakeFPS(30)

            root = self.loadEmptyScene()
            videoNode = avg.VideoNode(href="mpeg1-48x48.mov", threaded=False)
            if useCanvas:
                canvas = player.createCanvas(id="canvas",
                                             size=(48, 48),
                                             mediadir="media")
                canvas.getRootNode().appendChild(videoNode)
                avg.ImageNode(parent=root, href="canvas:canvas")
                testImageName = "testVideoWriterCanvas"
            else:
                root.appendChild(videoNode)
                canvas = player.getMainCanvas()
                testImageName = "testVideoWriter"

            self.start(False, (
                videoNode.play,
                lambda: startWriter(30, True),
                lambda: self.delay(100),
                stopWriter,
                killWriter,
                lambda: checkVideo(4),
                hideVideo,
                lambda: self.compareImage(testImageName + "1"),
                showVideo,
                testCreateException,
                lambda: startWriter(15, False),
                lambda: self.delay(150),
                stopWriter,
                killWriter,
                lambda: checkVideo(2),
                lambda: startWriter(30, False),
                pauseWriter,
                lambda: self.delay(200),
                playWriter,
                stopWriter,
                killWriter,
                lambda: checkVideo(1),
                lambda: startWriter(30, False),
                killWriter,
                lambda: checkVideo(1),
            ))
            os.remove("test.mov")
示例#26
0
 def redAlphaScene():
     self.redRect = avg.RectNode(parent=self.root, pos=(5, 5), fillcolor='FF0000',
             fillopacity=1, opacity=0, size=(72, 72))
     self.node = avg.ImageNode(parent=self.root, pos=(10,10),
             href="rgb24alpha-64x64.png")
     resetFX()
示例#27
0
 def createCompressed():
     avg.ImageNode(href="canvas:offscreencanvas",
                   compression="B5G6R5",
                   parent=root)
示例#28
0
 def newNode():
     self.newNode = avg.ImageNode(parent=root, href="rgb24-32x32.png", pos=(64,0))
     self.newNode.setEffect(avg.NullFXNode())
示例#29
0
 def makeSelfRef1():
     avg.ImageNode(href="canvas:offscreencanvas1",
                   parent=self.offscreen1.getRootNode())
示例#30
0
 def __createOffscreenCanvas(self, canvasName, handleEvents):
     canvas = player.createCanvas(id=canvasName, size=(160,120), 
             handleevents=handleEvents)
     canvas.getRootNode().mediadir = "media"
     avg.ImageNode(id="test1", href="rgb24-65x65.png", parent=canvas.getRootNode())
     return canvas