Best Python code snippet using fMBT_python
AnimatorView.py
Source:AnimatorView.py
...161 def setTargetAnimator( self, target ):162 self.saveAnimatorData()163 if target == self.targetAnimator: return164 if self.previewing:165 self.stopPreview()166 self.targetAnimator = target167 self.targetClip = None168 self.delegate.callMethod( 'view', 'setTargetAnimator', target )169 self.targetAnimatorData = self.delegate.callMethod( 'view', 'getTargetAnimatorData' )170 self.widget.rebuild()171 if self.targetAnimator:172 self.setEditing( True )173 signals.emit( 'animator.start' )174 else:175 self.setEditing( False )176 signals.emit( 'animator.stop' )177 178 path = self.delegate.callMethod( 'view', 'getTargetAnimatorDataPath' )179 if path:180 self.window.setWindowTitle( 'Animator - %s' % path )181 else:182 self.window.setWindowTitle( 'Animator' )183 clip = self.delegate.callMethod( 'view', 'getPreviousTargeClip', target )184 self.enableTool( 'animator_play' , False )185 self.enableTool( 'animator_track', False )186 if clip:187 self.widget.treeClips.selectNode( clip )188 else:189 self.widget.treeClips.selectFirstItem()190 self.applyTime( 0, True )191 def setTargetClip( self, clip ):192 wasPreviewing = self.previewing193 if self.previewing:194 self.stopPreview()195 self.targetClip = clip196 self.delegate.callMethod( 'view', 'setTargetClip', clip )197 self.widget.rebuildTimeline()198 self.widget.rebuildClipTree()199 self.enableTool( 'animator_play' , bool( clip ) )200 self.enableTool( 'animator_track', bool( clip ) )201 self.applyTime( 0, True )202 if wasPreviewing:203 self.startPreview()204 def setCurrentTrack( self, track ):205 self.currentTrack = track206 self.delegate.callMethod( 'view', 'setCurrentTrack', track )207 def getTargetClipLength( self ):208 return self.delegate.callMethod( 'view', 'getTargetClipLength' )209 def getClipList( self ):210 if self.targetAnimatorData:211 clipList = self.targetAnimatorData.clips212 return [ clip for clip in list(clipList.values()) ]213 else:214 return []215 def getRootClipGroup( self ):216 if self.targetAnimatorData:217 return self.targetAnimatorData.getRootGroup( self.targetAnimatorData )218 def getTrackList( self ):219 if self.targetClip:220 trackList = self.targetClip.getTrackList( self.targetClip )221 return [ track for track in list(trackList.values()) ]222 else:223 return []224 def getMarkerList( self ):225 if self.targetClip:226 markerList = self.targetClip.getMarkerList( self.targetClip )227 return [ track for track in list(markerList.values()) ]228 else:229 return []230 def getClipRoot( self ):231 if self.targetClip:232 return self.targetClip.getRoot( self.targetClip )233 else:234 return None235 def getClipTreeRoot( self ):236 if self.targetClip and isMockInstance( self.targetClip, 'AnimatorClipTree' ):237 return self.targetClip.getTreeRoot( self.targetClip )238 def addClip( self ):239 if not self.targetAnimatorData: return240 targetGroup = self.widget.getCurrentClipGroup()241 cmd = self.doCommand( 'scene_editor/animator_add_clip',242 animator_data = self.targetAnimatorData,243 parent_group = targetGroup244 )245 clip = cmd.getResult()246 clip.setFixedLength( clip, 3 ) 247 if clip:248 self.widget.addClip( clip, True )249 return clip250 def addClipTree( self ):251 if not self.targetAnimatorData: return252 targetGroup = self.widget.getCurrentClipGroup()253 cmd = self.doCommand( 'scene_editor/animator_add_clip_tree',254 animator_data = self.targetAnimatorData,255 parent_group = targetGroup256 )257 clip = cmd.getResult()258 if clip:259 self.widget.addClip( clip, True )260 return clip261 def addClipGroup( self ):262 if not self.targetAnimatorData: return263 targetGroup = self.widget.getCurrentClipGroup()264 cmd = self.doCommand( 'scene_editor/animator_add_clip_group',265 animator_data = self.targetAnimatorData,266 parent_group = targetGroup267 )268 group = cmd.getResult()269 if group:270 self.widget.addClip( group, True )271 return group272 def removeClipNode( self ):273 for clip in self.widget.treeClips.getSelection():274 if self.doCommand( 'scene_editor/animator_remove_clip_node',275 animator_data = self.targetAnimatorData,276 target_node = clip277 ):278 self.widget.removeClip( clip )279 def cloneClipNode( self ):280 if not self.targetClip: return281 result = []282 for clip in self.widget.treeClips.getSelection():283 cmd = self.doCommand( 'scene_editor/animator_clone_clip_node',284 animator_data = self.targetAnimatorData,285 target_node = clip286 )287 if cmd:288 cloned = cmd.getResult()289 self.widget.addClip( cloned, True )290 result.append( cloned )291 return result292 def onObjectEdited( self, obj ):293 if self.targetClip:294 self.delegate.callMethod( 'view', 'clearPreviewState' )295 self.delegate.callMethod( 'view', 'markClipDirty' )296 self.refreshPreview()297 def onSceneSelectionChanged( self, selection, key ):298 if key != 'scene': return299 #find animator component300 # self.findTargetAnimator()301 def findTargetAnimator( self ):302 target = self.delegate.callMethod( 'view', 'findTargetAnimator' )303 self.setTargetAnimator( target )304 return target305 def checkTargetAnimator( self ):306 if not self.targetAnimator:307 alertMessage( 'No Animator', 'No Animator Selected', 'question' )308 return False309 return True310 def addMarker( self ):311 if not self.targetClip: return312 cmd = self.doCommand( 'scene_editor/animator_add_marker' ,313 target_clip = self.targetClip,314 target_pos = self.widget.getCursorPos()315 )316 if cmd:317 marker = cmd.getResult()318 self.widget.addMarker( marker )319 def addKeyForField( self, target, fieldId ):320 if not self.checkTargetAnimator(): return 321 if not self.targetClip:322 self.addClip()323 # alertMessage( 'No Clip', 'You need to select a Clip first', 'question' )324 # return False325 keys = self.delegate.callMethod( 'view', 'addKeyForField', target, fieldId )326 if keys:327 for key in list(keys.values()):328 self.widget.addKey( key, True )329 def addKeyForEvent( self, target, eventId ):330 pass331 def addCustomAnimatorTrack( self, target, trackClasId ):332 if not self.checkTargetAnimator(): return333 334 track = self.delegate.callMethod( 'view', 'addCustomAnimatorTrack', target, trackClasId )335 if track:336 self.widget.addTrack( track )337 def addKeyForSelectedTracks( self ):338 #TODO: command339 selectedTracks = self.widget.getTrackSelection()340 for track in selectedTracks:341 keys = self.delegate.callMethod( 'view', 'addKeyForSelectedTrack', track )342 if keys:343 for key in list(keys.values()):344 self.widget.addKey( key, True )345 def removeSelectedKeys( self ):346 #TODO: command347 selectedKeys = self.widget.getKeySelection()348 for key in selectedKeys:349 self.widget.removeKey( key )350 def cloneSelectedKeys( self ):351 #TODO: command352 selectedKeys = self.widget.getKeySelection()353 cloned = []354 for key in selectedKeys:355 clonedKey = self.delegate.callMethod( 'view', 'cloneKey', key )356 if clonedKey:357 cloned.append( clonedKey )358 for clonedKey in cloned:359 keyItem = self.widget.addKey( clonedKey, False )360 keyItem.fitIntoNextEmptySpan()361 def onKeyRemoving( self, key ):362 if self.delegate.callMethod( 'view', 'removeKey', key ) != False:363 self.refreshPreview()364 return True365 def onMarkerRemoving( self, marker ):366 if self.delegate.callMethod( 'view', 'removeMarker', marker ) != False:367 return True368 def onClipLengthChanging( self, t1 ):369 if self.delegate.callMethod( 'view', 'setTargetClipLength', t1 ) != False:370 self.refreshPreview()371 return True372 def onTimelineKeyChanged( self, key, pos, length ):373 self.delegate.callMethod( 'view', 'updateTimelineKey', key, pos, length )374 self.refreshPreview()375 def onTimelineKeyCurveValueChanged( self, key, value ):376 self.delegate.callMethod( 'view', 'updateTimelineKeyCurveValue', key, value )377 self.refreshPreview()378 def onTimelineKeyTweenModeChanged( self, key, mode ):379 self.delegate.callMethod( 'view', 'updateTimelineKeyTweenMode', key, mode )380 self.refreshPreview()381 def onTimelineKeyBezierPointChanged( self, key, bpx0, bpy0, bpx1, bpy1 ):382 self.delegate.callMethod( 'view', 'updateTimelineKeyBezierPoint', key, bpx0, bpy0, bpx1, bpy1 )383 self.refreshPreview()384 def onTimelineMarkerChanged( self, marker, pos ):385 self.delegate.callMethod( 'view', 'updateTimelineMarker', marker, pos )386 def toggleTrackActive( self, track ):387 #TODO: command388 # self.module.doCommand( 'scene_editor/toggle_entity_visibility', target = node )389 self.delegate.callMethod( 'view', 'toggleTrackActive', track )390 self.refreshPreview()391 self.refreshPreview()392 393 def renameTrack( self, track, name ):394 self.delegate.callMethod( 'view', 'renameTrack', track, name )395 def renameClip( self, clip, name ):396 self.delegate.callMethod( 'view', 'renameClip', clip, name )397 def createClipTreeNode( self, nodeTypeName ):398 if not self.targetClip: return None399 contextNode = self.widget.treeClipTree.getFirstSelection()400 cmd = self.doCommand( 'scene_editor/animator_add_clip_tree_node',401 context_node = contextNode,402 parent_tree = self.targetClip,403 node_type = nodeTypeName404 )405 node = cmd.getResult()406 if node:407 self.widget.addClipTreeNode( node, True )408 return node409 def listClipTreeNodeTypes( self, typeId, context, option ):410 contextNode = self.widget.treeClipTree.getFirstSelection()411 parentTree = self.targetClip412 if not contextNode:413 contextNode = parentTree.getTreeRoot( parentTree )414 res = _MOCK_EDIT.requestAvailAnimatorClipTreeNodeTypes( contextNode )415 entries = []416 for n in list(res.values()):417 entry = ( n, n, 'AnimatorClipTreeNode', 'animator_clip_tree/'+n )418 entries.append( entry )419 return entries420 def retargetTrack( self, entity ):421 for track in self.widget.treeTracks.getSelection():422 cmd = self.doCommand( 423 'scene_editor/animator_retarget_track', 424 target_track = track,425 target_entity = entity,426 animator = self.targetAnimator427 )428 self.widget.treeTracks.refreshNodeContent( track )429 self.delegate.callMethod( 'view', 'clearPreviewState' )430 self.delegate.callMethod( 'view', 'markClipDirty' )431 self.refreshPreview()432 def selectAnimatorEntity( self, com ):433 entity = com._entity434 if not entity: return435 self.changeSelection( entity )436 self.findTargetAnimator()437 def openTargetContextMenu( self ):438 menu = QtWidgets.QMenu( "Animator Target Context" )439 itemAddKey = menu.addAction( 'Relocate Targets' )440 itemAddKey.triggered.connect( self.onRelocateTargets )441 menu.exec_(QtGui.QCursor.pos())442 def onRelocateTargets( self ):443 if not self.targetAnimator: return444 self.delegate.callMethod( 'view', 'relocateTargets' )445 def onTool( self, tool ):446 name = tool.name447 if name == 'find_animator':448 requestSearchView( 449 context = 'scene',450 type = _MOCK.Animator,451 on_selection = self.selectAnimatorEntity452 )453 elif name == 'change_animator':454 target0 = self.targetAnimator455 target1 = self.findTargetAnimator()456 if ( not target0 ) and ( not target1 ):457 alertMessage( 'No Animator', 'No Animator found in selected entity scope', 'question' )458 459 elif name == 'save_data':460 self.saveAnimatorData()461 elif name == 'extra':462 self.openTargetContextMenu()463 elif name == 'add_clip':464 if self.checkTargetAnimator():465 self.addClip()466 elif name == 'add_clip_tree':467 if self.checkTargetAnimator():468 self.addClipTree()469 elif name == 'add_clip_group':470 if self.checkTargetAnimator():471 self.addClipGroup()472 elif name == 'remove_clip':473 if self.checkTargetAnimator():474 self.removeClipNode() 475 elif name == 'clone_clip':476 if self.checkTargetAnimator():477 self.cloneClipNode() 478 elif name == 'add_track_group':479 group = self.delegate.callMethod( 'view', 'addTrackGroup' )480 if group:481 self.widget.addTrack( group, True )482 elif name == 'remove_track':483 for track in self.widget.treeTracks.getSelection():484 self.delegate.callMethod( 'view', 'removeTrack', track )485 self.widget.removeTrack( track )486 self.refreshPreview()487 elif name == 'fold_tracks':488 self.widget.treeTracks.foldAllItems()489 elif name == 'unfold_tracks':490 self.widget.treeTracks.expandAllItems()491 elif name == 'locate_target':492 for track in self.widget.treeTracks.getSelection():493 sceneGraphEditor = self.getModule( 'scenegraph_editor')494 if sceneGraphEditor:495 targetEntity = self.delegate.callMethod( 'view', 'findTrackEntity', track )496 if targetEntity:497 sceneGraphEditor.selectEntity( targetEntity, focus_tree = True )498 #pass499 return500 elif name == 'retarget':501 requestSearchView( 502 info = 'retarget animator track to...',503 context = 'scene',504 type = 'entity',505 multiple_selection = False,506 on_selection = self.retargetTrack,507 )508 elif name == 'add_clip_tree_node':509 requestSearchView( 510 info = 'adding AnimatorClipTree node...',511 context = 'clip_tree_node',512 type = None,513 multiple_selection = False,514 on_selection = self.createClipTreeNode,515 on_search = self.listClipTreeNodeTypes516 )517 elif name == 'remove_clip_tree_node':518 for node in self.widget.treeClipTree.getSelection():519 if node.isVirtual( node ): continue520 self.doCommand( 'scene_editor/animator_remove_clip_tree_node', target_node = node )521 self.widget.rebuildClipTree()522 self.refreshPreview()523 #preview524 elif name == 'goto_start':525 self.gotoStart()526 elif name == 'goto_end':527 self.gotoEnd()528 elif name == 'play':529 if tool.getValue():530 self.startPreview()531 else:532 self.stopPreview( False )533 elif name == 'stop':534 self.stopPreview( True )535 elif name == 'play_tree':536 if tool.getValue():537 self.startPreview()538 else:539 self.stopPreview( False )540 elif name == 'stop_tree':541 self.stopPreview( True )542 elif name == 'toggle_repeat':543 self.delegate.callMethod( 'view', 'togglePreviewRepeat', tool.getValue() )544 545 def getActiveSceneView( self ):546 return self.getModule( 'scene_view' )547 #preview548 def togglePreview( self ):549 if self.previewing:550 self.stopPreview()551 else:552 self.startPreview()553 def restartPreview( self ):554 self.stopPreview( True )555 self.startPreview()556 557 def resetPreview( self ):558 self.stopPreview( True )559 def startPreview( self ):560 # self.saveAnimatorData() #WHY??????561 if self.delegate.callMethod( 'view', 'startPreview', self.previewTime ):562 self.widget.setCursorMovable( False )563 self.previewing = True564 self.findTool( 'animator_play/play' ).setValue( True )565 self.findTool( 'animator_clip_tree/play_tree' ).setValue( True )566 self.previewTimer.start()567 self.getApp().setMinimalMainLoopBudget()568 569 def stopPreview( self, rewind = False ): 570 if self.previewing:571 self.delegate.callMethod( 'view', 'stopPreview' )572 self.getApp().resetMainLoopBudget()573 self.widget.setCursorMovable( True )574 self.previewing = False575 self.findTool( 'animator_play/play' ).setValue( False )576 self.findTool( 'animator_clip_tree/play_tree' ).setValue( False )577 self.previewTimer.stop()578 signals.emit( 'entity.modified', None , '' )579 if rewind:580 self.gotoStart()581 def onPreviewTimer( self ):582 playing, currentTime = self.delegate.callMethod( 'view', 'doPreviewStep' )583 self.previewTime = currentTime584 self.getActiveSceneView().forceUpdate()585 self.widget.setCursorPos( self.previewTime )586 if not playing:587 self.stopPreview()588 def gotoStart( self ):589 if self.previewing:590 self.delegate.callMethod( 'view', 'applyTime', 0 )591 else:592 self.widget.setCursorPos( 0, True )593 def gotoEnd( self ):594 if self.previewing:595 self.delegate.callMethod( 'view', 'applyTime', 10 )596 else:597 self.widget.setCursorPos( 10, True )598 def applyTime( self, t, syncCursor = False ):599 self.previewTime = self.delegate.callMethod( 'view', 'applyTime', t )600 # self.getActiveSceneView().scheduleUpdate()601 self.getActiveSceneView().forceUpdate()...
polypServer.py
Source:polypServer.py
...19 self.active = False20 self.camera = None21 def __delete__(self):22 if self.preview :23 self.stopPreview()24 if self.active :25 self.stopCamera()26 def service(self):27 return json.jsonify(name="PolyphemusServer", version="0.1.1", copyright="Glyphstone Productions (c)2015")28 def initCamera(self):29 self.camera = picamera.PiCamera()30 self.camera.resolution = (1024,768)31 self.camera.framerate = 3032 self.camera.rotation = 18033 self.active = True34 def stopCamera(self) :35 self.camera.close()36 self.active = False37 def startPreview(self):38 if self.active == False :39 self.initCamera()40 self.camera.start_preview()41 self.preview = True42 time.sleep(2)43 return json.jsonify(camera="Active", preview=True)44 def stopPreview(self):45 self.camera.stop_preview()46 self.preview = False47 return json.jsonify(camera="Active", preview=False)48 def getPicture(self):49 if( self.active == False ) :50 self.startPreview()51 self.camera.capture("snap.png", use_video_port=True)52 return send_file("snap.png")53# =======================================================================54app = PolypServer("polypserver1")55@app.route('/')56def service():57 return app.service()58@app.route('/camera/on')59def camactive():60 return app.startPreview()61@app.route('/camera/off')62def camdeactive():63 return app.stopPreview()64@app.route('/camera/get')65def camsnap():66 return app.getPicture()67if __name__ == "__main__":...
Vision.py
Source:Vision.py
...18 return19 def preview(self):20 self.camera.start_preview(fullscreen=False, window=(10, 24, 640, 480))21 return22 def stopPreview(self):23 self.camera.stop_preview()24 return25 def capture(self, path):26 if path == -1 and self.path == "":27 print("must set path first.")28 return29 else:30 dateNow = str(datetime.date.today())31 timeNow = str(datetime.datetime.now().strftime("%H:%M:%S"))32 fileName = dateNow + "_" + timeNow33 if path == -1:34 self.camera.capture(self.path + "/" + fileName + ".jpg")35 else:36 self.assertDirectory(path)37 self.camera.capture(path + "/" + fileName + ".jpg")38 return39class FaceDetector:40 def __init__(self, faceCascadePath):41 self.faceCascade = cv2.CascadeClassifier(faceCascadePath)42 43 def detect(self, image, scaleFactor =1.1, minNeighbors=5, minSize=(30,30)):44 rects = self.faceCascade.detectMultiScale(image, scaleFactor=scaleFactor, minNeighbors=minNeighbors, minSize=minSize, flags=cv2.CASCADE_SCALE_IMAGE)45 return rects46 def test(self):47 print("yes")48##v = Vision()49##v.detectFaces()50##v.preview()51##sleep(2)52##v.capture(-1)53##sleep(3)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!