def createDiv(): imgNode = player.createNode("image", {"id":"imageid", "href":"rgb24-64x64.png"}) node = player.createNode("div", {"id":"divid"}) node.appendChild(imgNode) imgNode.id = "imageid" root.appendChild(node) self.assertRaises(RuntimeError, lambda: setImageID(imgNode))
def createWords(useXml): if useXml: node = player.createNode("<words text='test'/>") else: node = player.createNode("words", {"text":"test"}) node.font="Bitstream Vera Sans" node.fontsize=12 node.width=200 return node
def createVideo(useXml): if useXml: node = player.createNode( "<video href='mpeg1-48x48.mov' threaded='false'/>") else: node = player.createNode("video", {"href":"mpeg1-48x48.mov", "threaded":False}) node.play() return node
def testRawText(self): def createDynNodes(): self.dictdnode = avg.WordsNode(text='<test dyndict&', rawtextmode=True, pos=(1,65), font='Bitstream Vera Sans', variant='roman', fontsize=12) root.appendChild(self.dictdnode) self.xmldnode = player.createNode(""" <words text="<test dynattr&" fontsize="12" font="Bitstream Vera Sans" variant="roman" rawtextmode="true" x="1" y="85"/>""") root.appendChild(self.xmldnode) def switchRawMode(): self.dictdnode.rawtextmode = False valNode.rawtextmode = True attribNode.rawtextmode = True def bombIt(): def cantRun(): self.xmldnode.rawtextmode = False self.assert_(0) self.assertException(cantRun) def assignNewTexts(): text = u'&ùùààxx>' self.dictdnode.rawtextmode = True self.dictdnode.text = text self.xmldnode.text = text valNode.text = text attribNode.text = text root = self.loadEmptyScene() attribNode = avg.WordsNode(text="ùnicòdé <b>bold</b>", fontsize=12, pos=(1,5), font="Bitstream Vera Sans", parent=root) valNode = player.createNode(""" <words id="nodeval" fontsize="10" x="1" y="25" font="Bitstream Vera Sans"><b>bold</b> ùnicòdé <</words>""") root.appendChild(valNode) root.appendChild( player.createNode(""" <words x="1" y="45" fontsize="15" font="Bitstream Vera Sans"> & </words>""")) self.start(True, (lambda: self.compareImage("testRawText1"), createDynNodes, lambda: self.compareImage("testRawText2"), switchRawMode, lambda: self.compareImage("testRawText3"), bombIt, assignNewTexts, lambda: self.compareImage("testRawText4"), ))
def testDynamicMediaDir(self): def attachNode(): root.appendChild(imageNode1) root = self.loadEmptyScene() root.mediadir="testmediadir" imageNode1 = player.createNode("image", {"href": "rgb24-64x64a.png"}) imageNode2 = player.createNode("image", {"href": "rgb24-64x64a.png", "x":30}) root.appendChild(imageNode2) self.start(False, (lambda: self.compareImage("testDynamicMediaDir1"), attachNode, lambda: self.compareImage("testDynamicMediaDir2") ))
def testI18NWords(self): def changeUnicodeText(): words.text = "Arabic nonsense: ﯿﭗ" def setNBSP(): words.width=100 words.text=(u"blindtext1\u00A0blindtext2\u00Ablindtext3 "+ u"blindtext4\u00A0blindtext\u00A0blindtext\u00A0") root = self.loadEmptyScene() avg.WordsNode(pos=(1,1), fontsize=14, font="Bitstream Vera Sans", text="一二三四五六七八九", parent=root) words = avg.WordsNode(pos=(1,24), fontsize=12, font="Bitstream Vera Sans", text="foo", parent=root) root.appendChild( player.createNode(""" <words x="1" y="48" fontsize="12" font="Bitstream Vera Sans"> & </words> """)) avg.WordsNode(pos=(12,48), fontsize=12, font="Bitstream Vera Sans", text="&", rawtextmode=True, parent=root) self.start(True, (lambda: self.compareImage("testI18NWords1"), changeUnicodeText, lambda: self.compareImage("testI18NWords2"), setNBSP, lambda: self.compareImage("testI18NWords3"), ))
def testNodePythonAttribute(): node1 = player.createNode("image", {"id":"foo", "pos":(23, 42)}) root.appendChild(node1) node1.customAttribute = "bbb" node2 = player.getElementByID("foo") self.assertEqual(node1, node2) self.assertEqual(node2.customAttribute, "bbb") node1.unlink(True)
def newRect(): self.rect.unlink() self.rect = player.createNode( """<rect pos="(20, 20)" size="(50, 40)" fillopacity="1" filltexcoord1="(1,1)" filltexcoord2="(0,0)" texcoords="(0, 0.25, 0.5, 0.75, 1)" strokewidth="20" texhref="rgb24-64x64.png"/>""") canvas.appendChild(self.rect)
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")))
def createDynNodes(): self.dictdnode = avg.WordsNode(text='<test dyndict&', rawtextmode=True, pos=(1,65), font='Bitstream Vera Sans', variant='roman', fontsize=12) root.appendChild(self.dictdnode) self.xmldnode = player.createNode(""" <words text="<test dynattr&" fontsize="12" font="Bitstream Vera Sans" variant="roman" rawtextmode="true" x="1" y="85"/>""") root.appendChild(self.xmldnode)
def createDiv(useXml): if useXml: node = player.createNode(""" <div> <image href='rgb24-64x64.png'/> </div> """) else: node = avg.DivNode() avg.ImageNode(href="rgb24-64x64.png", parent=node) return node
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")))
def __addMessage(self, text): MsgsNode = player.getElementByID("cal_messages") if self.__NumMessages > 38: for i in range(0, MsgsNode.getNumChildren() - 1): MsgsNode.getChild(i).text = MsgsNode.getChild(i + 1).text MsgsNode.removeChild(MsgsNode.getNumChildren() - 1) else: self.__NumMessages += 1 Node = player.createNode("<words fontsize='10' font='Eurostile' color='00FF00'/>") Node.x = 0 Node.y = self.__NumMessages * 13 Node.text = text MsgsNode.appendChild(Node)
def __addMessage(self, text): MsgsNode = player.getElementByID("cal_messages") if self.__NumMessages > 38: for i in range(0, MsgsNode.getNumChildren() - 1): MsgsNode.getChild(i).text = MsgsNode.getChild(i + 1).text MsgsNode.removeChild(MsgsNode.getNumChildren() - 1) else: self.__NumMessages += 1 Node = player.createNode( "<words fontsize='10' font='Eurostile' color='00FF00'/>") Node.x = 0 Node.y = self.__NumMessages * 13 Node.text = text MsgsNode.appendChild(Node)
def createNodes(): def appendEventString (s): self.__eventString += s return True def setHandler (node, s, swallow = False): node.setEventHandler(avg.Event.CURSOR_DOWN, avg.Event.MOUSE, lambda e: appendEventString(s) and swallow) parentNode = root node = player.createNode("div", {'x':0,'y':0,'width':50, 'height':50}) setHandler (node, 'a') parentNode.appendChild(node) node = player.createNode("div", {'x':0,'y':0,'width':100, 'height':100}) setHandler (node, 'b') parentNode.insertChild(node,0) parentNode = node node = player.createNode("div", {'x':40,'y':40,'width':30, 'height':30}) setHandler (node, 'c') parentNode.appendChild(node) node = player.createNode("div", {'x':60,'y':40,'width':30, 'height':30}) setHandler (node, 'd', True) parentNode.appendChild(node)
def testI18NWords(self): def changeUnicodeText(): words.text = "Arabic nonsense: ﯿﭗ" def setNBSP(): words.width = 100 words.text = (u"blindtext1\u00A0blindtext2\u00Ablindtext3 " + u"blindtext4\u00A0blindtext\u00A0blindtext\u00A0") root = self.loadEmptyScene() avg.WordsNode(pos=(1, 1), fontsize=14, font="Bitstream Vera Sans", variant="Roman", text="一二三四五六七八九", parent=root) words = avg.WordsNode(pos=(1, 24), fontsize=12, font="Bitstream Vera Sans", variant="Roman", text="foo", parent=root) root.appendChild( player.createNode(""" <words x="1" y="48" fontsize="12" font="Bitstream Vera Sans" variant="Roman"> & </words> """)) avg.WordsNode(pos=(12, 48), fontsize=12, font="Bitstream Vera Sans", variant="Roman", text="&", rawtextmode=True, parent=root) self.start(True, ( lambda: self.compareImage("testI18NWords1"), changeUnicodeText, lambda: self.compareImage("testI18NWords2"), setNBSP, lambda: self.compareImage("testI18NWords3"), ))
def testSpanWords(self): def setTextAttrib(): self.baselineBmp = player.screenshot() player.getElementByID("words").text = self.text def checkSameImage(): bmp = player.screenshot() self.assert_(self.areSimilarBmps(bmp, self.baselineBmp, 0, 0)) def createUsingDict(): player.getElementByID("words").unlink() node = avg.WordsNode(id="words", pos=(1, 1), fontsize=12, width=120, font="Bitstream Vera Sans", variant="roman", text=self.text) root.appendChild(node) self.text = """ Markup: <span size='14000' rise='5000' foreground='red'>span</span>, <i>italics</i>, <b>bold</b> """ root = self.loadEmptyScene() node = player.createNode(""" <words id="words" x="1" y="1" fontsize="12" width="120" font="Bitstream Vera Sans" variant="roman"> """ + self.text + """ </words> """) root.appendChild(node) self.start(True, [ lambda: self.compareImage("testSpanWords"), setTextAttrib, lambda: self.compareImage("testSpanWords"), checkSameImage, createUsingDict, lambda: self.compareImage("testSpanWords"), checkSameImage, ])
def testSpanWords(self): def setTextAttrib(): self.baselineBmp = player.screenshot() player.getElementByID("words").text = self.text def checkSameImage(): bmp = player.screenshot() self.assert_(self.areSimilarBmps(bmp, self.baselineBmp, 0, 0)) def createUsingDict(): player.getElementByID("words").unlink() node = avg.WordsNode(id="words", pos=(1,1), fontsize=12, width=120, font="Bitstream Vera Sans", variant="roman", text=self.text) root.appendChild(node) self.text = """ Markup: <span size='14000' rise='5000' foreground='red'>span</span>, <i>italics</i>, <b>bold</b> """ root = self.loadEmptyScene() node = player.createNode(""" <words id="words" x="1" y="1" fontsize="12" width="120" font="Bitstream Vera Sans" variant="roman"> """ +self.text+ """ </words> """) root.appendChild(node) self.start(True, [lambda: self.compareImage("testSpanWords"), setTextAttrib, lambda: self.compareImage("testSpanWords"), checkSameImage, createUsingDict, lambda: self.compareImage("testSpanWords"), checkSameImage, ])
def createXmlNode(pos, size): return player.createNode( """<image pos="%s" size="%s" href="rgb24-64x64.png"/>""" % (str(pos), str(size)))
def createImg(): parentNode = root node = player.createNode("image", {"id": "img", "href":"rgb24-64x64.png"}) parentNode.appendChild(node) node.subscribe(avg.Node.CURSOR_DOWN, captureMouseDown) parentNode.subscribe(avg.Node.CURSOR_UP, mainMouseUp)
def testRawText(self): def createDynNodes(): self.dictdnode = avg.WordsNode(text='<test dyndict&', rawtextmode=True, pos=(1, 65), font='Bitstream Vera Sans', variant='roman', fontsize=12) root.appendChild(self.dictdnode) self.xmldnode = player.createNode(""" <words text="<test dynattr&" fontsize="12" font="Bitstream Vera Sans" variant="roman" rawtextmode="true" x="1" y="85"/>""") root.appendChild(self.xmldnode) def switchRawMode(): self.dictdnode.rawtextmode = False valNode.rawtextmode = True attribNode.rawtextmode = True def bombIt(): def cantRun(): self.xmldnode.rawtextmode = False self.assertRaises(avg.Exception, cantRun) def assignNewTexts(): text = u'&ùùààxx>' self.dictdnode.rawtextmode = True self.dictdnode.text = text self.xmldnode.text = text valNode.text = text attribNode.text = text root = self.loadEmptyScene() attribNode = avg.WordsNode(text="ùnicòdé <b>bold</b>", fontsize=12, pos=(1, 5), font="Bitstream Vera Sans", variant="Roman", parent=root) valNode = player.createNode(""" <words id="nodeval" fontsize="10" x="1" y="25" font="Bitstream Vera Sans" variant="Roman"><b>bold</b> ùnicòdé <</words>""" ) root.appendChild(valNode) root.appendChild( player.createNode(""" <words x="1" y="45" fontsize="15" font="Bitstream Vera Sans" variant="Roman"> & </words>""")) self.start(True, ( lambda: self.compareImage("testRawText1"), createDynNodes, lambda: self.compareImage("testRawText2"), switchRawMode, lambda: self.compareImage("testRawText3"), bombIt, assignNewTexts, lambda: self.compareImage("testRawText4"), ))
def addLine(attribs): line = player.createNode("line", attribs) canvas.appendChild(line)
def addPolyLine2(): polyline2 = player.createNode( """<polyline strokewidth="2" color="FF00FF" pos="((110,10), (100,50), (110,70))" />""") canvas.insertChild(polyline2,0)
def createImg(useXml): if useXml: node = player.createNode("<image href='rgb24-64x64.png'/>") else: node = player.createNode("image", {"href":"rgb24-64x64.png"}) return node
def __init__(self, parentNode, cameraType = "FireFly", appStarter=None): super(Calibrator, self).__init__(parentNode) self.paramList = camera_setup(cameraType) self.parentNode = parentNode self.appStarter = appStarter self.mainNode = player.createNode( """ <div active = "False" opacity = "0"> <image width = "1280" height = "800" href = "black.png"/> <image id = "cal_distorted" x = "0" y = "0" width = "1280" height = "800" sensitive = "false" opacity = "1"/> <words id = "cal_fps" x = "30" y = "30" color = "00FF00" text = ""/> <words id = "cal_notification" x = "390" y = "390" width = "500" fontsize = "18" color = "ff3333" alignment = "center" /> <div id = "cal_gui" x = "30" y = "540"> <image id = "cal_shadow" x = "0" y = "13" width = "500" height = "150" href = "black.png" opacity = "0.6"/> <words x = "2" y = "13" text = "camera" fontsize = "16" color = "00FF00"/> <image x = "2" y = "32" href = "CamImgBorder.png"/> <image id = "cal_camera" x = "4" y = "34" width = "160" height = "120"/> <words x = "168" y = "13" text = "nohistory" fontsize = "16" color = "00FF00"/> <image x = "168" y = "32" href = "CamImgBorder.png"/> <image id = "cal_nohistory" x = "170" y = "34" width = "160" height = "120"/> <words x = "334" y = "13" text = "histogram" fontsize = "16" color = "00FF00"/> <image x = "334" y = "32" href = "CamImgBorder.png"/> <image id = "cal_histogram" x = "336" y = "34" width = "160" height = "120"/> <div id = "cal_params" y = "170" opacity = "0.9"> <image id = "cal_shadow2" width = "750" height = "65" href = "black.png" opacity = "0.6"/> <div id = "cal_paramdiv0" x = "2"> <words text = "camera" y = "0" fontsize = "10" color = "00ff00" /> <words id = "cal_param0" y = "12" fontsize = "10"/> <words id = "cal_param1" y = "24" fontsize = "10"/> <words id = "cal_param2" y = "36" fontsize = "10"/> <words id = "cal_param3" y = "48" fontsize = "10"/> </div> <div id = "cal_paramdiv1" x = "80"> <words text = "touch" y = "0" fontsize = "10" color = "00ff00" /> <words id = "cal_param4" y = "12" fontsize = "10"/> <words id = "cal_param5" y = "24" fontsize = "10"/> <words id = "cal_param6" y = "36" fontsize = "10"/> <words id = "cal_param7" y = "48" fontsize = "10"/> </div> <div id = "cal_paramdiv2" x = "200"> <words id = "cal_param8" y = "0" fontsize = "10"/> <words id = "cal_param9" y = "12" fontsize = "10"/> <words id = "cal_param10" y = "24" fontsize = "10"/> <words id = "cal_param11" y = "36" fontsize = "10"/> <words id = "cal_param12" y = "48" fontsize = "10"/> </div> <div id = "cal_paramdiv3" x = "350"> <words text = "track" y = "0" fontsize = "10" color = "00ff00" /> <words id = "cal_param13" y = "12" fontsize = "10"/> <words id = "cal_param14" y = "24" fontsize = "10"/> <words id = "cal_param15" y = "36" fontsize = "10"/> <words id = "cal_param16" y = "48" fontsize = "10"/> </div> <div id = "cal_paramdiv4" x = "500"> <words id = "cal_param17" y = "0" fontsize = "10"/> <words text = "distort" y = "12" fontsize = "10" color = "00ff00"/> <words id = "cal_param18" y = "24" fontsize = "10"/> <words id = "cal_param19" y = "36" fontsize = "10"/> <words id = "cal_param20" y = "48" fontsize = "10"/> </div> <div id = "cal_paramdiv5" x = "650"> <words id = "cal_param21" y = "0" fontsize = "10"/> <words id = "cal_param22" y = "12" fontsize = "10"/> <words id = "cal_param23" y = "24" fontsize = "10"/> <words id = "cal_param24" y = "36" fontsize = "10"/> <words id = "cal_param25" y = "48" fontsize = "10"/> </div> </div> </div> <div id = "cal_coordcalibrator" opacity = "0" active = "false"> <image x = "0" y = "0" width = "1280" height = "800" href = "border.png"/> <div id = "cal_messages" x = "100" y = "100"/> <image id = "cal_crosshair" href = "crosshair.png"/> <image id = "cal_feedback" href = "Feedback.png"/> </div> </div> """) self.mainNode.mediadir = mediadir parentNode.insertChild(self.mainNode, 0) self.coordCal = None self.tracker = player.getTracker() self.curParam = 0 self.saveIndex = 0 self.hideMainNodeTimeout = None self.video = [] self.__guiOpacity = 1 self.__showBigCamImage = False self.__notificationTimer = None self.__onCalibrationSuccess = None
def createXmlNode(pos): node = player.createNode( """<image pos="%s" href="rgb24-32x32.png"/>"""%str(pos)) self.assertEqual(node.getMediaSize(), avg.Point2D(32, 32)) return node
def createXmlNode(pos): return player.createNode( """<image pos="%s" href="rgb24-32x32.png"/>"""%str(pos))
def createImagePreviewNode(maxSize, absHref): node = player.createNode("image", {"href": absHref}) node.size = mathutil.getScaledDim(node.size, max=maxSize) return node
def createXmlNode(pos, size): return player.createNode( """<image pos="%s" size="%s" href="rgb24-64x64.png"/>""" %(str(pos), str(size)))
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") ))
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.mpg" 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") ))
def __init__(self, parentNode, CameraType = "FireFly", appStarter = None): super(Calibrator, self).__init__(parentNode) self.paramList = camera_setup(CameraType) self.parentNode=parentNode self.appStarter = appStarter self.mainNode = player.createNode( """ <div active="False" opacity="0"> <image width="1280" height="800" href="black.png"/> <image id="cal_distorted" x="0" y="0" width="1280" height="800" sensitive="false" opacity="1"/> <words id="cal_fps" x="30" y="30" color="00FF00" text=""/> <words id="cal_notification" x="390" y="390" width="500" fontsize="18" color="ff3333" alignment="center" /> <div id="cal_gui" x="30" y="540"> <image id="cal_shadow" x="0" y="13" width="500" height="150" href="black.png" opacity="0.6"/> <words x="2" y="13" text="camera" fontsize="16" color="00FF00"/> <image x="2" y="32" href="CamImgBorder.png"/> <image id="cal_camera" x="4" y="34" width="160" height="120"/> <words x="168" y="13" text="nohistory" fontsize="16" color="00FF00"/> <image x="168" y="32" href="CamImgBorder.png"/> <image id="cal_nohistory" x="170" y="34" width="160" height="120"/> <words x="334" y="13" text="histogram" fontsize="16" color="00FF00"/> <image x="334" y="32" href="CamImgBorder.png"/> <image id="cal_histogram" x="336" y="34" width="160" height="120"/> <div id="cal_params" y="170" opacity="0.9"> <image id="cal_shadow2" width="750" height="65" href="black.png" opacity="0.6"/> <div id="cal_paramdiv0" x="2"> <words text="camera" y="0" fontsize="10" color="00ff00" /> <words id="cal_param0" y="12" fontsize="10"/> <words id="cal_param1" y="24" fontsize="10"/> <words id="cal_param2" y="36" fontsize="10"/> <words id="cal_param3" y="48" fontsize="10"/> </div> <div id="cal_paramdiv1" x="80"> <words text="touch" y="0" fontsize="10" color="00ff00" /> <words id="cal_param4" y="12" fontsize="10"/> <words id="cal_param5" y="24" fontsize="10"/> <words id="cal_param6" y="36" fontsize="10"/> <words id="cal_param7" y="48" fontsize="10"/> </div> <div id="cal_paramdiv2" x="200"> <words id="cal_param8" y="0" fontsize="10"/> <words id="cal_param9" y="12" fontsize="10"/> <words id="cal_param10" y="24" fontsize="10"/> <words id="cal_param11" y="36" fontsize="10"/> <words id="cal_param12" y="48" fontsize="10"/> </div> <div id="cal_paramdiv3" x="350"> <words text="track" y="0" fontsize="10" color="00ff00" /> <words id="cal_param13" y="12" fontsize="10"/> <words id="cal_param14" y="24" fontsize="10"/> <words id="cal_param15" y="36" fontsize="10"/> <words id="cal_param16" y="48" fontsize="10"/> </div> <div id="cal_paramdiv4" x="500"> <words id="cal_param17" y="0" fontsize="10"/> <words text="distort" y="12" fontsize="10" color="00ff00"/> <words id="cal_param18" y="24" fontsize="10"/> <words id="cal_param19" y="36" fontsize="10"/> <words id="cal_param20" y="48" fontsize="10"/> </div> <div id="cal_paramdiv5" x="650"> <words id="cal_param21" y="0" fontsize="10"/> <words id="cal_param22" y="12" fontsize="10"/> <words id="cal_param23" y="24" fontsize="10"/> <words id="cal_param24" y="36" fontsize="10"/> <words id="cal_param25" y="48" fontsize="10"/> </div> </div> </div> <div id="cal_coordcalibrator" opacity="0" active="false"> <image x="0" y="0" width="1280" height="800" href="border.png"/> <div id="cal_messages" x="100" y="100"/> <image id="cal_crosshair" href="crosshair.png"/> <image id="cal_feedback" href="Feedback.png"/> </div> </div> """) self.mainNode.mediadir=mediadir parentNode.insertChild(self.mainNode, 0) self.coordCal = None self.tracker = player.getTracker() self.curParam = 0 self.saveIndex = 0 self.hideMainNodeTimeout = None self.video = [] self.__guiOpacity = 1 self.__showBigCamImage = False self.__notificationTimer = None self.__onCalibrationSuccess = None
def createImagePreviewNode(maxSize, absHref): node = player.createNode('image', {'href': absHref}) node.size = mathutil.getScaledDim(node.size, max=maxSize) return node
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)
def createXmlNode(pos): node = player.createNode( """<image pos="%s" href="rgb24-32x32.png"/>""" % str(pos)) self.assertEqual(node.getMediaSize(), avg.Point2D(32, 32)) return node
def createXmlNode(pos): return player.createNode( """<image pos="%s" href="rgb24-32x32.png"/>""" % str(pos))
def usePlugin2(): node = player.createNode('<colornode fillcolor="0f3f7f" id="mynode2" />') root.appendChild(node) mynode = player.getElementByID("mynode2") self.assertEqual(mynode.fillcolor, "0f3f7f")
sys.exit(1) else: fontname=sys.argv[1] if len(sys.argv) > 2: displayText=sys.argv[2] else: displayText="" variants = avg.WordsNode.getFontVariants(fontname) print variants rootNode = player.getRootNode() y = 10 for variant in variants: if displayText == "": text = fontname+": "+variant else: text = displayText node = player.createNode("words", { "text": text, "font": fontname, "variant": variant, "fontsize": 24, "x": 10, "y": y }) rootNode.appendChild(node) y += 50 player.setVBlankFramerate(1) player.play()