How to use is_screen_on method in ATX

Best Python code snippet using ATX

screen.py

Source:screen.py Github

copy

Full Screen

1"""2This module implements the screen class.3"""4import pygame5import numpy6import threading78from consts import *910KP_TRANSLATION_MAP = {11 pygame.K_KP0: 0,12 pygame.K_KP1: 1,13 pygame.K_KP2: 2,14 pygame.K_KP3: 3,15 pygame.K_KP4: 4,16 pygame.K_KP5: 5,17 pygame.K_KP6: 6,18 pygame.K_KP7: 7,19 pygame.K_KP8: 8,20 pygame.K_KP9: 9,21 pygame.K_KP_DIVIDE: 0xa,22 pygame.K_KP_MULTIPLY: 0xb,23 pygame.K_KP_MINUS: 0xc,24 pygame.K_KP_PLUS: 0xd,25 pygame.K_KP_ENTER: 0xe,26 pygame.K_KP_PERIOD: 0xf,27}282930class Screen(threading.Thread):31 def __init__(self):32 super().__init__()33 self.window_width = WIDTH * TILE_LEN34 self.window_height = HEIGHT * TILE_LEN35 self.width = WIDTH36 self.height = HEIGHT37 self.is_screen_on = False38 self.matrix = numpy.zeros((self.width, self.height), dtype=int)39 self.screen_lock = threading.Lock()40 self.keypad = {41 0: False,42 1: False,43 2: False,44 3: False,45 4: False,46 5: False,47 6: False,48 7: False,49 8: False,50 9: False,51 0xa: False,52 0xb: False,53 0xc: False,54 0xd: False,55 0xe: False,56 0xf: False,57 }5859 def run(self):60 self.is_screen_on = True61 self.display = pygame.display.set_mode((self.window_width, self.window_height))6263 while self.is_screen_on:64 self.handle_events()65 self.draw_screen()66 pygame.display.update()6768 def handle_events(self):69 for event in pygame.event.get():70 if event.type == pygame.QUIT:71 self.is_screen_on = False72 if event.type == pygame.KEYDOWN:73 if event.key in KP_TRANSLATION_MAP:74 self.keypad[KP_TRANSLATION_MAP[event.key]] = True75 if event.type == pygame.KEYUP:76 if event.key in KP_TRANSLATION_MAP:77 self.keypad[KP_TRANSLATION_MAP[event.key]] = False7879 def draw_screen(self):80 with self.screen_lock:81 for x in range(self.width):82 for y in range(self.height):83 self.draw_tile(x, y, self.matrix[x, y])8485 def draw_tile(self, x, y, value):86 rect = (x * TILE_LEN, y * TILE_LEN, (x + 1) * TILE_LEN, (y + 1) * TILE_LEN)87 if value == 1:88 pygame.draw.rect(self.display, (255, 255, 255), rect)89 elif value == 0:90 pygame.draw.rect(self.display, (0, 0, 0), rect)9192 def draw_sprite(self, x, y, width, height, raw_sprite):93 """94 :param x: The sprite x coordinate.95 :param y: The sprite y coordinate.96 :param width: The sprite width.97 :param height: The sprite height.98 :param raw_sprite: The raw sprite in bytes.99 :return: If any screen pixel is flipped from set to unset.100 :return: 1 or 0 depending on if any pixel was flipped from set to unset.101 :rtype: int102 """103 with self.screen_lock:104 raw_sprite_value = int.from_bytes(raw_sprite, byteorder='big')105 sprite_matrix = self.bin_to_matrix(width, height, raw_sprite_value)106 set_to_unset = 0107 for col in range(width):108 for row in range(height):109 matrix_x = (x + col) % self.width110 matrix_y = (y + row) % self.height111 if matrix_x < self.width and matrix_y < self.height:112 last_value = self.matrix[matrix_x, matrix_y]113 self.matrix[matrix_x, matrix_y] ^= sprite_matrix[col, row]114 if last_value == 1 and self.matrix[matrix_x, matrix_y] == 0:115 set_to_unset = 1116117 return set_to_unset118119 @staticmethod120 def bin_to_matrix(width, height, value):121 sprite_matrix = numpy.zeros((width, height), dtype=int)122 bit_index = (width * height) - 1123 bit_mask = 2 ** bit_index124125 for y in range(height):126 for x in range(width):127 sprite_matrix[x, y] = (value & bit_mask) >> bit_index128 bit_index -= 1129 bit_mask = 2 ** bit_index130131 return sprite_matrix132133 def key_status(self, key):134 return self.keypad[key]135136 def await_key(self):137 pressed_key = None138 while not pressed_key:139 for key in self.keypad:140 if self.keypad[key]:141 pressed_key = key142 return pressed_key143144 def clear_screen(self):145 with self.screen_lock:146 for x in range(self.width):147 for y in range(self.height):148 self.matrix[x, y] = 0 ...

