Best Python code snippet using Airtest
matrix0.py
Source:matrix0.py
1""" matrix0.py sample """2import sys3import pygame4from pygame.locals import QUIT, KEYDOWN, K_0, K_95pygame.init()6SURFACE = pygame.display.set_mode([400, 150])7FPSCLOCK = pygame.time.Clock()8class Box:9 "number input field"10 myfont = pygame.font.SysFont(None, 40)11 bitmaps = []12 for num in range(100):13 bitmaps.append(myfont.render(str(num), True, (64, 64, 64)))14 def __init__(self, pos, value, is_focused):15 self.is_focused = is_focused16 self.number = value17 self.number_rect = self.bitmaps[value].get_rect(center=pos)18 self.focus_rect = self.number_rect.copy()19 self.focus_rect.inflate_ip(10, 0)20 def draw(self):21 """ draw number and focus """22 if self.number > 99:23 return24 SURFACE.blit(self.bitmaps[self.number], self.number_rect)25 if self.is_focused:26 pygame.draw.rect(SURFACE, (0, 0, 225),27 self.focus_rect, 2)28def main():29 """ main routine """30 font = pygame.font.SysFont(None, 60)31 mess_cross = font.render("x", True, (0, 0, 0))32 mess_equal = font.render("=", True, (0, 0, 0))33 focus_index = 034 positions = (35 (50, 50, 1), (100, 50, 2), (50, 100, 3), (100, 100, 4),36 (170, 50, 1), (220, 50, 0), (170, 100, 0), (220, 100, 1),37 (300, 50, 1), (350, 50, 2), (300, 100, 3), (350, 100, 4))38 boxes = []39 for pos in positions:40 boxes.append(Box((pos[0], pos[1]), pos[2], False))41 while True:42 for event in pygame.event.get():43 if event.type == QUIT:44 pygame.quit()45 sys.exit()46 elif event.type == KEYDOWN and K_0 <= event.key <= K_9:47 boxes[focus_index].number = event.key - K_048 focus_index = (focus_index + 1) % 849 for index in range(8):50 boxes[index].is_focused = True \51 if index == focus_index else False52 val0 = boxes[0].number * boxes[4].number \53 + boxes[1].number * boxes[6].number54 val1 = boxes[0].number * boxes[5].number \55 + boxes[1].number * boxes[7].number56 val2 = boxes[2].number * boxes[4].number \57 + boxes[3].number * boxes[6].number58 val3 = boxes[2].number * boxes[5].number \59 + boxes[3].number * boxes[7].number60 boxes[8].number = val061 boxes[9].number = val162 boxes[10].number = val263 boxes[11].number = val364 # Paint65 SURFACE.fill((255, 255, 255))66 for box in boxes:67 box.draw()68 SURFACE.blit(mess_cross, (125, 50))69 SURFACE.blit(mess_equal, (250, 50))70 pygame.display.update()71 FPSCLOCK.tick(10)72if __name__ == '__main__':...
ScrollScene.py
Source:ScrollScene.py
...38 self.offset.x += self.focus.rect.right - self.focus_rect.rect.left39 #Bottom of focus_rect40 if self.focus.rect.top >= self.focus_rect.rect.bottom:41 self.offset.y += self.focus.rect.top - self.focus_rect.rect.bottom42 def update_focus_rect(self):43 self.focus_rect.rect.topleft = (44 self.display_width * (1 - self.focus_size)/2 + self.offset.x,45 self.display_height * (1 - self.focus_size)/2 + self.offset.y46 )47 def render(self):48 self.find_offset()49 self.update_focus_rect()50 51 52 self.display_surf.fill((colors.white))53 for entity in self.all_sprites:54 #create a surf and rect by adding the screen location to the entity surf and rect, then blit the new surf and rect to the screen55 self.display_surf.blit(entity.surf, (entity.rect.left - self.offset.x, entity.rect.top - self.offset.y))56# find the difference between focus pos and focus_rect57# blit sprites using a for loop with their pos's offset by offset58# keep a running tally on offset...
camera.py
Source:camera.py
...10 copy_rect = rect.copy()11 copy_rect.x -= self.focus_rect.centerx - self.x / 212 copy_rect.y -= self.focus_rect.centery - self.y / 213 return copy_rect14 def change_focus_rect(self, new_focus_rect):15 self.focus_rect = new_focus_rect16class GroupWithCamera(Camera, pygame.sprite.LayeredUpdates):17 def __init__(self, focus_rect, surface_x, surface_y, *args, **kwargs):18 pygame.sprite.LayeredUpdates.__init__(self, *args, **kwargs)19 Camera.__init__(self, focus_rect, surface_x, surface_y)20 def draw(self, surface: pygame.Surface) -> None:21 for i in self.sprites():...
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!!