Best Python code snippet using robotframework-androidlibrary_python
step0.py
Source:step0.py  
...72      >>> def swipe_down(board):73      ...     calls.append('swipe_down')74      >>> def swipe_right(board):75      ...     calls.append('swipe_right')76      >>> def swipe_left(board):77      ...     calls.append('swipe_left')78      >>> def make_board(N):79      ...     calls.append('make_board')80      >>> def swap(board):81      ...     calls.append('swap')82      >>> def print(msg):83      ...     calls.append('print')84      >>> def quit():85      ...     calls.append('quit')86      >>> def end_move(board):87      ...     return 188      >>> def place_random(board):89      ...     return 190      >>> def print_board(board):...swipe.py
Source:swipe.py  
1from micropython import const2from trezor import io, ui3from trezor.ui import contains, rotate4SWIPE_UP = const(0x01)5SWIPE_DOWN = const(0x02)6SWIPE_LEFT = const(0x04)7SWIPE_RIGHT = const(0x08)8SWIPE_VERTICAL = const(SWIPE_UP | SWIPE_DOWN)9SWIPE_HORIZONTAL = const(SWIPE_LEFT | SWIPE_RIGHT)10SWIPE_ALL = const(SWIPE_VERTICAL | SWIPE_HORIZONTAL)11_SWIPE_DISTANCE = const(120)12class Swipe(ui.Widget):13    def __init__(self, area=None, absolute=False, directions=SWIPE_ALL, treshold=30):14        self.area = area or (0, 0, ui.WIDTH, ui.HEIGHT)15        self.absolute = absolute16        self.directions = directions17        self.treshold = treshold18        self.start_pos = None19        self.light_origin = None20        self.light_target = ui.BACKLIGHT_NONE21    def touch(self, event, pos):22        if not self.absolute:23            pos = rotate(pos)24        if event == io.TOUCH_MOVE and self.start_pos is not None:25            pdx = pos[0] - self.start_pos[0]26            pdy = pos[1] - self.start_pos[1]27            pdxa = abs(pdx)28            pdya = abs(pdy)29            if pdxa > pdya and self.directions & SWIPE_HORIZONTAL:30                # Horizontal direction31                if (pdx > 0 and self.directions & SWIPE_RIGHT) or (32                    pdx < 0 and self.directions & SWIPE_LEFT33                ):34                    ui.display.backlight(35                        ui.lerpi(36                            self.light_origin,37                            self.light_target,38                            pdxa / _SWIPE_DISTANCE if pdxa < _SWIPE_DISTANCE else 1,39                        )40                    )41            elif pdxa < pdya and self.directions & SWIPE_VERTICAL:42                # Vertical direction43                if (pdy > 0 and self.directions & SWIPE_DOWN) or (44                    pdy < 0 and self.directions & SWIPE_UP45                ):46                    ui.display.backlight(47                        ui.lerpi(48                            self.light_origin,49                            self.light_target,50                            pdya / _SWIPE_DISTANCE if pdya < _SWIPE_DISTANCE else 1,51                        )52                    )53        elif event == io.TOUCH_START and contains(self.area, pos):54            self.start_pos = pos55            self.light_origin = ui.BACKLIGHT_NORMAL56        elif event == io.TOUCH_END and self.start_pos is not None:57            pdx = pos[0] - self.start_pos[0]58            pdy = pos[1] - self.start_pos[1]59            pdxa = abs(pdx)60            pdya = abs(pdy)61            if pdxa > pdya and self.directions & SWIPE_HORIZONTAL:62                # Horizontal direction63                ratio = pdxa / _SWIPE_DISTANCE if pdxa < _SWIPE_DISTANCE else 164                if ratio * 100 >= self.treshold:65                    if pdx > 0 and self.directions & SWIPE_RIGHT:66                        return SWIPE_RIGHT67                    elif pdx < 0 and self.directions & SWIPE_LEFT:68                        return SWIPE_LEFT69            elif pdxa < pdya and self.directions & SWIPE_VERTICAL:70                # Vertical direction71                ratio = pdya / _SWIPE_DISTANCE if pdya < _SWIPE_DISTANCE else 172                if ratio * 100 >= self.treshold:73                    if pdy > 0 and self.directions & SWIPE_DOWN:74                        return SWIPE_DOWN75                    elif pdy < 0 and self.directions & SWIPE_UP:76                        return SWIPE_UP77            # No swipe, reset the state78            self.start_pos = None...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!!