Full Screen

Full Screen

test_device_navigation_class.py

Source:test_device_navigation_class.py Github

copy

Full Screen

...4from mobiletestorchestrator.device import Device5from mobiletestorchestrator.application import Application, AsyncApplication6from mobiletestorchestrator.device_interactions import DeviceInteraction, AsyncDeviceInteraction7class TestDeviceInteraction:8 def test_is_screen_on(self, device: Device):9 device_nav = DeviceInteraction(device)10 is_screen_on = device_nav.is_screen_on()11 DeviceInteraction(device).toggle_screen_on()12 retries = 313 new_is_screen_on = is_screen_on14 while retries > 0 and new_is_screen_on == is_screen_on:15 time.sleep(3)16 new_is_screen_on = device_nav.is_screen_on()17 retries -= 118 assert is_screen_on != new_is_screen_on19 def test_return_home_succeeds(self, install_app, device: Device, support_app: str):20 app = install_app(Application, support_app)21 app.start(activity=".MainActivity")22 assert device.foreground_activity() == app.package_name23 device_nav = DeviceInteraction(device)24 device_nav.return_home()25 assert device_nav.home_screen_active()26 def test_return_home_fails(self, install_app, device: Device, support_app: str):27 app = install_app(Application, support_app)28 app.start(activity=".MainActivity")29 assert device.foreground_activity() == app.package_name30 with pytest.raises(expected_exception=Exception) as excinfo:31 # Nobody would ever really pass a negative number, but our test app has only one activity screen. So32 # need to pass -1 to force the function to reach its back button key-press limit33 DeviceInteraction(device).return_home(keycode_back_limit=-1)34 assert "Max number of back button presses" in str(excinfo.value)35class TestDeviceInteractionAsync:36 @pytest.mark.asyncio37 async def test_is_screen_on(self, device: Device):38 navigator = AsyncDeviceInteraction(device)39 is_screen_on = navigator.is_screen_on()40 await navigator.toggle_screen_on()41 retries = 342 new_is_screen_on = is_screen_on43 while retries > 0 and new_is_screen_on == is_screen_on:44 await asyncio.sleep(1)45 new_is_screen_on = await navigator.is_screen_on()46 retries -= 147 assert is_screen_on != new_is_screen_on48 @pytest.mark.asyncio49 async def test_go_home(self, device: Device, install_app_async, support_app: Application):50 app = await install_app_async(AsyncApplication, support_app)51 await app.start(activity=".MainActivity")52 assert device.foreground_activity() == app.package_name53 device_nav = AsyncDeviceInteraction(device)54 await device_nav.return_home()...

Full Screen

Full Screen

unlockWithSwipe.py

Source:unlockWithSwipe.py Github

copy

Full Screen

...8 unlockWithSwipe.py [-s DEVICE] [-u|-d|-l|-r] -t [TEXT_TO_TYPE] [-e]9"""10def get_screen_settings(device):11 return adbCommand(["shell", "dumpsys", "window"], device)12def is_screen_on(device, get_settings=get_screen_settings):13 settings = get_settings(device)14 if "mScreenOnFully=true" in settings:15 return True16 elif "mScreenOnFully=false" in settings:17 return False18 else:19 print("Unknown - assuming off")20 return False21def ensure_screen_off(device, command=lambda: press_power(device)):22 if is_screen_on(device):23 command()24def press_power(device):25 press_button("KEYCODE_POWER", device)26def unlock(options, press_enter):27 device=options.get("device")28 # ensure_screen_off(device)29 screen_is_on = is_screen_on(device)30 while not screen_is_on:31 press_power(device)32 time.sleep(0.5)33 screen_is_on = is_screen_on(device)34 # press_power(device)35 swipe_device("u", options)36 type_text(options.get("text"), device)37 if press_enter:38 press_button("KEYCODE_ENTER", device)39if __name__ == "__main__":40 options = setUp(ui_required = False)41 args = sys.argv42 del args[0]43 press_enter = False44 if "-e" in args:45 pos = args.index("-e")46 del args[pos]47 press_enter = True48 script_args = validateArgs(args, unlock_usage)49 unlock(options, press_enter)50 # ensure_screen_off(device)51 # screen_is_on = is_screen_on(device)52 # while screen_is_on:53 # screen_is_on = is_screen_on(device)54 # press_power(device)55 # swipe_device("u", options)56 # type_text(options.get("text"), device)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful