def testCanvasEvents(self): def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenRelPos = event.contact.getRelPos( offscreenImage, event.pos) self.__offscreenAbsPos = event.contact.getRelPos( player.getRootNode(), event.pos) tempNode = avg.ImageNode(href="rgb24-64x64.png") self.assertRaises( avg.Exception, lambda: event.contact.getRelPos(tempNode, event.pos)) def onMainDown(event): self.__mainDownCalled = True def reset(): self.__offscreenImageDownCalled = False self.__mainDownCalled = False def setPos(): self.node.pos = (80, 60) self.node.size = (80, 60) mainCanvas, offscreenCanvas = self.__setupCanvas(True) offscreenImage = offscreenCanvas.getElementByID("test1") offscreenImage.subscribe(avg.Node.CURSOR_DOWN, onOffscreenImageDown) player.getRootNode().subscribe(avg.Node.CURSOR_DOWN, onMainDown) self.node.pos = (10, 10) self.__offscreenImageDownCalled = False self.__mainDownCalled = False self.start(False, ( lambda: self.fakeClick(15, 15), lambda: self.assert_(self.__offscreenImageDownCalled), lambda: self.assert_(self.__offscreenRelPos == (5, 5)), lambda: self.assert_(self.__offscreenAbsPos == (15, 15)), reset, lambda: self.fakeClick(5, 5), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(80, 10), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, setPos, lambda: self.fakeClick(70, 65), lambda: self.assert_(not (self.__offscreenImageDownCalled)), lambda: self.fakeClick(120, 65), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(110, 65), lambda: self.assert_(self.__offscreenImageDownCalled and self. __mainDownCalled), reset, lambda: self.fakeClick(1, 1), lambda: self.assert_(not (self.__offscreenImageDownCalled) and self .__mainDownCalled), ))
def __clampPos(self, pos): if pos[0] < 0: pos[0] = 0 if pos[1] < 0: pos[1] = 0 if pos[0] >= player.getRootNode().size[0]: pos[0] = player.getRootNode().size[0]-1 if pos[1] >= player.getRootNode().size[1]: pos[1] = player.getRootNode().size[1]-1 return pos
def __clampPos(self, pos): if pos[0] < 0: pos[0] = 0 if pos[1] < 0: pos[1] = 0 if pos[0] >= player.getRootNode().size[0]: pos[0] = player.getRootNode().size[0] - 1 if pos[1] >= player.getRootNode().size[1]: pos[1] = player.getRootNode().size[1] - 1 return pos
def testCanvasEvents(self): def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenRelPos = event.contact.getRelPos(offscreenImage, event.pos) self.__offscreenAbsPos = event.contact.getRelPos( player.getRootNode(), event.pos) tempNode = avg.ImageNode(href="rgb24-64x64.png") self.assertRaises(avg.Exception, lambda: event.contact.getRelPos(tempNode, event.pos)) def onMainDown(event): self.__mainDownCalled = True def reset(): self.__offscreenImageDownCalled = False self.__mainDownCalled = False def setPos(): self.node.pos = (80, 60) self.node.size = (80, 60) mainCanvas, offscreenCanvas = self.__setupCanvas(True) offscreenImage = offscreenCanvas.getElementByID("test1") offscreenImage.subscribe(avg.Node.CURSOR_DOWN, onOffscreenImageDown) player.getRootNode().subscribe(avg.Node.CURSOR_DOWN, onMainDown) self.node.pos = (10,10) self.__offscreenImageDownCalled = False self.__mainDownCalled = False self.start(False, (lambda: self.fakeClick(15, 15), lambda: self.assert_(self.__offscreenImageDownCalled), lambda: self.assert_(self.__offscreenRelPos == (5,5)), lambda: self.assert_(self.__offscreenAbsPos == (15,15)), reset, lambda: self.fakeClick(5, 5), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(80, 10), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, setPos, lambda: self.fakeClick(70, 65), lambda: self.assert_(not(self.__offscreenImageDownCalled)), lambda: self.fakeClick(120, 65), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(110, 65), lambda: self.assert_(self.__offscreenImageDownCalled and self.__mainDownCalled), reset, lambda: self.fakeClick(1, 1), lambda: self.assert_(not(self.__offscreenImageDownCalled) and self.__mainDownCalled), ))
def testCanvasEvents(self): def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenPos = event.pos def onMainDown(event): self.__mainDownCalled = True def reset(): self.__offscreenImageDownCalled = False self.__mainDownCalled = False def setPos(): self.node.pos = (80, 60) self.node.size = (80, 60) mainCanvas, offscreenCanvas = self.__setupCanvas(True) offscreenImage = offscreenCanvas.getElementByID("test1") offscreenImage.subscribe(avg.Node.CURSOR_DOWN, onOffscreenImageDown) player.getRootNode().subscribe(avg.Node.CURSOR_DOWN, onMainDown) self.node.pos = (10,10) self.__offscreenImageDownCalled = False self.__mainDownCalled = False self.start(False, (lambda: self.fakeClick(15, 15), lambda: self.assert_(self.__offscreenImageDownCalled), lambda: self.assert_(self.__offscreenPos == (5,5)), reset, lambda: self.fakeClick(5, 5), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(80, 10), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, setPos, lambda: self.fakeClick(70, 65), lambda: self.assert_(not(self.__offscreenImageDownCalled)), lambda: self.fakeClick(120, 65), lambda: self.assert_(not(self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(110, 65), lambda: self.assert_(self.__offscreenImageDownCalled and self.__mainDownCalled), reset, lambda: self.fakeClick(1, 1), lambda: self.assert_(not(self.__offscreenImageDownCalled) and self.__mainDownCalled), ))
def testCanvasEvents(self): def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenPos = event.pos def onMainDown(event): self.__mainDownCalled = True def reset(): self.__offscreenImageDownCalled = False self.__mainDownCalled = False def setPos(): self.node.pos = (80, 60) self.node.size = (80, 60) mainCanvas, offscreenCanvas = self.__setupCanvas(True) offscreenImage = offscreenCanvas.getElementByID("test1") offscreenImage.subscribe(avg.Node.CURSOR_DOWN, onOffscreenImageDown) player.getRootNode().subscribe(avg.Node.CURSOR_DOWN, onMainDown) self.node.pos = (10, 10) self.__offscreenImageDownCalled = False self.__mainDownCalled = False self.start(False, ( lambda: self.fakeClick(15, 15), lambda: self.assert_(self.__offscreenImageDownCalled), lambda: self.assert_(self.__offscreenPos == (5, 5)), reset, lambda: self.fakeClick(5, 5), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(80, 10), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, setPos, lambda: self.fakeClick(70, 65), lambda: self.assert_(not (self.__offscreenImageDownCalled)), lambda: self.fakeClick(120, 65), lambda: self.assert_(not (self.__offscreenImageDownCalled)), reset, lambda: self.fakeClick(110, 65), lambda: self.assert_(self.__offscreenImageDownCalled and self. __mainDownCalled), reset, lambda: self.fakeClick(1, 1), lambda: self.assert_(not (self.__offscreenImageDownCalled) and self .__mainDownCalled), ))
def init(self): rootNode = player.getRootNode() orig = avg.ImageNode(parent = rootNode, href='../test/media/hsl.png') invert = avg.ImageNode(parent = rootNode, href='../test/media/hsl.png', pos=(orig.size.x+10, 0)) invert.setEffect(avg.InvertFXNode())
def unlink(self, kill=True): rootNode = player.getRootNode() if rootNode: rootNode.unsubscribe(avg.Node.CURSOR_DOWN, self.__onTouchDown) rootNode.unsubscribe(avg.Node.HOVER_DOWN, self.__onTouchDown) rootNode.unsubscribe(avg.Node.TANGIBLE_DOWN, self.__onTouchDown) super(TouchVisualizationOverlay, self).unlink(kill)
def unlink(self, kill=True): rootNode = player.getRootNode() if rootNode: rootNode.unsubscribe(avg.Node.CURSOR_DOWN, self.__onTouchDown) rootNode.unsubscribe(avg.Node.HOVER_DOWN, self.__onTouchDown) rootNode.unsubscribe(avg.Node.TANGIBLE_DOWN, self.__onTouchDown) super(TouchVisualizationOverlay, self).unlink(kill)
def init(self): self.testInstance.assert_(not player.isFullscreen()) rootNodeSize = player.getRootNode().size self.testInstance.assertEqual(rootNodeSize, TEST_RESOLUTION) # windowSize = player.getWindowResolution() # self.testInstance.assertEqual(windowSize, Point2D(TEST_RESOLUTION)/2) self.requestStop()
def setup(self, onKeyDownCb, onKeyUpCb): player.subscribe(avg.Player.KEY_DOWN, self.__onKeyDown) player.subscribe(avg.Player.KEY_UP, self.__onKeyUp) self.__onKeyDownCb = onKeyDownCb self.__onKeyUpCb = onKeyUpCb self.__keyCaptionsNode = KeysCaptionNode(pos=(5,5), parent=player.getRootNode())
def setup(self, onKeyDownCb, onKeyUpCb): player.subscribe(avg.Player.KEY_DOWN, self.__onKeyDown) player.subscribe(avg.Player.KEY_UP, self.__onKeyUp) self.__onKeyDownCb = onKeyDownCb self.__onKeyUpCb = onKeyUpCb self.__keyCaptionsNode = KeysCaptionNode(pos=(5,5), parent=player.getRootNode())
def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenRelPos = event.contact.getRelPos(offscreenImage, event.pos) self.__offscreenAbsPos = event.contact.getRelPos( player.getRootNode(), event.pos) tempNode = avg.ImageNode(href="rgb24-64x64.png") self.assertRaises(avg.Exception, lambda: event.contact.getRelPos(tempNode, event.pos))
def init(self): self.testInstance.assert_(not player.isFullscreen()) rootNodeSize = player.getRootNode().size self.testInstance.assertEqual(rootNodeSize, TEST_RESOLUTION) # windowSize = player.getWindowResolution() # self.testInstance.assertEqual(windowSize, Point2D(TEST_RESOLUTION)/2) self.requestStop()
def testAppResolution(self): app = TestApp() app.testRun( [ lambda: self.assertEquals(player.getRootNode().size, (160, 120)), lambda: self.assert_(not player.isFullscreen()), ] )
def onOffscreenImageDown(event): self.__offscreenImageDownCalled = True self.__offscreenRelPos = event.contact.getRelPos(offscreenImage, event.pos) self.__offscreenAbsPos = event.contact.getRelPos( player.getRootNode(), event.pos) tempNode = avg.ImageNode(href="rgb24-64x64.png") self.assertRaises(avg.Exception, lambda: event.contact.getRelPos(tempNode, event.pos))
def initFXCache(numFXNodes): nodes = [] mediadir = os.path.join(os.path.dirname(__file__), "data") for i in range(numFXNodes): node = avg.ImageNode(href=mediadir + "/black.png", parent=player.getRootNode()) node.setEffect(avg.NullFXNode()) nodes.append(node) for node in nodes: node.unlink(True)
def _setupBaseDivs(self, resolution): player.loadString(''' <?xml version="1.0"?> <!DOCTYPE avg SYSTEM "../../libavg/doc/avg.dtd"> <avg width="%s" height="%s"> </avg>''' % (resolution.x, resolution.y)) rootNode = player.getRootNode() self._appNode = avg.DivNode(opacity=0, sensitive=False, size=rootNode.size, parent=rootNode)
def test2VideosAtOnce(self): player.setFakeFPS(25) self.loadEmptyScene() root = player.getRootNode() for pos in ((0,0), (80,0)): video = avg.VideoNode(pos=pos, threaded=False, href="mpeg1-48x48.mov", parent=root) video.play() self.start(False, [lambda: self.compareImage("test2VideosAtOnce1"),])
def _setupBaseDivs(self, resolution): player.loadString(''' <?xml version="1.0"?> <!DOCTYPE avg SYSTEM "../../libavg/doc/avg.dtd"> <avg width="%s" height="%s"> </avg>''' % (resolution.x, resolution.y)) rootNode = player.getRootNode() self._appNode = avg.DivNode(opacity=0, sensitive=False, size=rootNode.size, parent=rootNode)
def setTouchVisualization(self, visClass): if not(self.__touchVisOverlay is None): self.__touchVisOverlay.unlink(True) del self.__touchVisOverlay self.__touchVisOverlay = None if not(visClass is None): rootNode = player.getRootNode() self.__touchVisOverlay = apphelpers.TouchVisualizationOverlay( isDebug=False, visClass=visClass, size=self._appNode.size, parent=rootNode)
def initFXCache(numFXNodes): nodes = [] mediadir = os.path.join(os.path.dirname(__file__), 'data') for i in range(numFXNodes): node = avg.ImageNode(href=mediadir + "/black.png", parent=player.getRootNode()) node.setEffect(avg.NullFXNode()) nodes.append(node) for node in nodes: node.unlink(True)
def setTouchVisualization(self, visClass): if not(self.__touchVisOverlay is None): self.__touchVisOverlay.unlink(True) del self.__touchVisOverlay self.__touchVisOverlay = None if not(visClass is None): rootNode = player.getRootNode() self.__touchVisOverlay = apphelpers.TouchVisualizationOverlay( isDebug=False, visClass=visClass, size=self._appNode.size, parent=rootNode)
def __switchShowMTEvents(self): if self.__debugTouchVisOverlay is None: rootNode = player.getRootNode() self.__debugTouchVisOverlay = apphelpers.TouchVisualizationOverlay( isDebug=True, visClass=apphelpers.DebugTouchVisualization, size=self._appNode.size, parent=rootNode) else: self.__debugTouchVisOverlay.unlink(True) del self.__debugTouchVisOverlay self.__debugTouchVisOverlay = None
def __switchShowMTEvents(self): if self.__debugTouchVisOverlay is None: rootNode = player.getRootNode() self.__debugTouchVisOverlay = apphelpers.TouchVisualizationOverlay( isDebug=True, visClass=apphelpers.DebugTouchVisualization, size=self._appNode.size, parent=rootNode) else: self.__debugTouchVisOverlay.unlink(True) del self.__debugTouchVisOverlay self.__debugTouchVisOverlay = None
def test2VideosAtOnce(self): player.setFakeFPS(25) self.loadEmptyScene() root = player.getRootNode() for pos in ((0,0), (80,0)): video = avg.VideoNode(pos=pos, threaded=False, href="mpeg1-48x48.mov", parent=root) video.play() self.start(False, [lambda: self.compareImage("test2VideosAtOnce1"),])
def showMemoryUsage(self): if self.__memGraph: self.__memGraph.unlink(True) self.__graphs.remove(self.__memGraph) self.__memGraph = None else: size = (self._appNode.width, self._appNode.height/6.0) self.__memGraph = graph.AveragingGraph(title = 'Memory Usage', getValue = avg.getMemoryUsage, parent=player.getRootNode(), size=size) self.__graphs.append(self.__memGraph) self.__positionGraphs()
def testPlayBeforeConnect(self): node = avg.VideoNode(href="media/mpeg1-48x48.mov", threaded=False) node.play() player.createMainCanvas(size=(160,120)) root = player.getRootNode() root.insertChild(node, 0) player.setFakeFPS(25) self.start(False, (lambda: self.assertEqual(node.size, (48, 48)), lambda: self.compareImage("testPlayBeforeConnect"), ))
def testPlayBeforeConnect(self): node = avg.VideoNode(href="media/mpeg1-48x48.mov", threaded=False) node.play() player.createMainCanvas(size=(160,120)) root = player.getRootNode() root.insertChild(node, 0) player.setFakeFPS(25) self.start(False, (lambda: self.assertEqual(node.size, (48, 48)), lambda: self.compareImage("testPlayBeforeConnect"), ))
def showMemoryUsage(self): if self.__memGraph: self.__memGraph.unlink(True) self.__graphs.remove(self.__memGraph) self.__memGraph = None else: size = (self._appNode.width, self._appNode.height/6.0) self.__memGraph = graph.AveragingGraph(title = 'Memory Usage', getValue = avg.getMemoryUsage, parent=player.getRootNode(), size=size) self.__graphs.append(self.__memGraph) self.__positionGraphs()
def init(self): self.curFrame = 0 global g_options self.optdict = {} for attr in dir(g_options): if attr[0] != "_": self.optdict[attr] = eval("g_options.%s" % attr) avg.logger.info("Creating camera:") avg.logger.info("driver=%(driver)s device=%(device)s" % self.optdict) avg.logger.info("width=%(width)d height=%(height)d pixelformat=%(pixelFormat)s" % self.optdict) avg.logger.info("unit=%(unit)d framerate=%(framerate)d fw800=%(fw800)s" % self.optdict) self.camNode = avg.CameraNode( driver=g_options.driver, device=g_options.device, unit=g_options.unit, fw800=g_options.fw800, framerate=g_options.framerate, capturewidth=g_options.width, captureheight=g_options.height, pixelformat=g_options.pixelFormat, ) player.getRootNode().appendChild(self.camNode) if not g_options.noinfo: self.infoText = ( "Driver=%(driver)s (dev=%(device)s unit=%(unit)d) %(width)dx%(height)d@%(framerate)f" % self.optdict ) avg.WordsNode( text=self.infoText, color="ff3333", pos=(5, 5), fontsize=14, rawtextmode=True, parent=player.getRootNode(), ) frameText = avg.WordsNode(color="ff3333", pos=(5, 25), fontsize=14, parent=player.getRootNode()) player.subscribe(player.ON_FRAME, lambda: self.updateFrameDisplay(frameText))
def showVideoMemoryUsage(self): if self.__vidMemGraph: self.__vidMemGraph.delete() self.__graphs.remove(self.__vidMemGraph) self.__vidMemGraph = None else: size = (self._appNode.width, self._appNode.height/6.0) self.__vidMemGraph = graph.AveragingGraph(title='Video Memory Usage', getValue=player.getVideoMemUsed, parent=player.getRootNode(), size=size) self.__graphs.append(self.__vidMemGraph) self.__positionGraphs()
def __screenshot(self): fnum = 0 fnameTemplate = 'screenshot-%03d.png' while os.path.exists(fnameTemplate % fnum): fnum += 1 try: player.screenshot().save('screenshot-%03d.png' % fnum) except RuntimeError: text = 'Cannot save snapshot file' else: text = 'Screenshot saved as ' + fnameTemplate % fnum self.__killNotifyNode() self.__notifyNode = avg.WordsNode( text=text, x=player.getRootNode().width - 50, y=player.getRootNode().height - 50, alignment='right', fontsize=20, sensitive=False, parent=player.getRootNode()) player.setTimeout(2000, self.__killNotifyNode)
def __screenshot(self): fnum = 0 fnameTemplate = 'screenshot-%03d.png' while os.path.exists(fnameTemplate % fnum): fnum += 1 try: player.screenshot().save('screenshot-%03d.png' % fnum) except RuntimeError: text = 'Cannot save snapshot file' else: text = 'Screenshot saved as ' + fnameTemplate % fnum self.__killNotifyNode() self.__notifyNode = avg.WordsNode( text=text, x=player.getRootNode().width - 50, y=player.getRootNode().height - 50, alignment='right', fontsize=20, sensitive=False, parent=player.getRootNode()) player.setTimeout(2000, self.__killNotifyNode)
def __init__(self, isDebug, visClass, parent=None, **kwargs): super(TouchVisualizationOverlay, self).__init__(**kwargs) self.registerInstance(self, parent) self.sensitive = False self.visClass = visClass rootNode = player.getRootNode() if isDebug: self.elementoutlinecolor='FFFFAA' avg.RectNode(parent=self, size=self.size, fillopacity=0.2, fillcolor='000000') rootNode.subscribe(avg.Node.CURSOR_DOWN, self.__onTouchDown) rootNode.subscribe(avg.Node.HOVER_DOWN, self.__onTouchDown)
def onInit(self, parent=None): stationNode = avg.WordsNode(pos=(10,10), font="arial",text="Currently: " + station, parent=player.getRootNode()) windSpeedNode = avg.WordsNode(pos=(10,30), font="arial",text="Wind Speed: " + windSpeed, parent=player.getRootNode()) currTempNode = avg.WordsNode(pos=(10,50), font="arial",text="Temp: " + currTemp, parent=player.getRootNode()) winDirNode = avg.WordsNode(pos=(10,70), font="arial",text="Wind Direction: " + windDir, parent=player.getRootNode()) todayNode = avg.WordsNode(pos=(180,70), font="arial",text=today, parent=player.getRootNode()) imgNode = avg.ImageNode(href="images/" + imageCode + ".png", pos=(10,70),parent=player.getRootNode()) print(today + "In Weather Class") # Forecast for coming days column = 10 for i in range(2,6): forecastDaysNode = avg.WordsNode(pos=(column,200), font="arial",text=forecastDays[i], parent=player.getRootNode()) forecastTextNode = avg.WordsNode(pos=(column,220), font="arial",text=forecastText[i], parent=player.getRootNode()) forecastHighsNode = avg.WordsNode(pos=(column,240), font="arial",text=forecastHighs[i] + "c", parent=player.getRootNode()) forecastLowsNode = avg.WordsNode(pos=(column,260), font="arial",text=forecastLows[i] + "c", parent=player.getRootNode()) column += 120 #time.sleep(5) #retrieval() #player.play() return
def testNodePythonSubclass(): class CustomImageNode(avg.ImageNode): def __init__(self, p, parent=None, **kwargs): avg.ImageNode.__init__(self, pos=p, href="rgb24-64x64.png", **kwargs) self.registerInstance(self, parent) def customMethod(self): pass class CustomDivNode(avg.DivNode): def __init__(self, parent=None, **kwargs): avg.DivNode.__init__(self, **kwargs) self.registerInstance(self, parent) CustomImageNode((23, 42), parent=self) customNode = CustomImageNode((23, 42), parent=root) retrievedImage = root.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode) self.assertEqual(retrievedImage.pos, (23, 42)) self.assertEqual(retrievedImage.href, "rgb24-64x64.png") retrievedImage.customMethod() customNode.unlink(True) CustomDivNode(parent=player.getRootNode()) retrievedDiv = player.getRootNode().getChild(0) self.assertEqual(type(retrievedDiv), CustomDivNode) retrievedImage = retrievedDiv.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode) retrievedDiv = retrievedImage.parent self.assertEqual(type(retrievedDiv), CustomDivNode) retrievedDiv.unlink(True) customNode = CustomImageNode((23, 42)) root.appendChild(customNode) retrievedImage = root.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode)
def testNodePythonSubclass(): class CustomImageNode(avg.ImageNode): def __init__(self, p, parent=None, **kwargs): avg.ImageNode.__init__(self, pos=p, href="rgb24-64x64.png", **kwargs) self.registerInstance(self, parent) def customMethod(self): pass class CustomDivNode(avg.DivNode): def __init__(self, parent=None, **kwargs): avg.DivNode.__init__(self, **kwargs) self.registerInstance(self, parent) CustomImageNode((23,42), parent=self) customNode = CustomImageNode((23, 42), parent=root) retrievedImage = root.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode) self.assertEqual(retrievedImage.pos, (23,42)) self.assertEqual(retrievedImage.href, "rgb24-64x64.png") retrievedImage.customMethod() customNode.unlink(True) CustomDivNode(parent=player.getRootNode()) retrievedDiv = player.getRootNode().getChild(0) self.assertEqual(type(retrievedDiv), CustomDivNode) retrievedImage = retrievedDiv.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode) retrievedDiv = retrievedImage.parent self.assertEqual(type(retrievedDiv), CustomDivNode) retrievedDiv.unlink(True) customNode = CustomImageNode((23,42)) root.appendChild(customNode) retrievedImage = root.getChild(0) self.assertEqual(type(retrievedImage), CustomImageNode)
def __init__(self): self.__oldEventHook = player.getEventHook() player.setEventHook(self.__onEvent) root = player.getRootNode() posX = root.size.x - 15 posY = root.size.y - 20 self.__layer = avg.WordsNode(text='Multitouch emulation active', pos=(posX, posY), alignment = 'right', color='DDDDDD', sensitive=False, fontsize=18, parent=root)
def __init__(self, isDebug, visClass, rootNode=None, parent=None, **kwargs): super(TouchVisualizationOverlay, self).__init__(**kwargs) self.registerInstance(self, parent) self.sensitive = False self.visClass = visClass if rootNode is None: rootNode = player.getRootNode() if isDebug: self.elementoutlinecolor='FFFFAA' avg.RectNode(parent=self, size=self.size, fillopacity=0.2, fillcolor='000000') rootNode.subscribe(avg.Node.CURSOR_DOWN, self.__onTouchDown) rootNode.subscribe(avg.Node.HOVER_DOWN, self.__onTouchDown) rootNode.subscribe(avg.Node.TANGIBLE_DOWN, self.__onTouchDown)
def __init__(self): self.__mouseState = self.MOUSE_STATE_UP self.__cursorID = 0 self.__dualTouch = False self.__secondTouch = False self.__source = avg.Event.TOUCH self.__oldEventHook = player.getEventHook() player.setEventHook(self.__onEvent) root = player.getRootNode() self.__caption = avg.WordsNode(pos=(root.size.x - 15, root.size.y - 20), alignment = 'right', color='DDDDDD', sensitive=False, fontsize=14, parent=root) self.__updateCaption()
def __init__(self): self.__mouseState = self.MOUSE_STATE_UP self.__cursorID = 0 self.__dualTouch = False self.__secondTouch = False self.__source = avg.Event.TOUCH self.__oldEventHook = player.getEventHook() player.setEventHook(self.__onEvent) root = player.getRootNode() self.__caption = avg.WordsNode(pos=(root.size.x - 15, root.size.y - 20), alignment = 'right', color='DDDDDD', sensitive=False, fontsize=14, parent=root) self.__updateCaption()
def loadEmptyScene(self, resolution=(160,120)): player.createMainCanvas(size=resolution) root = player.getRootNode() root.mediadir = "media" return root
def testAppRotation(self): app = TestApp() app.settings.set('app_rotation', 'left') app.testRun([ lambda: self.assertEquals(player.getRootNode().size, (120, 160)), ])
def testAppResolution(self): app = TestApp() app.testRun([ lambda: self.assertEquals(player.getRootNode().size, (160, 120)), lambda: self.assert_(not player.isFullscreen()), ])
class AVGMTAppStarter(AVGAppStarter): def __init__(self, *args, **kwargs): self.__touchVisOverlay = None super(AVGMTAppStarter, self).__init__(*args, **kwargs) def setTouchVisualization(self, visClass): if not (self.__touchVisOverlay is None): self.__touchVisOverlay.unlink(True) del self.__touchVisOverlay self.__touchVisOverlay = None if not (visClass is None): rootNode = player.getRootNode() self.__touchVisOverlay = apphelpers.TouchVisualizationOverlay( isDebug=False, visClass=visClass, size=self._appNode.size, parent=rootNode) def toggleTrackerImage(self): if self.__showTrackerImage: self.hideTrackerImage() else: self.showTrackerImage() def showTrackerImage(self): if self.__showTrackerImage: return self.__showTrackerImage = True self.__updateTrackerImageInterval = \ player.subscribe(player.ON_FRAME, self.__updateTrackerImage) self.__trackerImageNode.opacity = 1 self.tracker.setDebugImages(False, True) def hideTrackerImage(self): if not self.__showTrackerImage: return self.__showTrackerImage = False if self.__updateTrackerImageInterval: player.clearInterval(self.__updateTrackerImageInterval) self.__updateTrackerImageInterval = None self.__trackerImageNode.opacity = 0 self.tracker.setDebugImages(False, False) def __updateTrackerImage(self): def transformPos((x, y)): if self.trackerFlipX: x = 1 - x if self.trackerFlipY: y = 1 - y return (x, y) fingerBitmap = self.tracker.getImage(avg.IMG_FINGERS) node = self.__trackerImageNode node.setBitmap(fingerBitmap) node.pos = self.tracker.getDisplayROIPos() node.size = self.tracker.getDisplayROISize() grid = node.getOrigVertexCoords() grid = [[transformPos(pos) for pos in line] for line in grid] node.setWarpedVertexCoords(grid) def _onStart(self): from camcalibrator import Calibrator # we must add the tracker first, calibrator depends on it try: player.enableMultitouch() except RuntimeError, err: avg.logger.warning(str(err)) self.tracker = player.getTracker() if self.tracker: if Calibrator: self.__calibratorNode = player.createNode( 'div', { 'opacity': 0, 'active': False, }) rootNode = player.getRootNode() rootNode.appendChild(self.__calibratorNode) self.__calibratorNode.size = rootNode.size self.__calibrator = Calibrator(self.__calibratorNode, appStarter=self) self.__calibrator.setOnCalibrationSuccess( self.__onCalibrationSuccess) self.__calibrator.init() else: self.__calibrator = None self.__showTrackerImage = False self.__updateTrackerImageInterval = None self.__trackerImageNode = player.createNode( 'image', {'sensitive': False}) player.getRootNode().appendChild(self.__trackerImageNode) self.__updateTrackerImageFixup() g_KbManager.bindKey('h', self.tracker.resetHistory, 'RESET tracker history') g_KbManager.bindKey('d', self.toggleTrackerImage, 'toggle tracker image') if self.__calibrator: g_KbManager.bindKey('c', self.__enterCalibrator, 'enter calibrator') AVGAppStarter._onStart(self)
#!/usr/bin/env python # -*- coding: utf-8 -*- from libavg import avg, player canvas = player.createMainCanvas(size=(160,120)) avg.MeshNode(texhref="rgb24-64x64.png", vertexcoords=((0,0), (64,0), (0,64), (64, 64), (32, 32)), texcoords=((0,0), (1,0), (0,1), (1,1), (0.5,0.5)), triangles=((0,1,4), (1,3,4), (3,2,4), (2,0,4)), parent=player.getRootNode()) player.play()
def init(self): self.testInstance.assert_(player.isFullscreen()) rootNodeSize = player.getRootNode().size self.testInstance.assertEqual(rootNodeSize, resolution) self.requestStop()
def size(self): return player.getRootNode().size
def onInit(self): global g_gridSize self.mediadir = utils.getMediaDir(__file__) screenSize = player.getRootNode().size g_gridSize = int(min(floor(screenSize.x / BASE_GRIDSIZE.x), floor(screenSize.y / BASE_GRIDSIZE.y))) borderWidth = g_gridSize * BASE_BORDERWIDTH battlegroundSize = Point2D( floor((screenSize.x - borderWidth * 2) / g_gridSize) * g_gridSize, floor((screenSize.y - borderWidth * 2) / g_gridSize) * g_gridSize) borderWidth = (screenSize - battlegroundSize) / 2.0 avg.RectNode(parent=self, size=screenSize, opacity=0, fillcolor='B00000', fillopacity=1) avg.RectNode(parent=self, pos=borderWidth, size=battlegroundSize, opacity=0, fillcolor='000000', fillopacity=1) battleground = avg.DivNode(parent=self, pos=borderWidth, size=battlegroundSize, crop=True) self.__bgAnims = [] for i in xrange(4): self.__bgAnims.append(BgAnim(parent=battleground)) self.__initIdleDemo(battleground) self.__gameDiv = avg.DivNode(parent=battleground, size=battlegroundSize) self.__ctrlDiv = avg.DivNode(parent=self.__gameDiv, size=battlegroundSize) self.__winsDiv = avg.DivNode(parent=self.__ctrlDiv, size=battlegroundSize, opacity=0, sensitive=False) self.__shield = Shield(parent=self.__ctrlDiv) self.__blocker = Blocker(parent=self.__ctrlDiv) ctrlSize = Point2D(g_gridSize * 42, g_gridSize * 42) playerPos = ctrlSize.x + g_gridSize * 2 self.__controllers = [] # 1st p = RealPlayer(PLAYER_COLORS[0], (playerPos, playerPos), (g_gridSize, 0), self.__winsDiv, ctrlSize, pi, parent=self.__gameDiv) self.__controllers.append(Controller(p, self.joinPlayer, parent=self.__ctrlDiv, pos=(g_gridSize, g_gridSize), size=ctrlSize, angle=0)) # 2nd p = RealPlayer(PLAYER_COLORS[1], (self.__ctrlDiv.size.x - playerPos, playerPos), (-g_gridSize, 0), self.__winsDiv, ctrlSize, -pi / 2, parent=self.__gameDiv) self.__controllers.append(Controller(p, self.joinPlayer, parent=self.__ctrlDiv, pos=(self.__ctrlDiv.size.x - g_gridSize, g_gridSize), size=ctrlSize, angle=pi / 2)) # 3rd p = RealPlayer(PLAYER_COLORS[2], (playerPos, self.__ctrlDiv.size.y - playerPos), (g_gridSize, 0), self.__winsDiv, ctrlSize, pi / 2, parent=self.__gameDiv) self.__controllers.append(Controller(p, self.joinPlayer, parent=self.__ctrlDiv, pos=(g_gridSize, self.__ctrlDiv.size.y - g_gridSize), size=ctrlSize, angle=-pi / 2)) # 4th p = RealPlayer(PLAYER_COLORS[3], (self.__ctrlDiv.size.x - playerPos, self.__ctrlDiv.size.y - playerPos), (-g_gridSize, 0), self.__winsDiv, ctrlSize, 0, parent=self.__gameDiv) self.__controllers.append(Controller(p, self.joinPlayer, parent=self.__ctrlDiv, pos=(self.__ctrlDiv.size.x - g_gridSize, self.__ctrlDiv.size.y - g_gridSize), size=ctrlSize, angle=pi)) self.__startButton = Button(self.__ctrlDiv, 'FF0000', 'O', self.__start) self.__clearButton = Button(self.__ctrlDiv, 'FF0000', '#', self.__clearWins) self.__countdownNode = avg.CircleNode(parent=self.__ctrlDiv, pos=self.__ctrlDiv.size / 2, r=self.__ctrlDiv.size.y / 4, opacity=0, sensitive=False) self.__leftQuitButton = Button(self.__winsDiv, 'FF0000', 'xl', player.stop) self.__leftQuitButton.activate() self.__rightQuitButton = Button(self.__winsDiv, 'FF0000', 'xr', player.stop) self.__rightQuitButton.activate() self.__redSound = avg.SoundNode(parent=battleground, href='red.wav') self.__yellowSound = avg.SoundNode(parent=battleground, href='yellow.wav') self.__greenSound = avg.SoundNode(parent=battleground, href='green.wav') self.__startSound = avg.SoundNode(parent=battleground, href='start.wav') self.__downHandlerID = None self.__preStart() self.__startSound.play() self.__ctrlDiv.sensitive = True for bga in self.__bgAnims: bga.start() self.__setupMultitouch() self.__startIdleDemo()
def testAppRotation(self): app = TestApp() app.settings.set('app_rotation', 'left') app.testRun([ lambda: self.assertEquals(player.getRootNode().size, (120, 160)), ])
def onMouseMove(self, event): windowWidth = player.getRootNode().width ratio = event.x/float(windowWidth) self.videoListNode.x = -(ratio*(self.getTotalWidth()-windowWidth))
def onMouseMove(self, event): windowWidth = player.getRootNode().width ratio = event.x / float(windowWidth) self.videoListNode.x = -(ratio * (self.getTotalWidth() - windowWidth))
def loadEmptyScene(self, resolution=(160,120)): player.createMainCanvas(size=resolution) root = player.getRootNode() root.mediadir = "media" return root
def init(self): self.testInstance.assert_(player.isFullscreen()) rootNodeSize = player.getRootNode().size self.testInstance.assertEqual(rootNodeSize, res) self.requestStop()