Best Python code snippet using prospector_python
displays_test.py
Source:displays_test.py
1import unittest2from rum.displays import DirectDisplay, DisplayWindow, ScrollingDisplay, \3 PagedDisplay4from rum.scheduling import Scheduler5from tests.testutils import FakeClock6class DirectDisplayTests(unittest.TestCase):7 def setUp(self):8 def push_fn(lines):9 self._pushed = lines10 self._display = (DirectDisplay.Builder()11 .set_lines(2)12 .set_line_width(16)13 .push_with(push_fn)14 .build())15 def test_initialState_correctDimensions(self):16 self.assertEqual(2, len(self._display))17 self.assertEqual(2, self._display.height())18 self.assertEqual(16, self._display.width())19 def test_initialState_displayPaddedWithSpaces(self):20 self.assertEqual([' ']*16, self._display[0])21 self.assertEqual([' ']*16, self._display[1])22 def test_assignment_displayPaddedWithSpaces(self):23 self._display[0] = '123'24 self.assertEqual(['1', '2', '3'] + [' ']*13, self._display[0])25 self.assertEqual([' ']*16, self._display[1])26 def test_subassignment_portionOfDisplayUpdated(self):27 self._display[0][3:5] = '45'28 self.assertEqual(' 45 ', ''.join(self._display[0]))29 self.assertEqual([' ']*16, self._display[1])30 def test_repr_displaysStrings(self):31 self.assertEqual(f'{" ":16}\n{" ":16}', repr(self._display))32 def test_push_callsUnderlyingFunction(self):33 self._display[0][3:5] = '45'34 self._display.push()35 self.assertEqual([36 list(' 45 '),37 list(' '*16)], self._pushed)38class DisplayWindowTest(unittest.TestCase):39 def setUp(self):40 def push_fn(lines):41 self._pushed = lines42 self._display = (DirectDisplay.Builder()43 .set_lines(5)44 .set_line_width(16)45 .push_with(push_fn)46 .build())47 self._window = (DisplayWindow.Builder(self._display)48 .line_range(2, 4)49 .char_range(5, 10)50 .build())51 self._window2 = (DisplayWindow.Builder(self._display)52 .char_range(5, 10)53 .build())54 self._window3 = (DisplayWindow.Builder(self._display)55 .line_range(2, 4)56 .build())57 def test_initialState_correctDimensions(self):58 self.assertEqual(2, len(self._window))59 self.assertEqual(2, self._window.height())60 self.assertEqual(5, self._window.width())61 def test_underlyingDisplayUpdated_windowUpdated(self):62 self._display[0] = '****************'63 self._display[1] = '****************'64 self._display[2] = '0123456789abcdef'65 self._display[3] = 'ABCDEFGHIJKLMNOP'66 self._display[4] = '****************'67 self.assertEqual(list('56789'), self._window[0])68 self.assertEqual(list('FGHIJ'), self._window[1])69 def test_updateWindow_underlyingDisplayAndOtherWindowsUpdated(self):70 self._display[0] = '****************'71 self._display[1] = '****************'72 self._display[2] = '0123456789abcdef'73 self._display[3] = 'ABCDEFGHIJKLMNOP'74 self._display[4] = '****************'75 self._window[0] = ':)'76 self._window[1] = 'helloworld'77 self.assertEqual(list(':) '), self._window[0])78 self.assertEqual(list('hello'), self._window[1])79 self.assertEqual(list(':) '), self._window2[2])80 self.assertEqual(list('hello'), self._window2[3])81 self.assertEqual(list('01234:) abcdef'), self._window3[0])82 self.assertEqual(list('ABCDEhelloKLMNOP'), self._window3[1])83 self.assertEqual(list('****************'), self._display[0])84 self.assertEqual(list('****************'), self._display[1])85 self.assertEqual(list('01234:) abcdef'), self._display[2])86 self.assertEqual(list('ABCDEhelloKLMNOP'), self._display[3])87 self.assertEqual(list('****************'), self._display[4])88 def test_pushCalled_propagatesToUnderlyingDisplay(self):89 self._display[0] = '****************'90 self._display[1] = '****************'91 self._display[2] = '0123456789abcdef'92 self._display[3] = 'ABCDEFGHIJKLMNOP'93 self._display[4] = '****************'94 self._window[0] = ':)'95 self._window[1] = 'helloworld'96 self._window.push()97 self.assertEqual([98 list('****************'),99 list('****************'),100 list('01234:) abcdef'),101 list('ABCDEhelloKLMNOP'),102 list('****************')],103 self._pushed)104class ScrollingDisplayTest(unittest.TestCase):105 def setUp(self):106 self._clock = FakeClock()107 def push_fn(lines):108 self._pushed = lines109 self._scheduler = Scheduler(time_fn=self._clock.time)110 self._display = (DirectDisplay.Builder()111 .set_lines(5)112 .set_line_width(16)113 .push_with(push_fn)114 .build())115 window = (DisplayWindow.Builder(self._display)116 .line_range(2, 4)117 .char_range(5, 10)118 .build())119 self._window = ScrollingDisplay(window,120 self._scheduler,121 scroll_interval_ms=250,122 scroll_amount=1,123 padding=2)124 self._display[0] = '****************'125 self._display[1] = '****************'126 self._display[2] = '***** ******'127 self._display[3] = '***** ******'128 self._display[4] = '****************'129 def test_dimensions_matchUnderlyingWindow(self):130 self.assertEqual(2, self._window.height())131 self.assertEqual(5, self._window.width())132 self.assertEqual(2, len(self._window))133 def test_setLongLines_contentContainsFullLines(self):134 self._window[0] = 'hello world'135 self._window[0] += '!'136 self._window[1] = 'this is a test'137 self.assertEqual('hello world!', self._window[0])138 self.assertEqual('this is a test', self._window[1])139 def test_setShortLines_contentContainsFullLines(self):140 self._window[0] = 'hello'141 self._window[1] = 'world'142 self.assertEqual('hello', self._window[0])143 self.assertEqual('world', self._window[1])144 def test_allShortLines_noScrolling(self):145 self._window[0] = 'hello'146 self._window[1] = 'world'147 self._clock.advance(0.250)148 self._scheduler.idle()149 self.assertEqual('hello', self._window[0])150 self.assertEqual('world', self._window[1])151 self.assertEqual(list('****************'), self._display[0])152 self.assertEqual(list('****************'), self._display[1])153 self.assertEqual(list('*****hello******'), self._display[2])154 self.assertEqual(list('*****world******'), self._display[3])155 self.assertEqual(list('****************'), self._display[4])156 def test_allLongLines_bothScrolling(self):157 self._window[0] = 'hello!!'158 self._window[1] = 'world!'159 # Iteration 1160 self._clock.advance(0.250)161 self._scheduler.idle()162 self.assertEqual('hello!!', self._window[0])163 self.assertEqual('world!', self._window[1])164 self.assertEqual(list('****************'), self._display[0])165 self.assertEqual(list('****************'), self._display[1])166 self.assertEqual(list('*****ello!******'), self._display[2])167 self.assertEqual(list('*****orld!******'), self._display[3])168 self.assertEqual(list('****************'), self._display[4])169 # Iteration 2170 self._clock.advance(0.250)171 self._scheduler.idle()172 self.assertEqual('hello!!', self._window[0])173 self.assertEqual('world!', self._window[1])174 self.assertEqual(list('****************'), self._display[0])175 self.assertEqual(list('****************'), self._display[1])176 self.assertEqual(list('*****llo!!******'), self._display[2])177 self.assertEqual(list('*****rld! ******'), self._display[3])178 self.assertEqual(list('****************'), self._display[4])179 # Iteration 3180 self._clock.advance(0.250)181 self._scheduler.idle()182 self.assertEqual('hello!!', self._window[0])183 self.assertEqual('world!', self._window[1])184 self.assertEqual(list('****************'), self._display[0])185 self.assertEqual(list('****************'), self._display[1])186 self.assertEqual(list('*****lo!! ******'), self._display[2])187 self.assertEqual(list('*****ld! ******'), self._display[3])188 self.assertEqual(list('****************'), self._display[4])189 # Iteration 4190 self._clock.advance(0.250)191 self._scheduler.idle()192 self.assertEqual('hello!!', self._window[0])193 self.assertEqual('world!', self._window[1])194 self.assertEqual(list('****************'), self._display[0])195 self.assertEqual(list('****************'), self._display[1])196 self.assertEqual(list('*****o!! ******'), self._display[2])197 self.assertEqual(list('*****d! w******'), self._display[3])198 self.assertEqual(list('****************'), self._display[4])199 # Iteration 5200 self._clock.advance(0.250)201 self._scheduler.idle()202 self.assertEqual('hello!!', self._window[0])203 self.assertEqual('world!', self._window[1])204 self.assertEqual(list('****************'), self._display[0])205 self.assertEqual(list('****************'), self._display[1])206 self.assertEqual(list('*****!! h******'), self._display[2])207 self.assertEqual(list('*****! wo******'), self._display[3])208 self.assertEqual(list('****************'), self._display[4])209 # Iteration 6210 self._clock.advance(0.250)211 self._scheduler.idle()212 self.assertEqual(list('*****! he******'), self._display[2])213 self.assertEqual(list('***** wor******'), self._display[3])214 # Iteration 7215 self._clock.advance(0.250)216 self._scheduler.idle()217 self.assertEqual(list('***** hel******'), self._display[2])218 self.assertEqual(list('***** worl******'), self._display[3])219 # Iteration 8220 self._clock.advance(0.250)221 self._scheduler.idle()222 self.assertEqual(list('***** hell******'), self._display[2])223 self.assertEqual(list('*****world******'), self._display[3])224 # Iteration 9225 self._clock.advance(0.250)226 self._scheduler.idle()227 self.assertEqual(list('*****hello******'), self._display[2])228 self.assertEqual(list('*****orld!******'), self._display[3])229 def test_bothShortAndLongLines_onlyLongScrolling(self):230 self._window[0] = 'hello'231 self._window[1] = 'world!'232 # Iteration 1233 self._clock.advance(0.250)234 self._scheduler.idle()235 self.assertEqual('hello', self._window[0])236 self.assertEqual('world!', self._window[1])237 self.assertEqual(list('****************'), self._display[0])238 self.assertEqual(list('****************'), self._display[1])239 self.assertEqual(list('*****hello******'), self._display[2])240 self.assertEqual(list('*****orld!******'), self._display[3])241 self.assertEqual(list('****************'), self._display[4])242 # Iteration 2243 self._clock.advance(0.250)244 self._scheduler.idle()245 self.assertEqual('hello', self._window[0])246 self.assertEqual('world!', self._window[1])247 self.assertEqual(list('****************'), self._display[0])248 self.assertEqual(list('****************'), self._display[1])249 self.assertEqual(list('*****hello******'), self._display[2])250 self.assertEqual(list('*****rld! ******'), self._display[3])251 self.assertEqual(list('****************'), self._display[4])252 # Iteration 3253 self._clock.advance(0.250)254 self._scheduler.idle()255 self.assertEqual(list('*****hello******'), self._display[2])256 self.assertEqual(list('*****ld! ******'), self._display[3])257 # Iteration 4258 self._clock.advance(0.250)259 self._scheduler.idle()260 self.assertEqual(list('*****d! w******'), self._display[3])261 # Iteration 5262 self._clock.advance(0.250)263 self._scheduler.idle()264 self.assertEqual(list('*****! wo******'), self._display[3])265 # Iteration 6266 self._clock.advance(0.250)267 self._scheduler.idle()268 self.assertEqual(list('***** wor******'), self._display[3])269 # Iteration 7270 self._clock.advance(0.250)271 self._scheduler.idle()272 self.assertEqual(list('***** worl******'), self._display[3])273 # Iteration 8274 self._clock.advance(0.250)275 self._scheduler.idle()276 self.assertEqual(list('*****world******'), self._display[3])277 def test_updateTextWhileScrolling_startsBackAt0(self):278 self._window[0] = 'hello!!'279 self._window[1] = 'world!'280 # Iteration 1281 self._clock.advance(0.250)282 self._scheduler.idle()283 self.assertEqual('hello!!', self._window[0])284 self.assertEqual('world!', self._window[1])285 self.assertEqual(list('****************'), self._display[0])286 self.assertEqual(list('****************'), self._display[1])287 self.assertEqual(list('*****ello!******'), self._display[2])288 self.assertEqual(list('*****orld!******'), self._display[3])289 self.assertEqual(list('****************'), self._display[4])290 # Iteration 2291 self._clock.advance(0.250)292 self._scheduler.idle()293 self.assertEqual('hello!!', self._window[0])294 self.assertEqual('world!', self._window[1])295 self.assertEqual(list('****************'), self._display[0])296 self.assertEqual(list('****************'), self._display[1])297 self.assertEqual(list('*****llo!!******'), self._display[2])298 self.assertEqual(list('*****rld! ******'), self._display[3])299 self.assertEqual(list('****************'), self._display[4])300 # Insert text301 self._window[0] = 'hello!!'302 # Iteration 3303 self._clock.advance(0.250)304 self._scheduler.idle()305 self.assertEqual(list('****************'), self._display[0])306 self.assertEqual(list('****************'), self._display[1])307 self.assertEqual(list('*****hello******'), self._display[2])308 self.assertEqual(list('*****ld! ******'), self._display[3])309 self.assertEqual(list('****************'), self._display[4])310 # Iteration 4311 self._clock.advance(0.250)312 self._scheduler.idle()313 self.assertEqual('hello!!', self._window[0])314 self.assertEqual('world!', self._window[1])315 self.assertEqual(list('****************'), self._display[0])316 self.assertEqual(list('****************'), self._display[1])317 self.assertEqual(list('*****ello!******'), self._display[2])318 self.assertEqual(list('*****d! w******'), self._display[3])319 self.assertEqual(list('****************'), self._display[4])320class PagedDisplayTests(unittest.TestCase):321 def setUp(self):322 self._clock = FakeClock()323 self._pushed = None324 def push_fn(lines):325 self._pushed = [line[:] for line in lines]326 self._scheduler = Scheduler(time_fn=self._clock.time)327 self._display = (DirectDisplay.Builder()328 .set_lines(2)329 .set_line_width(16)330 .push_with(push_fn)331 .build())332 self._paged_display = PagedDisplay(self._display, self._scheduler)333 self._display[0] = 'Hello'334 self._display[1] = 'World'335 def test_pagedDisplay_matchesUnderlyingDimensions(self):336 self.assertEqual(2, len(self._paged_display))337 self.assertEqual(16, self._paged_display.width())338 def test_setInactivePage_doesNotImpactCurrentDisplay(self):339 self._paged_display.page('page1')[0] = 'goodbye'340 self._paged_display.page('page1')[1] = 'unittest'341 self.assertEqual(list('Hello '), self._display[0])342 self.assertEqual(list('World '), self._display[1])343 self.assertEqual(['goodbye', 'unittest'],344 self._paged_display.page('page1'))345 self.assertEqual(None, self._pushed)346 def test_setActivePage_alsoUpdatesDisplay(self):347 self._paged_display.page('main')[0] = 'main'348 self._paged_display.page('main')[1] = 'page'349 self._paged_display.set_active_page('main')350 self.assertEqual(list('main '), self._display[0])351 self.assertEqual(list('page '), self._display[1])352 self.assertEqual([list('main '),353 list('page ')],354 self._pushed)355 def test_directlyChangeActivePage_alsoUpdatesActiveKey(self):356 self._paged_display.page('main')[0] = 'main'357 self._paged_display.page('main')[1] = 'page'358 self._paged_display.set_active_page('main')359 self._paged_display[0] = 'changed'360 self._paged_display[1] = 'text'361 self.assertEqual(list('changed '), self._display[0])362 self.assertEqual(list('text '), self._display[1])363 self.assertEqual(['changed', 'text'], self._paged_display.page('main'))364 # Changes don't get pushed until explicitly pushed or active page set.365 self.assertEqual([list('main '),366 list('page ')],367 self._pushed)368 def test_temporaryPage_properlyShowsAndRevertsToActivePageContent(self):369 self._paged_display.page('main')[0] = 'main'370 self._paged_display.page('main')[1] = 'page'371 self._paged_display.set_active_page('main')372 self._paged_display.page('tmp')[0] = 'temporary'373 self._paged_display.page('tmp')[1] = 'toast'374 self._paged_display.set_active_page('tmp', expiration_ms=500)375 self.assertEqual(list('temporary '), self._display[0])376 self.assertEqual(list('toast '), self._display[1])377 self.assertEqual(['temporary', 'toast'],378 self._paged_display.page('tmp'))379 self.assertEqual('temporary', self._paged_display[0])380 self.assertEqual('toast', self._paged_display[1])381 self.assertEqual([list('temporary '),382 list('toast ')],383 self._pushed)384 # No changes if the expiration time doesn't hit385 self._clock.advance(0.499)386 self._scheduler.idle()387 self.assertEqual('temporary', self._paged_display[0])388 self.assertEqual('toast', self._paged_display[1])389 self.assertEqual([list('temporary '),390 list('toast ')],391 self._pushed)392 # When expires, content reverts to main page393 self._clock.advance(0.001)394 self._scheduler.idle()395 self.assertEqual('main', self._paged_display[0])396 self.assertEqual('page', self._paged_display[1])397 self.assertEqual([list('main '),398 list('page ')],399 self._pushed)400 def test_temporaryPage_properlyShowsAndRevertsToActivePageContent(self):401 self._paged_display.page('main')[0] = 'main'402 self._paged_display.page('main')[1] = 'page'403 self._paged_display.set_active_page('main')404 self._paged_display.page('tmp')[0] = 'temporary'405 self._paged_display.page('tmp')[1] = 'toast'406 self._paged_display.set_active_page('tmp', expiration_ms=500)407 self.assertEqual(list('temporary '), self._display[0])408 self.assertEqual(list('toast '), self._display[1])409 self.assertEqual(['temporary', 'toast'],410 self._paged_display.page('tmp'))411 self.assertEqual('temporary', self._paged_display[0])412 self.assertEqual('toast', self._paged_display[1])413 self.assertEqual([list('temporary '),414 list('toast ')],415 self._pushed)416 # No changes if the expiration time doesn't hit417 self._clock.advance(0.499)418 self._scheduler.idle()419 self.assertEqual('temporary', self._paged_display[0])420 self.assertEqual('toast', self._paged_display[1])421 self.assertEqual([list('temporary '),422 list('toast ')],423 self._pushed)424 # When expires, content reverts to main page425 self._clock.advance(0.001)426 self._scheduler.idle()427 self.assertEqual('main', self._paged_display[0])428 self.assertEqual('page', self._paged_display[1])429 self.assertEqual([list('main '),430 list('page ')],431 self._pushed)432 def test_temporaryPageWhileTemporaryPageActive_cancelsFirstProperly(self):433 self._paged_display.page('main')[0] = 'main'434 self._paged_display.page('main')[1] = 'page'435 self._paged_display.set_active_page('main')436 self._paged_display.page('tmp')[0] = 'temporary'437 self._paged_display.page('tmp')[1] = 'toast'438 self._paged_display.set_active_page('tmp', expiration_ms=500)439 self._paged_display.page('tmp2')[0] = 'another'440 self._paged_display.page('tmp2')[1] = 'msg'441 self._paged_display.set_active_page('tmp2', expiration_ms=100)442 self.assertEqual(list('another '), self._display[0])443 self.assertEqual(list('msg '), self._display[1])444 self.assertEqual('another', self._paged_display[0])445 self.assertEqual('msg', self._paged_display[1])446 self.assertEqual([list('another '),447 list('msg ')],448 self._pushed)449 # No changes if the expiration time doesn't hit450 self._clock.advance(0.100)451 self._scheduler.idle()452 self.assertEqual('main', self._paged_display[0])453 self.assertEqual('page', self._paged_display[1])454 self.assertEqual([list('main '),455 list('page ')],456 self._pushed)457 # When previous toast would have expire, nothing changes458 self._clock.advance(0.500)459 self._scheduler.idle()460 self.assertEqual('main', self._paged_display[0])461 self.assertEqual('page', self._paged_display[1])462 self.assertEqual([list('main '),463 list('page ')],464 self._pushed)465 def test_temporaryPageResetWhileActive_cancelsAndResetsProperly(self):466 self._paged_display.page('main')[0] = 'main'467 self._paged_display.page('main')[1] = 'page'468 self._paged_display.set_active_page('main')469 self._paged_display.page('tmp')[0] = 'temporary'470 self._paged_display.page('tmp')[1] = 'toast'471 self._paged_display.set_active_page('tmp', expiration_ms=500)472 self._paged_display.reset()473 self.assertEqual('main', self._paged_display[0])474 self.assertEqual('page', self._paged_display[1])475 self.assertEqual([list('main '),476 list('page ')],477 self._pushed)478 # Update active tab before the toast would have expired479 self._paged_display.page('new')[0] = 'hello'480 self._paged_display.page('new')[1] = 'world'481 self._paged_display.set_active_page('new')482 # When previous toast would have expire, nothing changes483 self._clock.advance(0.500)484 self._scheduler.idle()485 self.assertEqual('hello', self._paged_display[0])486 self.assertEqual('world', self._paged_display[1])487 self.assertEqual([list('hello '),488 list('world ')],489 self._pushed)490if __name__ == '__main__':...
drv_led_matrix.py
Source:drv_led_matrix.py
1#!/usr/bin/env python32# -*- coding: utf-8 -*-34import matatalab5import math6import time7import led_matrix_data89_led_matrix = matatalab.led_matrix()1011PICTURE_MODE = const(0x00)12ANIMATION_MODE = const(0x01)13CHARACTER_MODE = const(0x02)1415TURN_PAGES_MODE = const(0X00)16MOVE_UP_MODE = const(0X01)17MOVE_DOWN_MODE = const(0X02)18MOVE_LEFT_MODE = const(0X03)19MOVE_RIGHT_MODE = const(0X04)202122tempdis_bit_array = bytearray([0] * 256)23tempdis_array = bytearray([0] * 32)2425class display():26 _width = 1527 _height = 728 _brightness = 2029 _mode = PICTURE_MODE30 _currently_display_data = bytearray([0] * 16)31 _display_bank = [[0 for i in range(16)] for j in range(8)]32 _frame = 033 _char_string = ""34 _refresh_mode = MOVE_LEFT_MODE35 _refresh_time = 0.136 _screen_rotate_flag = False37 _bank_time = [0] * 83839 def __init__(self):40 self._frame = 041 self.init()4243 def init(self):44 self.sleep(True)45 self._mode = PICTURE_MODE46 for frame in range(8):47 empty_picture = bytearray([0] * 16)48 self.picture_bank(frame, empty_picture, 1)49 self.sleep(False)50 self._currently_display_data = bytearray(led_matrix_data.face_data_table.get('face1'))51 self._screen_rotate_flag = False52 self.show_image(self._currently_display_data, "None")5354 def picture_bank(self, bank, data_array, bank_time):55 if(bank < 0) or (bank > 7):56 return57 for i in range(len(data_array)):58 self._display_bank[bank][i] = data_array[i]59 self._bank_time[bank] = bank_time6061 def auto_play(self, frames = 0):62 self._frame = frames63 if self._frame > 0:64 self._mode = ANIMATION_MODE65 else:66 self._mode = PICTURE_MODE6768 def sleep(self, value):69 if value is True:70 _led_matrix.set_brightness(0)71 else:72 brightness_data = int(self._brightness * 2)73 _led_matrix.set_brightness(brightness_data)7475 def reset(self, time_value = 0.01):76 self.sleep(True)77 time.sleep(time_value) # 10 MS pause to reset.78 self.sleep(False)7980 def show_image(self, data_array, time_data = "None"):81 self._mode = PICTURE_MODE82 self._currently_display_data = data_array83 self._screen_rotate_flag = False84 _led_matrix.show_image(self._currently_display_data)85 if time_data != "None":86 time.sleep(time_data)87 _led_matrix.clear()8889 def set_pixel(self, x, y, brightness):90 self._mode = PICTURE_MODE91 brightness_data = int(brightness * 2)92 data_num = int((2 * y) + (x / 8))93 data_bit = x % 894 if brightness_data > 0:95 self._currently_display_data[data_num] = self._currently_display_data[data_num] | (0x01 << data_bit)96 else:97 self._currently_display_data[data_num] = self._currently_display_data[data_num] & (~(0x01 << data_bit) & 0xff)98 _led_matrix.set_pixel(x, y, brightness_data)99100 def write(self, input):101 strlist = str(input)102 # print("write:%s" %(strlist))103 if len(strlist) > 2:104 self._char_string = "%s%s" %(strlist, " ")105 self._mode = CHARACTER_MODE106 else:107 self._mode = PICTURE_MODE108 char_byte_list = [[0 for i in range(16)] for j in range(2)]109 for i in range(2):110 if(len(strlist) > i):111 char_byte_list[i] = led_matrix_data.character_data_table.get(strlist[i])112 if(char_byte_list[i] is None):113 char_byte_list[i] = led_matrix_data.character_data_table.get(" ")114 else:115 char_byte_list[i] = led_matrix_data.character_data_table.get(" ")116117 for frame_byte in range(8):118 self._currently_display_data[frame_byte * 2] = char_byte_list[0][frame_byte]119 self._currently_display_data[frame_byte * 2 + 1] = char_byte_list[1][frame_byte]120 _led_matrix.show_image(bytearray(self._currently_display_data))121122 def clear(self):123 self._mode = PICTURE_MODE124 self._char_string = ""125 for frame_byte in range(16):126 self._currently_display_data[frame_byte] = 0x00127 self._screen_rotate_flag = False128 _led_matrix.clear()129130 def set_brightness(self, brightness):131 self._brightness = brightness132 brightness_data = int(self._brightness * 2);133 _led_matrix.set_brightness(brightness_data)134135 def get_brightness(self):136 return self._brightness137138 def screen_rotate(self, rotate):139 global tempdis_bit_array140 global tempdis_array141 if self._mode == PICTURE_MODE:142 if self._screen_rotate_flag == False:143 for frame_byte in range(8):144 tempdis_array[frame_byte] = 0x00145 for frame_byte in range(16):146 tempdis_array[frame_byte + 8] = self._currently_display_data[frame_byte]147 for frame_byte in range(8):148 tempdis_array[frame_byte + 24] = 0x00149 self._screen_rotate_flag = True150 for frame_bit in range(256):151 tempdis_bit_array[frame_bit] = (tempdis_array[int(frame_bit / 8)] >> (frame_bit % 8)) & 0x01152 if rotate == "counterclockwise":153 for frame_byte in range(16):154 temp_data = 0x0000155 for i in range(16):156 temp_data = temp_data | (tempdis_bit_array[(15 - frame_byte) + 16 * i] << i) & 0xffff157 tempdis_array[2 * frame_byte] = temp_data & 0xff158 tempdis_array[2 * frame_byte + 1] = (temp_data >> 8) & 0xff159 _led_matrix.show_image(bytearray(tempdis_array[8:24]))160 elif rotate == "clockwise":161 for frame_byte in range(16):162 temp_data = 0x0000163 for i in range(16):164 temp_data = temp_data | (tempdis_bit_array[frame_byte + 16 * (15 - i)] << i) & 0xffff165 tempdis_array[2 * frame_byte] = temp_data & 0xff166 tempdis_array[2 * frame_byte + 1] = (temp_data >> 8) & 0xff167 _led_matrix.show_image(bytearray(tempdis_array[8:24])) 168 else:169 pass170171 def set_orientation(self, orientation):172 # print("set_orientation:%s" %(orientation))173 if orientation == "upright":174 self._refresh_mode = MOVE_UP_MODE175 elif orientation == "left":176 self._refresh_mode = MOVE_LEFT_MODE177 elif orientation == "right":178 self._refresh_mode = MOVE_RIGHT_MODE179 elif orientation == "upside down":180 self._refresh_mode = MOVE_DOWN_MODE181 elif orientation == "turn pages":182 self._refresh_mode = TURN_PAGES_MODE183 else:184 self._refresh_mode = MOVE_LEFT_MODE185186 def set_refresh_time(self, time):187 self._refresh_time = time188189 def set_refresh_mode(self, mode):190 self._refresh_mode = mode191192_display = display()193194def _led_matrix_process():195 if(_display._mode == ANIMATION_MODE) and _display._frame > 0:196 if (_display._refresh_mode == TURN_PAGES_MODE):197 198 for frame_index in range(_display._frame):199 time_sleep_count = 0200 char_bytes = _display._display_bank[frame_index]201 if (_display._refresh_mode != TURN_PAGES_MODE) or (_display._mode != ANIMATION_MODE):202 break203 for frame_byte in range(16):204 _display._currently_display_data[frame_byte] = char_bytes[frame_byte]205 _led_matrix.show_image(bytearray(_display._currently_display_data))206 if(_display._bank_time[frame_index] == 0):207 time.sleep(_display._refresh_time)208 else:209 while(time_sleep_count < _display._bank_time[frame_index]):210 if (_display._refresh_mode != TURN_PAGES_MODE) or (_display._mode != ANIMATION_MODE):211 break212 time_sleep_count = time_sleep_count + 1213 time.sleep(0.01)214 elif (_display._refresh_mode == MOVE_LEFT_MODE) or (_display._refresh_mode == MOVE_RIGHT_MODE):215 char_byte_list = [[0 for i in range(16)] for j in range(2)]216 for frame_index in range(_display._frame):217 for i in range(2):218 char_byte_list[i] = _display._display_bank[(frame_index + i) % _display._frame]219 if(_display._refresh_mode == MOVE_LEFT_MODE):220 for j in range(16):221 if (_display._refresh_mode != MOVE_LEFT_MODE) or (_display._mode != ANIMATION_MODE):222 break223 for frame_byte in range(8):224 if j < 8:225 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[0][frame_byte * 2] >> j) | (char_byte_list[0][frame_byte * 2 + 1] << (8 - j))) & 0xff226 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[0][frame_byte * 2 + 1] >> j) | (char_byte_list[1][frame_byte * 2] << (8 -j))) & 0xff227 else:228 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[0][frame_byte * 2 + 1] >> (j - 8)) | (char_byte_list[1][frame_byte * 2] << (16 - j))) & 0xff229 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[1][frame_byte * 2] >> (j - 8)) | (char_byte_list[1][frame_byte * 2 + 1] << (16 -j))) & 0xff230 _led_matrix.show_image(bytearray(_display._currently_display_data))231 time.sleep(_display._refresh_time)232 elif (_display._refresh_mode == MOVE_RIGHT_MODE):233 for j in range(16):234 if (_display._refresh_mode != MOVE_RIGHT_MODE) or (_display._mode != ANIMATION_MODE):235 break236 for frame_byte in range(8):237 if j < 8:238 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[0][frame_byte * 2] << j) | (char_byte_list[0][frame_byte * 2 + 1] >> (8 - j))) & 0xff239 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[0][frame_byte * 2 + 1] << j) | (char_byte_list[1][frame_byte * 2] >> (8 -j))) & 0xff240 else:241 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[0][frame_byte * 2 + 1] << (j - 8)) | (char_byte_list[1][frame_byte * 2] >> (16 - j))) & 0xff242 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[1][frame_byte * 2] << (j - 8)) | (char_byte_list[1][frame_byte * 2 + 1] >> (16 -j))) & 0xff243 _led_matrix.show_image(bytearray(_display._currently_display_data))244 time.sleep(_display._refresh_time)245 elif (_display._refresh_mode == MOVE_UP_MODE) or (_display._refresh_mode == MOVE_DOWN_MODE):246 char_byte_list = [[0 for i in range(16)] for j in range(2)]247 for frame_index in range(_display._frame):248 for i in range(2):249 char_byte_list[i] = _display._display_bank[(frame_index + i) % _display._frame]250 if (_display._refresh_mode == MOVE_UP_MODE):251 for j in range(8):252 if (_display._refresh_mode != MOVE_UP_MODE) or (_display._mode != ANIMATION_MODE):253 break254 for frame_byte in range(8):255 if((frame_byte + j) < 8):256 _display._currently_display_data[frame_byte * 2] = char_byte_list[0][(frame_byte + j) * 2]257 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[0][(frame_byte + j) * 2 + 1]258 else:259 _display._currently_display_data[frame_byte * 2] = char_byte_list[1][(frame_byte + j - 8) * 2]260 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[1][(frame_byte + j - 8) * 2 + 1]261 _led_matrix.show_image(bytearray(_display._currently_display_data))262 time.sleep(_display._refresh_time)263 elif (_display._refresh_mode == MOVE_DOWN_MODE):264 for j in range(8):265 if (_display._refresh_mode != MOVE_DOWN_MODE) or (_display._mode != ANIMATION_MODE):266 break267 for frame_byte in range(8):268 if(frame_byte < j):269 _display._currently_display_data[frame_byte * 2] = char_byte_list[1][(frame_byte + 8 - j) * 2]270 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[1][(frame_byte + 8 - j) * 2 + 1]271 else:272 _display._currently_display_data[frame_byte * 2] = char_byte_list[0][(frame_byte - j) * 2]273 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[0][(frame_byte - j) * 2 + 1]274 _led_matrix.show_image(bytearray(_display._currently_display_data))275 time.sleep(_display._refresh_time)276 else:277 time.sleep(0.1)278 elif(_display._mode == CHARACTER_MODE):279 if (_display._refresh_mode == TURN_PAGES_MODE):280 for char_index in range(len(_display._char_string)):281 char_data = _display._char_string[char_index % len(_display._char_string)]282 char_bytes = led_matrix_data.character_data_table.get(char_data)283 if ((_display._refresh_mode != TURN_PAGES_MODE) | (_display._mode != CHARACTER_MODE)):284 break285 if(char_bytes is None):286 char_bytes = led_matrix_data.character_data_table.get(" ")287 if(char_index % 2 == 0):288 for frame_byte in range(8):289 _display._currently_display_data[frame_byte * 2] = char_bytes[frame_byte]290 if(char_index == len(_display._char_string) - 1):291 char_bytes = led_matrix_data.character_data_table.get(" ")292 for frame_byte in range(8):293 _display._currently_display_data[frame_byte * 2 + 1] = char_bytes[frame_byte]294 _led_matrix.show_image(bytearray(_display._currently_display_data))295 time.sleep(_display._refresh_time * 8)296 else:297 for frame_byte in range(8):298 _display._currently_display_data[frame_byte * 2 + 1] = char_bytes[frame_byte]299 _led_matrix.show_image(bytearray(_display._currently_display_data))300 time.sleep(_display._refresh_time * 8)301 elif (_display._refresh_mode == MOVE_LEFT_MODE) or (_display._refresh_mode == MOVE_RIGHT_MODE):302 char_data_buffer = [0] * 3303 char_byte_list = [[0 for i in range(8)] for j in range(3)]304 for char_index in range(len(_display._char_string) - 2 ):305 for i in range(3):306 char_data_buffer[i] = _display._char_string[(char_index + i) % len(_display._char_string)]307 char_byte_list[i] = led_matrix_data.character_data_table.get(char_data_buffer[i])308 if(char_byte_list[i] is None):309 char_byte_list[i] = led_matrix_data.character_data_table.get(" ")310 if(_display._refresh_mode == MOVE_LEFT_MODE):311 for j in range(8):312 if ((_display._refresh_mode != MOVE_LEFT_MODE) | (_display._mode != CHARACTER_MODE)):313 break314 for frame_byte in range(8):315 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[0][frame_byte] >> j) | (char_byte_list[1][frame_byte] << (8 - j))) & 0xff316 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[1][frame_byte] >> j) | (char_byte_list[2][frame_byte] << (8 -j))) & 0xff317 _led_matrix.show_image(bytearray(_display._currently_display_data))318 time.sleep(_display._refresh_time)319 elif (_display._refresh_mode == MOVE_RIGHT_MODE):320 for j in range(8):321 if ((_display._refresh_mode != MOVE_RIGHT_MODE) | (_display._mode != CHARACTER_MODE)):322 break323 for frame_byte in range(8):324 _display._currently_display_data[frame_byte * 2 + 1] = ((char_byte_list[0][frame_byte] << j) | (char_byte_list[1][frame_byte] >> (8 - j))) & 0xff325 _display._currently_display_data[frame_byte * 2] = ((char_byte_list[1][frame_byte] << j) | (char_byte_list[2][frame_byte] >> (8 -j))) & 0xff326 _led_matrix.show_image(bytearray(_display._currently_display_data))327 time.sleep(_display._refresh_time)328 else:329 break330 time.sleep(_display._refresh_time * 2)331 elif (_display._refresh_mode == MOVE_UP_MODE) or (_display._refresh_mode == MOVE_DOWN_MODE):332 if len(_display._char_string) % 2 != 0:333 _display._char_string = "%s%s" %(_display._char_string, " ")334 char_data_buffer = [0] * 4335 char_byte_list = [[0 for i in range(8)] for j in range(4)]336 for char_index in range(len(_display._char_string) / 2):337 for i in range(4):338 char_data_buffer[i] = _display._char_string[(char_index * 2 + i) % len(_display._char_string)]339 char_byte_list[i] = led_matrix_data.character_data_table.get(char_data_buffer[i])340 if(char_byte_list[i] is None):341 char_byte_list[i] = led_matrix_data.character_data_table.get(" ")342 if (_display._refresh_mode == MOVE_UP_MODE):343 for j in range(8):344 if ((_display._refresh_mode != MOVE_UP_MODE) | (_display._mode != CHARACTER_MODE)):345 break346 for frame_byte in range(8):347 if((frame_byte + j) < 8):348 _display._currently_display_data[frame_byte * 2] = char_byte_list[0][frame_byte + j]349 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[1][frame_byte + j]350 else:351 _display._currently_display_data[frame_byte * 2] = char_byte_list[2][frame_byte + j - 8]352 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[3][frame_byte + j -8]353 _led_matrix.show_image(bytearray(_display._currently_display_data))354 time.sleep(_display._refresh_time)355356 elif (_display._refresh_mode == MOVE_DOWN_MODE):357 for j in range(8):358 if ((_display._refresh_mode != MOVE_DOWN_MODE) | (_display._mode != CHARACTER_MODE)):359 break360 for frame_byte in range(8):361 if(frame_byte < j):362 _display._currently_display_data[frame_byte * 2] = char_byte_list[2][frame_byte + 8 - j]363 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[3][frame_byte + 8 - j]364 else:365 _display._currently_display_data[frame_byte * 2] = char_byte_list[0][frame_byte - j]366 _display._currently_display_data[frame_byte * 2 + 1] = char_byte_list[1][frame_byte - j]367 _led_matrix.show_image(bytearray(_display._currently_display_data))368 time.sleep(_display._refresh_time)369 else:370 break371 time.sleep(_display._refresh_time * 2)372 else:373 time.sleep(0.1)374 else:375 time.sleep(0.1)376377def led_matrix_process():378 while True:379 try:380 _led_matrix_process()381 except Exception as e:382 print("ERROR : " + str(e))383 except:
...
_pyautogui_x11.py
Source:_pyautogui_x11.py
1# NOTE - It is a known issue that the keyboard-related functions don't work on Ubuntu VMs in Virtualbox.2import pyautogui3import sys4from Xlib.display import Display5from Xlib import X6from Xlib.ext.xtest import fake_input7import Xlib.XK8BUTTON_NAME_MAPPING = {'left': 1, 'middle': 2, 'right': 3, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7}9if sys.platform in ('java', 'darwin', 'win32'):10 raise Exception('The pyautogui_x11 module should only be loaded on a Unix system that supports X11.')11#from pyautogui import *12"""13Much of this code is based on information gleaned from Paul Barton's PyKeyboard in PyUserInput from 2013, itself derived from Akkana Peck's pykey in 2008 ( http://www.shallowsky.com/software/crikey/pykey-0.1 ), itself derived from her "Crikey" lib.14"""15def _position():16 coord = _display.screen().root.query_pointer()._data17 return coord["root_x"], coord["root_y"]18def _size():19 return _display.screen().width_in_pixels, _display.screen().height_in_pixels20def _vscroll(clicks, x=None, y=None):21 clicks = int(clicks)22 if clicks == 0:23 return24 elif clicks > 0:25 button = 4 # scroll up26 else:27 button = 5 # scroll down28 for i in range(abs(clicks)):29 _click(x, y, button=button)30def _hscroll(clicks, x=None, y=None):31 clicks = int(clicks)32 if clicks == 0:33 return34 elif clicks > 0:35 button = 7 # scroll right36 else:37 button = 6 # scroll left38 for i in range(abs(clicks)):39 _click(x, y, button=button)40def _scroll(clicks, x=None, y=None):41 return _vscroll(clicks, x, y)42def _click(x, y, button):43 assert button in BUTTON_NAME_MAPPING.keys(), "button argument not in ('left', 'middle', 'right', 4, 5, 6, 7)"44 button = BUTTON_NAME_MAPPING[button]45 _mouseDown(x, y, button)46 _mouseUp(x, y, button)47def _moveTo(x, y):48 fake_input(_display, X.MotionNotify, x=x, y=y)49 _display.sync()50def _mouseDown(x, y, button):51 _moveTo(x, y)52 assert button in BUTTON_NAME_MAPPING.keys(), "button argument not in ('left', 'middle', 'right', 4, 5, 6, 7)"53 button = BUTTON_NAME_MAPPING[button]54 fake_input(_display, X.ButtonPress, button)55 _display.sync()56def _mouseUp(x, y, button):57 _moveTo(x, y)58 assert button in BUTTON_NAME_MAPPING.keys(), "button argument not in ('left', 'middle', 'right', 4, 5, 6, 7)"59 button = BUTTON_NAME_MAPPING[button]60 fake_input(_display, X.ButtonRelease, button)61 _display.sync()62def _keyDown(key):63 """Performs a keyboard key press without the release. This will put that64 key in a held down state.65 NOTE: For some reason, this does not seem to cause key repeats like would66 happen if a keyboard key was held down on a text field.67 Args:68 key (str): The key to be pressed down. The valid names are listed in69 pyautogui.KEY_NAMES.70 Returns:71 None72 """73 if key not in keyboardMapping or keyboardMapping[key] is None:74 return75 if type(key) == int:76 fake_input(_display, X.KeyPress, key)77 _display.sync()78 return79 needsShift = pyautogui.isShiftCharacter(key)80 if needsShift:81 fake_input(_display, X.KeyPress, keyboardMapping['shift'])82 fake_input(_display, X.KeyPress, keyboardMapping[key])83 if needsShift:84 fake_input(_display, X.KeyRelease, keyboardMapping['shift'])85 _display.sync()86def _keyUp(key):87 """Performs a keyboard key release (without the press down beforehand).88 Args:89 key (str): The key to be released up. The valid names are listed in90 pyautogui.KEY_NAMES.91 Returns:92 None93 """94 """95 Release a given character key. Also works with character keycodes as96 integers, but not keysyms.97 """98 if key not in keyboardMapping or keyboardMapping[key] is None:99 return100 if type(key) == int:101 keycode = key102 else:103 keycode = keyboardMapping[key]104 fake_input(_display, X.KeyRelease, keycode)105 _display.sync()106# Taken from PyKeyboard's ctor function.107_display = Display(None) # TODO - Display() can have other values passed to it. Implement that later.108""" Information for keyboardMapping derived from PyKeyboard's special_key_assignment() function.109The *KB dictionaries in pyautogui map a string that can be passed to keyDown(),110keyUp(), or press() into the code used for the OS-specific keyboard function.111They should always be lowercase, and the same keys should be used across all OSes."""112keyboardMapping = {key: None for key in pyautogui.KEY_NAMES}113keyboardMapping.update({114 'back': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('BackSpace')),115 'backspace': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('BackSpace')),116 '\b': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('BackSpace')),117 'tab': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Tab')),118 'enter': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Return')),119 'return': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Return')),120 'shift': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Shift_L')),121 'ctrl': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Control_L')),122 'alt': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Alt_L')),123 'pause': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Pause')),124 'capslock': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Caps_Lock')),125 'esc': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Escape')),126 'escape': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Escape')),127 'pgup': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Page_Up')),128 'pgdn': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Page_Down')),129 'pageup': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Page_Up')),130 'pagedown': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Page_Down')),131 'end': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('End')),132 'home': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Home')),133 'left': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Left')),134 'up': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Up')),135 'right': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Right')),136 'down': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Down')),137 'select': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Select')),138 'print': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Print')),139 'execute': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Execute')),140 'prtsc': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Print')),141 'prtscr': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Print')),142 'prntscrn': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Print')),143 'printscreen': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Print')),144 'insert': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Insert')),145 'del': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Delete')),146 'delete': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Delete')),147 'help': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Help')),148 'winleft': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Super_L')),149 'winright': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Super_R')),150 'apps': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Super_L')),151 'num0': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_0')),152 'num1': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_1')),153 'num2': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_2')),154 'num3': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_3')),155 'num4': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_4')),156 'num5': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_5')),157 'num6': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_6')),158 'num7': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_7')),159 'num8': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_8')),160 'num9': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_9')),161 'multiply': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Multiply')),162 'add': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Add')),163 'separator': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Separator')),164 'subtract': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Subtract')),165 'decimal': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Decimal')),166 'divide': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('KP_Divide')),167 'f1': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F1')),168 'f2': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F2')),169 'f3': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F3')),170 'f4': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F4')),171 'f5': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F5')),172 'f6': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F6')),173 'f7': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F7')),174 'f8': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F8')),175 'f9': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F9')),176 'f10': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F10')),177 'f11': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F11')),178 'f12': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F12')),179 'f13': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F13')),180 'f14': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F14')),181 'f15': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F15')),182 'f16': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F16')),183 'f17': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F17')),184 'f18': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F18')),185 'f19': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F19')),186 'f20': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F20')),187 'f21': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F21')),188 'f22': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F22')),189 'f23': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F23')),190 'f24': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('F24')),191 'numlock': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Num_Lock')),192 'scrolllock': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Scroll_Lock')),193 'shiftleft': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Shift_L')),194 'shiftright': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Shift_R')),195 'ctrlleft': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Control_L')),196 'ctrlright': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Control_R')),197 'altleft': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Alt_L')),198 'altright': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Alt_R')),199 # These are added because unlike a-zA-Z0-9, the single characters do not have a200 ' ': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('space')),201 'space': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('space')),202 '\t': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Tab')),203 '\n': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Return')), # for some reason this needs to be cr, not lf204 '\r': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Return')),205 '\e': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Escape')),206 '!': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('exclam')),207 '#': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('numbersign')),208 '%': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('percent')),209 '$': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('dollar')),210 '&': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('ampersand')),211 '"': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('quotedbl')),212 "'": _display.keysym_to_keycode(Xlib.XK.string_to_keysym('apostrophe')),213 '(': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('parenleft')),214 ')': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('parenright')),215 '*': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('asterisk')),216 '=': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('equal')),217 '+': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('plus')),218 ',': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('comma')),219 '-': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('minus')),220 '.': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('period')),221 '/': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('slash')),222 ':': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('colon')),223 ';': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('semicolon')),224 '<': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('less')),225 '>': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('greater')),226 '?': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('question')),227 '@': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('at')),228 '[': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('bracketleft')),229 ']': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('bracketright')),230 '\\': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('backslash')),231 '^': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('asciicircum')),232 '_': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('underscore')),233 '`': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('grave')),234 '{': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('braceleft')),235 '|': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('bar')),236 '}': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('braceright')),237 '~': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('asciitilde')),238})239# Trading memory for time" populate winKB so we don't have to call VkKeyScanA each time.240for c in """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890""":...
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!!