Best JavaScript code snippet using wpt
Layout_Russian_Standard.py
Source:Layout_Russian_Standard.py
1#2# This layout implements a standard Russian ÐЦУÐÐÐ keyboard for use with Android3# Tested with AnySoftKeyboard4#56import struct78def printEncoded( f, s):9 f.write( s.encode(encoding="utf-8"))10 return111213def printKey( f, x, y, color):14 if color:15 printEncoded( f, "shape ( {:d}, {:d}, 35, 35,rectangle,3,000000,50505F)\n".format(40+x, 120+y))16 else:17 printEncoded( f, "shape ( {:d}, {:d}, 35, 35,rectangle,3,000000,FFFFFF)\n".format(40+x, 120+y))18 return192021class ArduinoKeyConverter():22 def __init__(self):23 self.conversion = [24 ("_NUL_", 0x00),25 ("_MODE0_", 0x01),26 ("_MODE1_", 0x02),27 ("_MODE2_", 0x03),28 ("_MODE3_", 0x04),29 ("_MODE4_", 0x05),30 ("_MODE5_", 0x06),31 ("_MODE6_", 0x07),32 ("_MODE7_", 0x08),33 ("_MODE8_", 0x09),34 ("_MODE9_", 0x0A),35 ("_RUSLAT_", 0x0B),36 ("_DELAY_", 0x0C),37 ("_DISABLE_", 0x0D),38 ("_ENABLE_", 0x0E),39 ("_RELEASE_", 0x0F),40 ("_LEFT_CTRL_", 0x80),41 ("_LEFT_SHIFT_", 0x81),42 ("_LEFT_ALT_", 0x82),43 ("_LEFT_GUI_", 0x83),44 ("_RIGHT_CTRL_", 0x84),45 ("_RIGHT_SHIFT_", 0x85),46 ("_RIGHT_ALT_", 0x86),47 ("_RIGHT_GUI_", 0x87),48 ("_UP_ARROW_", 0xDA),49 ("_DOWN_ARROW_", 0xD9),50 ("_LEFT_ARROW_", 0xD8),51 ("_RIGHT_ARROW_", 0xD7),52 ("_BACKSPACE_", 0xB2),53 ("_TAB_", 0xB3),54 ("_RETURN_", 0xB0),55 ("_ESC_", 0xB1),56 ("_INSERT_", 0xD1),57 ("_DELETE_", 0xD4),58 ("_PAGE_UP_", 0xD3),59 ("_PAGE_DOWN_", 0xD6),60 ("_HOME_", 0xD2),61 ("_END_", 0xD5),62 ("_CAPS_LOCK_", 0xC1),63 ("_F1_", 0xC2),64 ("_F2_", 0xC3),65 ("_F3_", 0xC4),66 ("_F4_", 0xC5),67 ("_F5_", 0xC7),68 ("_F7_", 0xC8),69 ("_F8_", 0xC9),70 ("_F9_", 0xCA),71 ("_F10_", 0xCB),72 ("_F11_", 0xCC),73 ("_F12_", 0xCD)]74 return75 def StartsWithMeta( self, s):76 self.meta = None77 for t in self.conversion:78 if not s.startswith( t[0]): continue79 self.meta = t80 return True81 return False82 def ConvertString( self, s):83 tmp = []84 while(len(s)):85 if self.StartsWithMeta(s):86 tmp += [self.meta[1]]87 s = s[len(self.meta[0]):]88 continue89 tmp += [(bytearray( s[:1], encoding="UTF-8"))[0]]90 s = s[1:]91 tmp += [0]92 return tmp93 def __str__(self):94 s = ""95 for t in self.conversion:96 s += "#define {:s}\t\t\t0x{:02x}\n".format(t[0], t[1])97 return s9899class EALIOR_Key():100 def __init__( self, code, mode, nominal, keysequence):101 self.Code = code # 0-59102 self.Mode = mode # 0-9103 self.Index = code*10 + mode104 self.Nominal = nominal105 self.Border = 0106 self.Address = 0107 self.Keysequence = keysequence108 return109 def __str__(self):110 s = ""111 for b in self.Keysequence:112 s += "0x{:02x},".format(b)113 return s[:-1]114 def makeDefinitionFile(self, f, mode):115 if mode != self.Mode: return116 n = self.Code117 nx = self.Code % 8118 ny = self.Code // 8119 printKey( f, nx*140, ny*200, n % 2)120 printKey( f, nx*140, ny*200+40, (n//2) % 2)121 printKey( f, nx*140, ny*200+80, (n//4) % 2)122 printKey( f, nx*140+40, ny*200, (n//8) % 2)123 printKey( f, nx*140+40, ny*200+40, (n//16) % 2)124 printKey( f, nx*140+40, ny*200+80, (n//32) % 2)125 if len( self.Nominal) < 1:126 printEncoded( f, "\n")127 return128 if len( self.Nominal) < 4:129 printEncoded( f, "label ( {:d},{:d},{:d},35,nana,20,000000,FFFFFF)\n".format(nx*140+40, ny*200+240, len(self.Nominal)*18+20))130 else:131 printEncoded( f, "label ( {:d},{:d},{:d},30,nana,14,000000,FFFFFF)\n".format(nx*140+40, ny*200+240+2, len(self.Nominal)*14+20))132 print( self.Mode, self.Code)133 printEncoded( f, "\tlSize = {:d}\n".format(self.Border))134 printEncoded( f, "\ttext ={:s}\n".format(self.Nominal))135 printEncoded( f, "\n")136 return137138class EALIOR_Keyboard():139 def __init__( self):140 self.Converter = ArduinoKeyConverter()141 self.Keys = []142 self.ByteSequence = []143 self.AddressSequence = bytearray( 1280)144 return145146 def __str__(self):147 lc = 0148 s = "const byte _EALIOR_Mantras[] PROGMEM = {\n\t"149 for b in self.ByteSequence:150 s += "0x{:02x},".format(b)151 lc += 1152 if lc >= 20:153 s += "\n\t"154 lc = 0155 if lc == 0: s = s[:-2]156 s = s[:-1] + "};\n\n"157 lc = 0158 s += "const byte _EALIOR_Addresses[] PROGMEM = {\n\t"159 for b in self.AddressSequence:160 s += "0x{:02x},".format(b)161 lc += 1162 if lc >= 20:163 s += "\n\t"164 lc = 0165 if lc == 0: s = s[:-2]166 s = s[:-1] + "};\n"167 return s168169 def appendKey( self, code, mode, nominal, keysequence, border=0):170 k = EALIOR_Key( code, mode, nominal,171 self.Converter.ConvertString(keysequence))172 k.Border = border173 index = bytes(self.ByteSequence).find(bytes(k.Keysequence))174 if index >= 0:175 k.Address = index176 else:177 k.Address = len( self.ByteSequence)178 self.ByteSequence += k.Keysequence179 self.Keys += [k]180 struct.pack_into(">H", self.AddressSequence, k.Index*2, k.Address)181 return182183 def makeDefinitionFile(self, f, name, mode):184 printEncoded( f, "################################################\n")185 printEncoded( f, "# #\n")186 printEncoded( f, "# Chorded keyboard layout: {:15s} #\n".format(name))187 printEncoded( f, "# #\n")188 printEncoded( f, "################################################\n")189 printEncoded( f, "#\n")190 printEncoded( f, "slide ({:s},1240,1753,png+pdf,FFFFFFFF,21.01,29.69,150)\n".format(name.strip().replace(" ", "_")))191 printEncoded( f, "label (170,40,900,80,none,24)\n")192 printEncoded( f, "\tText={:s}\n".format(name))193 printEncoded( f, "\tfStyle=bold\n")194 printEncoded( f, "\tlSize=0\n")195 printEncoded( f, "\ttPosition=center\n")196 printEncoded( f, "\n")197 for k in self.Keys:198 k.makeDefinitionFile( f, mode)199 return200201ek = EALIOR_Keyboard()202203# Mode 0 - Latin Normal204mode = 0205ek.appendKey( 0, mode, "none", "", 2)206ek.appendKey( 1, mode, "e", "e")207ek.appendKey( 2, mode, "a", "a")208ek.appendKey( 3, mode, "t", "t")209ek.appendKey( 4, mode, "l", "l")210ek.appendKey( 5, mode, "p", "p")211ek.appendKey( 6, mode, "s", "s")212ek.appendKey( 7, mode, "backspace", "_BACKSPACE_", 2)213214ek.appendKey( 8, mode, "i", "i")215ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)216ek.appendKey( 10, mode, "j", "j")217ek.appendKey( 11, mode, "v", "v")218ek.appendKey( 12, mode, "u", "u")219ek.appendKey( 13, mode, "sh", "sh")220ek.appendKey( 14, mode, "b", "b")221ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)222223ek.appendKey( 16, mode, "o", "o")224ek.appendKey( 17, mode, "m", "m")225ek.appendKey( 18, mode, "return", "_RETURN_", 2)226ek.appendKey( 19, mode, "w", "w")227ek.appendKey( 20, mode, ",", ",_DELAY_ ")228ek.appendKey( 21, mode, "ch", "ch")229ek.appendKey( 22, mode, "c", "c")230ek.appendKey( 23, mode, "selâ", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)231232ek.appendKey( 24, mode, "n", "n")233ek.appendKey( 25, mode, "g", "g")234ek.appendKey( 26, mode, "q", "q")235ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)236ek.appendKey( 28, mode, "and", "and")237ek.appendKey( 29, mode, "or", "or")238ek.appendKey( 30, mode, "?", "_MODE1_?_DELAY_ ")239ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)240241ek.appendKey( 32, mode, "r", "r")242ek.appendKey( 33, mode, "d", "d")243ek.appendKey( 34, mode, ".", "_MODE1_._DELAY_ ")244ek.appendKey( 35, mode, "z", "z")245ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)246ek.appendKey( 37, mode, "-", "-")247ek.appendKey( 38, mode, "k", "k")248ek.appendKey( 39, mode, "end ", "_END_", 2)249250ek.appendKey( 40, mode, "y", "y")251ek.appendKey( 41, mode, "you", "you")252ek.appendKey( 42, mode, "th", "th")253ek.appendKey( 43, mode, "selâ", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)254ek.appendKey( 44, mode, "the", "the")255ek.appendKey( 45, mode, " del", "_DELETE_", 2)256ek.appendKey( 46, mode, "selâ", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)257ek.appendKey( 47, mode, "copy", "_LEFT_CTRL_c_RELEASE_", 2)258259ek.appendKey( 48, mode, "h", "h")260ek.appendKey( 49, mode, "f", "f")261ek.appendKey( 50, mode, "x", "x")262ek.appendKey( 51, mode, "!", "_MODE1_!_DELAY_ ")263ek.appendKey( 52, mode, '""', '""_DELAY__LEFT_ARROW_')264ek.appendKey( 53, mode, "#", "#")265ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)266ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)267268ek.appendKey( 56, mode, "space", " ", 2)269ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)270ek.appendKey( 58, mode, "sel.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)271ek.appendKey( 59, mode, "wordâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)272ek.appendKey( 60, mode, "home", "_HOME_", 2)273ek.appendKey( 61, mode, "paste", "_LEFT_CTRL_v_RELEASE_", 2)274ek.appendKey( 62, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)275ek.appendKey( 63, mode, "âRUS", "_RUSLAT__MODE5_", 2)276277# Mode 1 - Latin Shifted278mode = 1279ek.appendKey( 0, mode, "none", "", 2)280ek.appendKey( 1, mode, "E", "_MODE0_E")281ek.appendKey( 2, mode, "A", "_MODE0_A")282ek.appendKey( 3, mode, "T", "_MODE0_T")283ek.appendKey( 4, mode, "L", "_MODE0_L")284ek.appendKey( 5, mode, "P", "_MODE0_P")285ek.appendKey( 6, mode, "S", "_MODE0_S")286ek.appendKey( 7, mode, "backspace", "_BACKSPACE_", 2)287288ek.appendKey( 8, mode, "I", "_MODE0_I")289ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)290ek.appendKey( 10, mode, "J", "_MODE0_J")291ek.appendKey( 11, mode, "V", "_MODE0_V")292ek.appendKey( 12, mode, "U", "_MODE0_U")293ek.appendKey( 13, mode, "Sh", "_MODE0_Sh")294ek.appendKey( 14, mode, "B", "_MODE0_B")295ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)296297ek.appendKey( 16, mode, "O", "_MODE0_O")298ek.appendKey( 17, mode, "M", "_MODE0_M")299ek.appendKey( 18, mode, "return", "_RETURN_", 2)300ek.appendKey( 19, mode, "W", "_MODE0_W")301ek.appendKey( 20, mode, ";", "_MODE0_;_DELAY_ ")302ek.appendKey( 21, mode, "Ch", "_MODE0_Ch")303ek.appendKey( 22, mode, "C", "_MODE0_C")304ek.appendKey( 23, mode, "selâ", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)305306ek.appendKey( 24, mode, "N", "_MODE0_N")307ek.appendKey( 25, mode, "G", "_MODE0_G")308ek.appendKey( 26, mode, "Q", "_MODE0_Q")309ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)310ek.appendKey( 28, mode, "And", "_MODE0_And")311ek.appendKey( 29, mode, "Or", "_MODE0_Or")312ek.appendKey( 30, mode, "?", "?_DELAY_ ")313ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)314315ek.appendKey( 32, mode, "R", "_MODE0_R")316ek.appendKey( 33, mode, "D", "_MODE0_D")317ek.appendKey( 34, mode, ":", "_MODE0_:_DELAY_ ")318ek.appendKey( 35, mode, "Z", "_MODE0_Z")319ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)320ek.appendKey( 37, mode, "_", "_MODE0__")321ek.appendKey( 38, mode, "K", "_MODE0_K")322ek.appendKey( 39, mode, "end ", "_END_", 2)323324ek.appendKey( 40, mode, "Y", "_MODE0_Y")325ek.appendKey( 41, mode, "You", "_MODE0_You")326ek.appendKey( 42, mode, "Th", "_MODE0_Th")327ek.appendKey( 43, mode, "selâ", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)328ek.appendKey( 44, mode, "The", "_MODE0_The")329ek.appendKey( 45, mode, " del", "_DELETE_", 2)330ek.appendKey( 46, mode, "selâ", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)331ek.appendKey( 47, mode, "copy", "_LEFT_CTRL_c_RELEASE_", 2)332333ek.appendKey( 48, mode, "H", "_MODE0_H")334ek.appendKey( 49, mode, "F", "_MODE0_F")335ek.appendKey( 50, mode, "X", "_MODE0_X")336ek.appendKey( 51, mode, "!", "!_DELAY_ ")337ek.appendKey( 52, mode, "'", "_MODE0_'")338ek.appendKey( 53, mode, "#", "_MODE3_#")339ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)340ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)341342ek.appendKey( 56, mode, "space", " ", 2)343ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)344ek.appendKey( 58, mode, "sel.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)345ek.appendKey( 59, mode, "wordâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)346ek.appendKey( 60, mode, "home", "_HOME_", 2)347ek.appendKey( 61, mode, "paste", "_LEFT_CTRL_v_RELEASE_", 2)348ek.appendKey( 62, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)349ek.appendKey( 63, mode, "âRUS", "_RUSLAT__MODE6_", 2)350351# Mode 2 - Latin CAPS352mode = 2353ek.appendKey( 0, mode, "none", "", 2)354ek.appendKey( 1, mode, "E", "E")355ek.appendKey( 2, mode, "A", "A")356ek.appendKey( 3, mode, "T", "T")357ek.appendKey( 4, mode, "L", "L")358ek.appendKey( 5, mode, "P", "P")359ek.appendKey( 6, mode, "S", "S")360ek.appendKey( 7, mode, "backspace", "_BACKSPACE_", 2)361362ek.appendKey( 8, mode, "I", "I")363ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)364ek.appendKey( 10, mode, "J", "J")365ek.appendKey( 11, mode, "V", "V")366ek.appendKey( 12, mode, "U", "U")367ek.appendKey( 13, mode, "SH", "SH")368ek.appendKey( 14, mode, "B", "B")369ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)370371ek.appendKey( 16, mode, "O", "O")372ek.appendKey( 17, mode, "M", "M")373ek.appendKey( 18, mode, "return", "_RETURN_", 2)374ek.appendKey( 19, mode, "W", "W")375ek.appendKey( 20, mode, ",", ",_DELAY_ ")376ek.appendKey( 21, mode, "CH", "CH")377ek.appendKey( 22, mode, "C", "C")378ek.appendKey( 23, mode, "selâ", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)379380ek.appendKey( 24, mode, "N", "N")381ek.appendKey( 25, mode, "G", "G")382ek.appendKey( 26, mode, "Q", "Q")383ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)384ek.appendKey( 28, mode, "AND", "AND")385ek.appendKey( 29, mode, "OR", "OR")386ek.appendKey( 30, mode, "?", "?_DELAY_ ")387ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)388389ek.appendKey( 32, mode, "R", "R")390ek.appendKey( 33, mode, "D", "D")391ek.appendKey( 34, mode, ".", "._DELAY_ ")392ek.appendKey( 35, mode, "Z", "Z")393ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)394ek.appendKey( 37, mode, "-", "-")395ek.appendKey( 38, mode, "K", "K")396ek.appendKey( 39, mode, "end ", "_END_", 2)397398ek.appendKey( 40, mode, "Y", "Y")399ek.appendKey( 41, mode, "YOU", "YOU")400ek.appendKey( 42, mode, "TH", "TH")401ek.appendKey( 43, mode, "selâ", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)402ek.appendKey( 44, mode, "THE", "THE")403ek.appendKey( 45, mode, " del", "_DELETE_", 2)404ek.appendKey( 46, mode, "selâ", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)405ek.appendKey( 47, mode, "copy", "_LEFT_CTRL_c_RELEASE_", 2)406407ek.appendKey( 48, mode, "H", "H")408ek.appendKey( 49, mode, "F", "F")409ek.appendKey( 50, mode, "X", "X")410ek.appendKey( 51, mode, "!", "! ")411ek.appendKey( 52, mode, '""', '""_DELAY__LEFT_ARROW_')412ek.appendKey( 53, mode, "#", "#")413ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)414ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)415416ek.appendKey( 56, mode, "space", " ", 2)417ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)418ek.appendKey( 58, mode, "sel.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)419ek.appendKey( 59, mode, "wordâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)420ek.appendKey( 60, mode, "home", "_HOME_", 2)421ek.appendKey( 61, mode, "paste", "_LEFT_CTRL_v_RELEASE_", 2)422ek.appendKey( 62, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)423ek.appendKey( 63, mode, "âRUS", "_RUSLAT__MODE7_", 2)424425# Mode 3 - Latin Numbers426mode = 3427ek.appendKey( 0, mode, "none", "", 2)428ek.appendKey( 1, mode, "1", "_MODE0_1")429ek.appendKey( 2, mode, "2", "_MODE0_2")430ek.appendKey( 3, mode, "+", "_MODE0_+")431ek.appendKey( 4, mode, "3", "_MODE0_3")432ek.appendKey( 5, mode, "()", "_MODE0_()_LEFT_ARROW_")433ek.appendKey( 6, mode, "=", "_MODE0_=")434ek.appendKey( 7, mode, "backspace", "_BACKSPACE_", 2)435436ek.appendKey( 8, mode, "4", "_MODE0_4")437ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)438ek.appendKey( 10, mode, "|", "_MODE0_|")439ek.appendKey( 11, mode, "-", "-")440ek.appendKey( 12, mode, "%", "_MODE0_%")441ek.appendKey( 13, mode, "[]", "_MODE0_[]_DELAY__LEFT_ARROW_")442ek.appendKey( 14, mode, "<", "_MODE0_<")443ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)444445ek.appendKey( 16, mode, "5", "_MODE0_5")446ek.appendKey( 17, mode, "&", "_MODE0_&")447ek.appendKey( 18, mode, "return", "_RETURN_", 2)448ek.appendKey( 19, mode, "/", "_MODE0_/")449ek.appendKey( 20, mode, ",", "_MODE0_,")450ek.appendKey( 21, mode, "{}", "_MODE0_{}_DELAY__LEFT_ARROW_")451ek.appendKey( 22, mode, ">", "_MODE0_>")452ek.appendKey( 23, mode, "selâ", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)453454ek.appendKey( 24, mode, "0", "_MODE0_0")455ek.appendKey( 25, mode, "7", "_MODE0_7")456ek.appendKey( 26, mode, "8", "_MODE0_8")457ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)458ek.appendKey( 28, mode, "9", "_MODE0_9")459ek.appendKey( 29, mode, "</>", "_MODE0_</>_DELAY__LEFT_ARROW__LEFT_ARROW_")460ek.appendKey( 30, mode, "$", "_MODE0_$")461ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)462463ek.appendKey( 32, mode, "6", "_MODE0_6")464ek.appendKey( 33, mode, "^", "_MODE0_^")465ek.appendKey( 34, mode, ".", "_MODE0_.")466ek.appendKey( 35, mode, "*", "_MODE0_*")467ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)468ek.appendKey( 37, mode, "_", "_MODE0__")469ek.appendKey( 38, mode, "%", "_MODE0_%")470ek.appendKey( 39, mode, "end ", "_END_", 2)471472ek.appendKey( 40, mode, "esc ", "_ESC_", 2)473ek.appendKey( 41, mode, "SoftKbd", "_MODE0__DISABLE_", 2)474ek.appendKey( 42, mode, "`", "_MODE0_`")475ek.appendKey( 43, mode, "selâ", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)476ek.appendKey( 44, mode, "~", "_MODE0_~")477ek.appendKey( 45, mode, " del", "_DELETE_", 2)478ek.appendKey( 46, mode, "selâ", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)479ek.appendKey( 47, mode, " cut", "_MODE0__LEFT_CTRL_x_RELEASE_", 2)480481ek.appendKey( 48, mode, "e", "e")482ek.appendKey( 49, mode, ">", ">")483ek.appendKey( 50, mode, "~", "_MODE0_~")484ek.appendKey( 51, mode, "|", "_MODE0_|")485ek.appendKey( 52, mode, "`", "_MODE0_`")486ek.appendKey( 53, mode, "#", "_MODE0_#")487ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)488ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)489490ek.appendKey( 56, mode, "tab ", "_TAB_", 2)491ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)492ek.appendKey( 58, mode, "sel.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)493ek.appendKey( 59, mode, "wordâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)494ek.appendKey( 60, mode, "top", "_MODE0__LEFT_CTRL__HOME__RELEASE_", 2)495ek.appendKey( 61, mode, "undo", "_MODE0__LEFT_CTRL_z_RELEASE_", 2)496ek.appendKey( 62, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)497ek.appendKey( 63, mode, "RUS synch.", "_RUSLAT__MODE0_", 2)498499500# Mode 4 - Latin NUMLOCK501mode = 4502ek.appendKey( 0, mode, "none", "", 2)503ek.appendKey( 1, mode, "1", "1")504ek.appendKey( 2, mode, "2", "2")505ek.appendKey( 3, mode, "+", "+")506ek.appendKey( 4, mode, "3", "3")507ek.appendKey( 5, mode, "()", "()_DELAY__LEFT_ARROW_")508ek.appendKey( 6, mode, "=", "=")509ek.appendKey( 7, mode, "backspace", "_BACKSPACE_", 2)510511ek.appendKey( 8, mode, "4", "4")512ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)513ek.appendKey( 10, mode, "|", "|")514ek.appendKey( 11, mode, "-", "-")515ek.appendKey( 12, mode, "%", "%")516ek.appendKey( 13, mode, "[]", "[]_DELAY__LEFT_ARROW_")517ek.appendKey( 14, mode, "<", "<")518ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)519520ek.appendKey( 16, mode, "5", "5")521ek.appendKey( 17, mode, "&", "&")522ek.appendKey( 18, mode, "return", "_RETURN_", 2)523ek.appendKey( 19, mode, "/", "/")524ek.appendKey( 20, mode, ",", ",")525ek.appendKey( 21, mode, "{}", "{}_DELAY__LEFT_ARROW_")526ek.appendKey( 22, mode, ">", ">")527ek.appendKey( 23, mode, "selâ", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)528529ek.appendKey( 24, mode, "0", "0")530ek.appendKey( 25, mode, "7", "7")531ek.appendKey( 26, mode, "8", "8")532ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)533ek.appendKey( 28, mode, "9", "9")534ek.appendKey( 29, mode, "</>", "</>_DELAY__LEFT_ARROW__LEFT_ARROW_")535ek.appendKey( 30, mode, "$", "$")536ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)537538ek.appendKey( 32, mode, "6", "6")539ek.appendKey( 33, mode, "^", "^")540ek.appendKey( 34, mode, ".", ".")541ek.appendKey( 35, mode, "*", "*")542ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)543ek.appendKey( 37, mode, "_", "_")544ek.appendKey( 38, mode, "%", "%")545ek.appendKey( 39, mode, "end ", "_END_", 2)546547ek.appendKey( 40, mode, "esc ", "_ESC_", 2)548ek.appendKey( 41, mode, "undef", "", 2)549ek.appendKey( 42, mode, "`", "`")550ek.appendKey( 43, mode, "selâ", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)551ek.appendKey( 44, mode, "~", "~")552ek.appendKey( 45, mode, " del", "_DELETE_", 2)553ek.appendKey( 46, mode, "selâ", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)554ek.appendKey( 47, mode, "copy", "_MODE0__LEFT_CTRL_c_RELEASE_", 2)555556ek.appendKey( 48, mode, "e", "e")557ek.appendKey( 49, mode, ">", ">")558ek.appendKey( 50, mode, "~", "~")559ek.appendKey( 51, mode, "|", "|")560ek.appendKey( 52, mode, "`", "`")561ek.appendKey( 53, mode, "#", "#")562ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)563ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)564565ek.appendKey( 56, mode, "tab ", "_TAB_", 2)566ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)567ek.appendKey( 58, mode, "sel.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)568ek.appendKey( 59, mode, "wordâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)569ek.appendKey( 60, mode, "home", "_HOME_", 2)570ek.appendKey( 61, mode, "undo", "_LEFT_CTRL_z_RELEASE_", 2)571ek.appendKey( 62, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)572ek.appendKey( 63, mode, "âRUS", "_RUSLAT__MODE9_", 2)573574# Mode 5 - Russian Normal575mode = 5576ek.appendKey( 0, mode, "пÑÑÑой", "", 2)577ek.appendKey( 1, mode, "е", "t")578ek.appendKey( 2, mode, "а", "f")579ek.appendKey( 3, mode, "Ñ", "n")580ek.appendKey( 4, mode, "л", "k_LEFT_ARROW__RIGHT_ARROW_") # double k (л) is a ж (;:)581ek.appendKey( 5, mode, "п", "g")582ek.appendKey( 6, mode, "Ñ", "c")583ek.appendKey( 7, mode, "забой", "_BACKSPACE_", 2)584585ek.appendKey( 8, mode, "и", "b")586ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)587ek.appendKey( 10, mode, "й", "q")588ek.appendKey( 11, mode, "в", "d")589ek.appendKey( 12, mode, "Ñ", "e")590ek.appendKey( 13, mode, "Ñ", "i")591ek.appendKey( 14, mode, "б", ",_LEFT_ARROW__RIGHT_ARROW_")592ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)593594ek.appendKey( 16, mode, "о", "j")595ek.appendKey( 17, mode, "м", "v")596ek.appendKey( 18, mode, "ввод", "_RETURN_", 2)597ek.appendKey( 19, mode, "ж", ";")598ek.appendKey( 20, mode, ",", "_RUSLAT_,_DELAY_ _RUSLAT_")599ek.appendKey( 21, mode, "Ñ", "o_LEFT_ARROW__RIGHT_ARROW_")600ek.appendKey( 22, mode, "Ñ", "w")601ek.appendKey( 23, mode, "вÑд.â", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)602603ek.appendKey( 24, mode, "н", "y")604ek.appendKey( 25, mode, "г", "u")605ek.appendKey( 26, mode, "Ñ", "z")606ek.appendKey( 27, mode, "ÑÑÑâ", "_PAGE_UP_", 2)607ek.appendKey( 28, mode, "Ñ", "m")608ek.appendKey( 29, mode, "Ñ", "]")609ek.appendKey( 30, mode, "?", "_MODE6_&_DELAY_ ")610ek.appendKey( 31, mode, "Ñловоâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)611612ek.appendKey( 32, mode, "Ñ", "h")613ek.appendKey( 33, mode, "д", "l_LEFT_ARROW__RIGHT_ARROW_") # double д is Ñ614ek.appendKey( 34, mode, ".", "_MODE6_/_DELAY_ ")615ek.appendKey( 35, mode, "з", "p_LEFT_ARROW__RIGHT_ARROW_") # double з is Ñ616ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)617ek.appendKey( 37, mode, "-", "-")618ek.appendKey( 38, mode, "к", "r")619ek.appendKey( 39, mode, "конеÑ", "_END_", 2)620621ek.appendKey( 40, mode, "Ñ", "s")622ek.appendKey( 41, mode, "Ñ", ".")623ek.appendKey( 42, mode, "Ñ", "'")624ek.appendKey( 43, mode, "вÑд.â", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)625ek.appendKey( 44, mode, "Ñ", "`")626ek.appendKey( 45, mode, "Ñдал.", "_DELETE_", 2)627ek.appendKey( 46, mode, "вÑд.â", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)628ek.appendKey( 47, mode, "копиÑ.", "_RUSLAT__LEFT_CTRL_c_RELEASE__RUSLAT_", 2)629630ek.appendKey( 48, mode, "Ñ", "x")631ek.appendKey( 49, mode, "Ñ", "a")632ek.appendKey( 50, mode, "Ñ
", "[")633ek.appendKey( 51, mode, "!", "_MODE6_!_DELAY_ ")634ek.appendKey( 52, mode, '""', '@@_DELAY__LEFT_ARROW_')635ek.appendKey( 53, mode, "â", "#")636ek.appendKey( 54, mode, "ÑÑÑâ", "_PAGE_DOWN_", 2)637ek.appendKey( 55, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)638639ek.appendKey( 56, mode, "пÑобел", " ", 2)640ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)641ek.appendKey( 58, mode, "вÑд.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)642ek.appendKey( 59, mode, "Ñловоâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)643ek.appendKey( 60, mode, "наÑало", "_RUSLAT__HOME__RUSLAT_", 2)644ek.appendKey( 61, mode, "вÑÑав.", "_RUSLAT__LEFT_CTRL_v_RELEASE__RUSLAT_", 2)645ek.appendKey( 62, mode, "вÑд.Ñ.â", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)646ek.appendKey( 63, mode, "âLAT", "_RUSLAT__MODE0_", 2)647648# Mode 6 - Russian Shifted649mode = 6650ek.appendKey( 0, mode, "пÑÑÑой", "", 2)651ek.appendKey( 1, mode, "Ð", "_MODE5_T")652ek.appendKey( 2, mode, "Ð", "_MODE5_F")653ek.appendKey( 3, mode, "Т", "_MODE5_N")654ek.appendKey( 4, mode, "Ð", "_MODE5_K_DELAY__LEFT_ARROW__RIGHT_ARROW_") # double k (л) is a ж (;:)655ek.appendKey( 5, mode, "Ð", "_MODE5_G")656ek.appendKey( 6, mode, "С", "_MODE5_C")657ek.appendKey( 7, mode, "забой", "_BACKSPACE_", 2)658659ek.appendKey( 8, mode, "Ð", "_MODE5_B")660ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)661ek.appendKey( 10, mode, "Ð", "_MODE5_Q")662ek.appendKey( 11, mode, "Ð", "_MODE5_D")663ek.appendKey( 12, mode, "У", "_MODE5_E")664ek.appendKey( 13, mode, "Ш", "_MODE5_I")665ek.appendKey( 14, mode, "Ð", "_MODE5_<_DELAY__LEFT_ARROW__RIGHT_ARROW_")666ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)667668ek.appendKey( 16, mode, "Ð", "_MODE5_J")669ek.appendKey( 17, mode, "Ð", "_MODE5_V")670ek.appendKey( 18, mode, "ввод", "_RETURN_", 2)671ek.appendKey( 19, mode, "Ð", "_MODE5_:")672ek.appendKey( 20, mode, ";", "_MODE5_$ ")673ek.appendKey( 21, mode, "Щ", "_MODE5_O_DELAY__LEFT_ARROW__RIGHT_ARROW_")674ek.appendKey( 22, mode, "Ц", "_MODE5_W")675ek.appendKey( 23, mode, "вÑд.â", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)676677ek.appendKey( 24, mode, "Ð", "_MODE5_Y")678ek.appendKey( 25, mode, "Ð", "_MODE5_U")679ek.appendKey( 26, mode, "Я", "_MODE5_Z")680ek.appendKey( 27, mode, "ÑÑÑâ", "_PAGE_UP_", 2)681ek.appendKey( 28, mode, "Ь", "_MODE5_M")682ek.appendKey( 29, mode, "Ъ", "_MODE5_}")683ek.appendKey( 30, mode, "?", "&_DELAY_ ")684ek.appendKey( 31, mode, "Ñловоâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)685686ek.appendKey( 32, mode, "Ð ", "_MODE5_H")687ek.appendKey( 33, mode, "Ð", "_MODE5_L_LEFT_ARROW__RIGHT_ARROW_") # double д is Ñ688ek.appendKey( 34, mode, ":", "_MODE5__RUSLAT_:_DELAY_ _RUSLAT_")689ek.appendKey( 35, mode, "Ð", "_MODE5_P_LEFT_ARROW__RIGHT_ARROW_") # double з is Ñ690ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)691ek.appendKey( 37, mode, "_", "_MODE5__")692ek.appendKey( 38, mode, "Ð", "_MODE5_R")693ek.appendKey( 39, mode, "конеÑ", "_END_", 2)694695ek.appendKey( 40, mode, "Ы", "_MODE5_S")696ek.appendKey( 41, mode, "Ю", "_MODE5_>")697ek.appendKey( 42, mode, "Ð", '_MODE5_"')698ek.appendKey( 43, mode, "вÑд.â", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)699ek.appendKey( 44, mode, "Ð", "_MODE5_~")700ek.appendKey( 45, mode, "Ñдал.", "_DELETE_", 2)701ek.appendKey( 46, mode, "вÑд.â", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)702ek.appendKey( 47, mode, "вÑÑез.", "_MODE5__RUSLAT__LEFT_CTRL_x_RELEASE__RUSLAT_", 2)703704ek.appendKey( 48, mode, "Ч", "_MODE5_X")705ek.appendKey( 49, mode, "Ф", "_MODE5_A")706ek.appendKey( 50, mode, "Ð¥", "_MODE5_{")707ek.appendKey( 51, mode, "!", "!_DELAY_ ")708ek.appendKey( 52, mode, "'", "_MODE5__RUSLAT_'_RUSLAT_")709ek.appendKey( 53, mode, "â", "_MODE5_#")710ek.appendKey( 54, mode, "ÑÑÑâ", "_PAGE_DOWN_", 2)711ek.appendKey( 55, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)712713ek.appendKey( 56, mode, "пÑобел", " ", 2)714ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)715ek.appendKey( 58, mode, "вÑд.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)716ek.appendKey( 59, mode, "Ñловоâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)717ek.appendKey( 60, mode, "наÑало", "_RUSLAT__HOME__RUSLAT_", 2)718ek.appendKey( 61, mode, "вÑÑав.", "_RUSLAT__LEFT_CTRL_v_RELEASE__RUSLAT_", 2)719ek.appendKey( 62, mode, "вÑд.Ñ.â", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)720ek.appendKey( 63, mode, "âLAT", "_RUSLAT__MODE1_", 2)721722# Mode 7 - Russian CAPS723mode = 7724ek.appendKey( 0, mode, "пÑÑÑой", "", 2)725ek.appendKey( 1, mode, "Ð", "T")726ek.appendKey( 2, mode, "Ð", "F")727ek.appendKey( 3, mode, "Т", "N")728ek.appendKey( 4, mode, "Ð", "K_LEFT_ARROW__RIGHT_ARROW_") # double k (л) is a ж (;:)729ek.appendKey( 5, mode, "Ð", "G")730ek.appendKey( 6, mode, "С", "C")731ek.appendKey( 7, mode, "забой", "_BACKSPACE_", 2)732733ek.appendKey( 8, mode, "Ð", "B")734ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)735ek.appendKey( 10, mode, "Ð", "Q")736ek.appendKey( 11, mode, "Ð", "D")737ek.appendKey( 12, mode, "У", "E")738ek.appendKey( 13, mode, "Ш", "I")739ek.appendKey( 14, mode, "Ð", "<_LEFT_ARROW__RIGHT_ARROW_")740ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)741742ek.appendKey( 16, mode, "Ð", "J")743ek.appendKey( 17, mode, "Ð", "V")744ek.appendKey( 18, mode, "ввод", "_RETURN_", 2)745ek.appendKey( 19, mode, "Ð", ":")746ek.appendKey( 20, mode, ",", "_RUSLAT_,_DELAY_ _RUSLAT_")747ek.appendKey( 21, mode, "Щ", "O_LEFT_ARROW__RIGHT_ARROW_")748ek.appendKey( 22, mode, "Ц", "W")749ek.appendKey( 23, mode, "вÑд.â", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)750751ek.appendKey( 24, mode, "Ð", "Y")752ek.appendKey( 25, mode, "Ð", "U")753ek.appendKey( 26, mode, "Я", "Z")754ek.appendKey( 27, mode, "ÑÑÑâ", "_PAGE_UP_", 2)755ek.appendKey( 28, mode, "Ь", "M")756ek.appendKey( 29, mode, "Ъ", "}")757ek.appendKey( 30, mode, "?", "& ")758ek.appendKey( 31, mode, "Ñловоâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)759760ek.appendKey( 32, mode, "Ð ", "H")761ek.appendKey( 33, mode, "Ð", "L_LEFT_ARROW__RIGHT_ARROW_") # double д is Ñ762ek.appendKey( 34, mode, ".", "/ ")763ek.appendKey( 35, mode, "Ð", "P_LEFT_ARROW__RIGHT_ARROW_") # double з is Ñ764ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)765ek.appendKey( 37, mode, "-", "-")766ek.appendKey( 38, mode, "Ð", "R")767ek.appendKey( 39, mode, "конеÑ", "_END_", 2)768769ek.appendKey( 40, mode, "Ы", "S")770ek.appendKey( 41, mode, "Ю", ">")771ek.appendKey( 42, mode, "Ð", '"')772ek.appendKey( 43, mode, "вÑд.â", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)773ek.appendKey( 44, mode, "Ð", "~")774ek.appendKey( 45, mode, "Ñдал.", "_DELETE_", 2)775ek.appendKey( 46, mode, "вÑд.â", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)776ek.appendKey( 47, mode, "копиÑ.", "_RUSLAT__LEFT_CTRL_c_RELEASE__RUSLAT_", 2)777778ek.appendKey( 48, mode, "Ч", "X")779ek.appendKey( 49, mode, "Ф", "A")780ek.appendKey( 50, mode, "Ð¥", "{")781ek.appendKey( 51, mode, "!", "!_DELAY_ ")782ek.appendKey( 52, mode, '""', '@@_DELAY__LEFT_ARROW_')783ek.appendKey( 53, mode, "â", "#")784ek.appendKey( 54, mode, "ÑÑÑâ", "_PAGE_DOWN_", 2)785ek.appendKey( 55, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)786787ek.appendKey( 56, mode, "пÑобел", " ", 2)788ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)789ek.appendKey( 58, mode, "вÑд.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)790ek.appendKey( 59, mode, "Ñловоâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)791ek.appendKey( 60, mode, "наÑало", "_RUSLAT__HOME__RUSLAT_", 2)792ek.appendKey( 61, mode, "вÑÑав.", "_RUSLAT__LEFT_CTRL_v_RELEASE__RUSLAT_", 2)793ek.appendKey( 62, mode, "вÑд.Ñ.â", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)794ek.appendKey( 63, mode, "âLAT", "_RUSLAT__MODE2_", 2)795796# Mode 8 - Russian Numbers797mode = 8798ek.appendKey( 0, mode, "пÑÑÑой", "", 2)799ek.appendKey( 1, mode, "1", "_MODE5_1")800ek.appendKey( 2, mode, "2", "_MODE5_2")801ek.appendKey( 3, mode, "+", "_MODE5_+")802ek.appendKey( 4, mode, "3", "_MODE5_3")803ek.appendKey( 5, mode, "()", "_MODE5_()_DELAY__LEFT_ARROW_")804ek.appendKey( 6, mode, "=", "_MODE5_=")805ek.appendKey( 7, mode, "забой", "_BACKSPACE_", 2)806807ek.appendKey( 8, mode, "4", "_MODE5_4")808ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)809ek.appendKey( 10, mode, "|", "_MODE5_|")810ek.appendKey( 11, mode, "-", "-")811ek.appendKey( 12, mode, "%", "_MODE5_%")812ek.appendKey( 13, mode, "[]", "_MODE5__RUSLAT_[]_DELAY__LEFT_ARROW__RUSLAT_")813ek.appendKey( 14, mode, "<", "_MODE5__RUSLAT_<_RUSLAT_")814ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)815816ek.appendKey( 16, mode, "5", "_MODE5_5")817ek.appendKey( 17, mode, "&", "_MODE5_&")818ek.appendKey( 18, mode, "ввод", "_RETURN_", 2)819ek.appendKey( 19, mode, "/", "_MODE5_|")820ek.appendKey( 20, mode, ",", "_MODE5__RUSLAT_,_RUSLAT_")821ek.appendKey( 21, mode, "{}", "_MODE5__RUSLAT_{}_DELAY__LEFT_ARROW__RUSLAT_")822ek.appendKey( 22, mode, ">", "_MODE5__RUSLAT_>_RUSLAT_")823ek.appendKey( 23, mode, "вÑд.â", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)824825ek.appendKey( 24, mode, "0", "_MODE5_0")826ek.appendKey( 25, mode, "7", "_MODE5_7")827ek.appendKey( 26, mode, "8", "_MODE5_8")828ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)829ek.appendKey( 28, mode, "9", "_MODE5_9")830ek.appendKey( 29, mode, "</>", "_MODE5__RUSLAT_</>_RUSLAT__LEFT_ARROW__LEFT_ARROW_")831ek.appendKey( 30, mode, "$", "_MODE5_$")832ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)833834ek.appendKey( 32, mode, "6", "_MODE5_6")835ek.appendKey( 33, mode, "^", "_MODE5_^")836ek.appendKey( 34, mode, ".", "_MODE5_/")837ek.appendKey( 35, mode, "*", "_MODE5_*")838ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)839ek.appendKey( 37, mode, "_", "_MODE5__")840ek.appendKey( 38, mode, "%", "_MODE5_%")841ek.appendKey( 39, mode, "конеÑ", "_END_", 2)842843ek.appendKey( 40, mode, "ÐÑÑ
од", "_ESC_", 2)844ek.appendKey( 41, mode, "СоÑÑÐбд", "_MODE5__DISABLE_", 2)845ek.appendKey( 42, mode, "неопÑ.", "", 2)846ek.appendKey( 43, mode, "вÑд.â", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)847ek.appendKey( 44, mode, "~", "_MODE5__RUSLAT_~_RUSLAT_")848ek.appendKey( 45, mode, "Ñдал.", "_DELETE_", 2)849ek.appendKey( 46, mode, "вÑд.â", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)850ek.appendKey( 47, mode, "вÑÑез.", "_MODE5__RUSLAT__LEFT_CTRL_x_RELEASE__RUSLAT_", 2)851852ek.appendKey( 48, mode, "e", "_MODE5__RUSLAT_e_RUSLAT_")853ek.appendKey( 49, mode, ">", "_MODE5__RUSLAT_>_RUSLAT_")854ek.appendKey( 50, mode, "~", "_MODE5__RUSLAT_~_RUSLAT_")855ek.appendKey( 51, mode, "|", "_MODE5__RUSLAT_|_RUSLAT_")856ek.appendKey( 52, mode, "`", "_MODE5__RUSLAT_`_RUSLAT_")857ek.appendKey( 53, mode, "#", "_MODE5__RUSLAT_#_RUSLAT_")858ek.appendKey( 54, mode, "pgdn", "_PAGE_DOWN_", 2)859ek.appendKey( 55, mode, "selwâ", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_")860861ek.appendKey( 56, mode, "Ñаб ", "_MODE5__TAB_", 2)862ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)863ek.appendKey( 58, mode, "вÑд.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)864ek.appendKey( 59, mode, "Ñловоâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)865ek.appendKey( 60, mode, "наÑ.ÑекÑ.", "_MODE5__RUSLAT__LEFT_CTRL__HOME__RELEASE__RUSLAT_", 2)866ek.appendKey( 61, mode, "оÑмена", "_MODE5__RUSLAT__LEFT_CTRL_z_RELEASE__RUSLAT_", 2)867ek.appendKey( 62, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)868ek.appendKey( 63, mode, "LAT ÑинÑ
.", "_RUSLAT__MODE5_", 2)869870# Mode 9 - Russian NUMLOCK871mode = 9872ek.appendKey( 0, mode, "пÑÑÑой", "", 2)873ek.appendKey( 1, mode, "1", "1")874ek.appendKey( 2, mode, "2", "2")875ek.appendKey( 3, mode, "+", "+")876ek.appendKey( 4, mode, "3", "3")877ek.appendKey( 5, mode, "()", "()_LEFT_ARROW_")878ek.appendKey( 6, mode, "=", "=")879ek.appendKey( 7, mode, "забой", "_BACKSPACE_", 2)880881ek.appendKey( 8, mode, "4", "4")882ek.appendKey( 9, mode, " â ", "_UP_ARROW_", 2)883ek.appendKey( 10, mode, "|", "|")884ek.appendKey( 11, mode, "-", "-")885ek.appendKey( 12, mode, "%", "%")886ek.appendKey( 13, mode, "[]", "_RUSLAT_[]_DELAY__LEFT_ARROW__RUSLAT_")887ek.appendKey( 14, mode, "<", "_RUSLAT_<_RUSLAT_")888ek.appendKey( 15, mode, " â ", "_RIGHT_ARROW_", 2)889890ek.appendKey( 16, mode, "5", "5")891ek.appendKey( 17, mode, "&", "&")892ek.appendKey( 18, mode, "ввод", "_RETURN_", 2)893ek.appendKey( 19, mode, "/", "|")894ek.appendKey( 20, mode, ",", "_RUSLAT_,_RUSLAT_")895ek.appendKey( 21, mode, "{}", "_RUSLAT_{}_DELAY__LEFT_ARROW__RUSLAT_")896ek.appendKey( 22, mode, ">", "_RUSLAT_>_RUSLAT_")897ek.appendKey( 23, mode, "вÑд.â", "_LEFT_SHIFT__RIGHT_ARROW__RELEASE_", 2)898899ek.appendKey( 24, mode, "0", "0")900ek.appendKey( 25, mode, "7", "7")901ek.appendKey( 26, mode, "8", "8")902ek.appendKey( 27, mode, "pgup", "_PAGE_UP_", 2)903ek.appendKey( 28, mode, "9", "9")904ek.appendKey( 29, mode, "</>", "_RUSLAT_</>_DELAY__RUSLAT__LEFT_ARROW__LEFT_ARROW_")905ek.appendKey( 30, mode, "$", "$")906ek.appendKey( 31, mode, "wordâ", "_LEFT_CTRL__RIGHT_ARROW__RELEASE_", 2)907908ek.appendKey( 32, mode, "6", "6")909ek.appendKey( 33, mode, "^", "^")910ek.appendKey( 34, mode, ".", "/")911ek.appendKey( 35, mode, "*", "*")912ek.appendKey( 36, mode, " â ", "_DOWN_ARROW_", 2)913ek.appendKey( 37, mode, "_", "_")914ek.appendKey( 38, mode, "%", "%")915ek.appendKey( 39, mode, "конеÑ", "_END_", 2)916917ek.appendKey( 40, mode, "ÐÑÑ
од", "_ESC_", 2)918ek.appendKey( 41, mode, "неопÑ.", "", 2)919ek.appendKey( 42, mode, "неопÑ.", "", 2)920ek.appendKey( 43, mode, "вÑд.â", "_LEFT_SHIFT__UP_ARROW__RELEASE_", 2)921ek.appendKey( 44, mode, "~", "_RUSLAT_~_RUSLAT_")922ek.appendKey( 45, mode, "Ñдал.", "_DELETE_", 2)923ek.appendKey( 46, mode, "вÑд.â", "_LEFT_SHIFT__DOWN_ARROW__RELEASE_", 2)924ek.appendKey( 47, mode, "копиÑ.", "_RUSLAT__LEFT_CTRL_c_RELEASE__RUSLAT_", 2)925926ek.appendKey( 48, mode, "e", "_RUSLAT_e_RUSLAT_")927ek.appendKey( 49, mode, ">", "_RUSLAT_>_RUSLAT_")928ek.appendKey( 50, mode, "~", "_RUSLAT_~_RUSLAT_")929ek.appendKey( 51, mode, "|", "_RUSLAT_|_RUSLAT_")930ek.appendKey( 52, mode, "`", "_RUSLAT_`_RUSLAT_")931ek.appendKey( 53, mode, "#", "_RUSLAT_#_RUSLAT_")932ek.appendKey( 54, mode, "ÑÑÑâ", "_PAGE_DOWN_", 2)933ek.appendKey( 55, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__RIGHT_ARROW__RELEASE_")934935ek.appendKey( 56, mode, "Ñаб ", "_TAB_", 2)936ek.appendKey( 57, mode, " â ", "_LEFT_ARROW_", 2)937ek.appendKey( 58, mode, "вÑд.â", "_LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)938ek.appendKey( 59, mode, "Ñловоâ", "_LEFT_CTRL__LEFT_ARROW__RELEASE_", 2)939ek.appendKey( 60, mode, "наÑало", "_RUSLAT__HOME__RUSLAT_", 2)940ek.appendKey( 61, mode, "оÑмена", "_RUSLAT__LEFT_CTRL_z_RELEASE__RUSLAT_", 2)941ek.appendKey( 62, mode, "в.Ñл.â", "_LEFT_CTRL__LEFT_SHIFT__LEFT_ARROW__RELEASE_", 2)942ek.appendKey( 63, mode, "âLAT", "_RUSLAT__MODE4_", 2)943944f = open( "keymapRusStandard.h", "wt", encoding="UTF-8")945s = "{:s}".format(str(ek))946print(s)947f.write(s)948f.close()949950f = open( "./Layout_Russian_Standard/StandardRussian.def", "wb")951if True:952 ek.makeDefinitionFile( f, "ENGLISH NORMAL ", 0)953 ek.makeDefinitionFile( f, "ENGLISH SHIFTED", 1)954 ek.makeDefinitionFile( f, "ENGLISH CAPS ", 2)955 ek.makeDefinitionFile( f, "ENGLISH NUMBERS", 3)956 ek.makeDefinitionFile( f, "ENGLISH NUMLOCK", 4)957 ek.makeDefinitionFile( f, "RUSSIAN NORMAL ", 5)958 ek.makeDefinitionFile( f, "RUSSIAN SHIFTED", 6)959 ek.makeDefinitionFile( f, "RUSSIAN CAPS ", 7)960 ek.makeDefinitionFile( f, "RUSSIAN NUMBERS", 8)961 ek.makeDefinitionFile( f, "RUSSIAN NUMLOCK", 9)962 #print( ArduinoKeyConverter())
...
RoadCombat.py
Source:RoadCombat.py
1# Run this file to get everything working2# Keyboards are now supported (Be sure to press and hold when moving)3# Background Image found on https://entertainment.ie/gaming/pics-heres-the-real-life-locations-of-street-fighter-iis-stages-277425/4from my_cmu_112_graphics import *5from fighter import *6SCREEN_WIDTH = 6407SCREEN_HEIGHT = 3608class MyModalApp(ModalApp):9 def appStarted(app):10 # Set Up App11 app.splashScreen = SplashScreen()12 app.colorSelectSingle = ColorSelectSingle()13 app.colorSelctMulti = ColorSelectMulti()14 app.timerDelay = 115 fighter.screenWidth = app.width16 fighter.screenHeight = app.height17 app.colors = ["red", "green", "blue", "yellow", "cyan", "magenta"]18 app.colorPlayer1 = app.colorPlayer2 = random.sample(app.colors, 1)19 while app.colorPlayer2 == app.colorPlayer1:20 app.colorPlayer2 = random.sample(app.colors, 1)21 app.player1 = AI(app.width/3, app.colorPlayer1)22 app.player2 = AI(app.width*(2/3), app.colorPlayer2)23 # Keep this at the end24 app.setActiveMode(app.splashScreen)25class SplashScreen(Mode):26 def appStarted(mode):27 mode.count = 028 mode.timerDelay = 129 fighter.GRAVITY = -0.5 * mode.timerDelay30 fighter.FLOOR = mode.height - 2031 mode.app.player1.opponent = mode.app.player232 mode.app.player2.opponent = mode.app.player133 mode.limbWidth = body.LW34 mode.background = mode.loadImage("https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwOlxcXC9cXFwvczMtZXUtd2VzdC0xLmFtYXpvbmF3cy5jb21cXFwvZW50ZXJ0YWlubWVudGllXFxcL3N0b3JhZ2VcXFwvaW1hZ2VzX2NvbnRlbnRcXFwvcmVjdGFuZ2xlXFxcLzYyMHgzNzJcXFwvdW5uYW1lZDYyMDE2MTEzMTgxOTcwNS5qcGdcIixcIndpZHRoXCI6NjQwLFwiaGVpZ2h0XCI6Mzg0LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDgzYjBmNzVhNmY5YWViMTRmMjM1MjQxOTBhMGI5NWIyZDE0NjY4OCJ9/unnamed620161131819705.jpg")35 mode.background = ImageTk.PhotoImage(mode.background)36 37 def mousePressed(mode, event):38 if 3*mode.bH <= event.y <= 4*mode.bH:39 if mode.bW <= event.x <= 2*mode.bW:40 mode.app.setActiveMode(mode.app.colorSelectSingle)41 elif 3*mode.bW <= event.x <= 4*mode.bW:42 mode.app.setActiveMode(mode.app.colorSelctMulti)43 def timerFired(mode):44 mode.count += 145 fighter.applyGravity()46 for player in fighter._registry:47 player.health = fighter.startingHealth48 49 for i in range(len(fighter._registry)):50 fighter.threads[i] = threading.Thread(target=fighter._registry[i].getInput)51 fighter.threads[i].start()52 for i in range(len(fighter._registry)):53 fighter.threads[i].join()54 if mode.count % 66 == 0:55 fighter.updateFrames()56 def drawPlayers(mode, canvas):57 for player in fighter._registry:58 color = player.color59 # Draw Left Arm60 leftShoulderX, leftShoulderY = player.body.shoulderL61 leftElbowX, leftElbowY = player.body.elbowL62 leftHandX, lefthandY = player.body.handL63 canvas.create_line(leftShoulderX, leftShoulderY,64 leftElbowX, leftElbowY,65 fill=color, width=mode.limbWidth)66 canvas.create_line(leftElbowX, leftElbowY,67 leftHandX, lefthandY,68 fill=color, width=mode.limbWidth)69 # Draw Right Arm70 rightShoulderX, rightShoulderY = player.body.shoulderR71 rightElbowX, rightElbowY = player.body.elbowR72 rightHandX, rightHandY = player.body.handR73 canvas.create_line(rightShoulderX, rightShoulderY,74 rightElbowX, rightElbowY,75 fill=color, width=mode.limbWidth)76 canvas.create_line(rightElbowX, rightElbowY,77 rightHandX, rightHandY,78 fill=color, width=mode.limbWidth)79 # Draw Left Leg80 leftHipX, leftHipY = player.body.hipL81 leftKneeX, leftKneeY = player.body.kneeL82 leftHandX, leftFootY = player.body.footL83 canvas.create_line(leftHipX, leftHipY,84 leftKneeX, leftKneeY,85 fill=color, width=mode.limbWidth)86 canvas.create_line(leftKneeX, leftKneeY,87 leftHandX, leftFootY,88 fill=color, width=mode.limbWidth)89 # Draw Right Leg90 rightHipX, rightHipY = player.body.hipR91 rightKneeX, rightKneeY = player.body.kneeR92 rightHandX, rightFootY = player.body.footR93 canvas.create_line(rightHipX, rightHipY,94 rightKneeX, rightKneeY,95 fill=color, width=mode.limbWidth)96 canvas.create_line(rightKneeX, rightKneeY,97 rightHandX, rightFootY,98 fill=color, width=mode.limbWidth)99 # Draw the Torso100 # Done like this to allow for better animations in future101 canvas.create_polygon(player.body.shoulderL, player.body.shoulderR, 102 player.body.hipR, player.body.hipL, 103 fill=color, width=0)104 # Draw the Head105 x,y = player.body.head106 r = body.HR107 canvas.create_oval(x-r, y-r, x+r, y+r, fill=color, width=0)108 109 def drawBackground(mode, canvas):110 canvas.create_line(0, fighter.FLOOR, mode.width, fighter.FLOOR)111 def drawGameModes(mode, canvas):112 mode.bW = 128 # buttonWidth113 mode.bH = 72 # buttonHeight114 canvas.create_rectangle(mode.bW, 3*mode.bH, 2*mode.bW, 4*mode.bH, fill="white")115 canvas.create_text(1.5*mode.bW, 3.5*mode.bH, text="Singleplayer")116 canvas.create_rectangle(3*mode.bW, 3*mode.bH, 4*mode.bW, 4*mode.bH, fill="white")117 canvas.create_text(3.5*mode.bW, 3.5*mode.bH, text="Multiplayer")118 def redrawAll(mode, canvas):119 if mode.count % 66 > 0:120 return121 mode.app._canvas.delete(ALL)122 mode.drawBackground(canvas)123 mode.drawPlayers(canvas)124 mode.drawGameModes(canvas)125 canvas.create_text(mode.app.width/2, mode.app.height/4, text="Road Combat",126 font="arial 40 bold", fill="Black")127class ColorSelectSingle(Mode):128 def appStarted(mode):129 fighter._registry = []130 fighter.threads = []131 if X_input.checkControllers() > 0:132 mode.app.player1 = xbox(mode.app.width/3, 0, mode.app.colorPlayer1)133 else:134 mode.app.player1 = fighter(mode.app.width/3, mode.app.colorPlayer1)135 mode.app.player2 = AI(mode.app.width*(2/3), mode.app.colorPlayer2)136 def mousePressed(mode, event):137 if 120 <= event.y <= 200: 138 if 40 <= event.x <= 220: 139 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "red"140 while mode.app.colorPlayer2 == mode.app.colorPlayer1:141 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)142 mode.app.setActiveMode(Battle())143 if 230 <= event.x <= 410: 144 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "green"145 while mode.app.colorPlayer2 == mode.app.colorPlayer1:146 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)147 mode.app.setActiveMode(Battle())148 if 420 <= event.x <= 600: 149 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "blue"150 while mode.app.colorPlayer2 == mode.app.colorPlayer1:151 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)152 mode.app.setActiveMode(Battle())153 elif 220 <= event.y <= 300:154 if 40 <= event.x <= 220: 155 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "cyan"156 while mode.app.colorPlayer2 == mode.app.colorPlayer1:157 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)158 mode.app.setActiveMode(Battle())159 if 230 <= event.x <= 410: 160 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "yellow"161 while mode.app.colorPlayer2 == mode.app.colorPlayer1:162 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)163 mode.app.setActiveMode(Battle())164 if 420 <= event.x <= 600: 165 mode.app.colorPlayer2 = mode.app.colorPlayer1 = "magenta"166 while mode.app.colorPlayer2 == mode.app.colorPlayer1:167 mode.app.colorPlayer2 = random.sample(mode.app.colors, 1)168 mode.app.setActiveMode(Battle())169 def drawColors(mode, canvas):170 canvas.create_rectangle(40, 120, 220, 200, fill="red")171 canvas.create_rectangle(230, 120, 410, 200, fill="green")172 canvas.create_rectangle(420, 120, 600, 200, fill="blue")173 canvas.create_rectangle(40, 220, 220, 300, fill="cyan")174 canvas.create_rectangle(230, 220, 410, 300, fill="yellow")175 canvas.create_rectangle(420, 220, 600, 300, fill="magenta")176 def redrawAll(mode, canvas):177 mode.app._canvas.delete(ALL)178 canvas.create_text(mode.app.width/2, 80, text="Select Your Color", font="arial 30 bold")179 mode.drawColors(canvas)180class ColorSelectMulti(Mode):181 def appStarted(mode):182 fighter._registry = []183 fighter.threads = []184 numControllers = X_input.checkControllers()185 if numControllers > 0:186 mode.app.player1 = xbox(mode.app.width/3, 0, mode.app.colorPlayer1)187 if numControllers > 1:188 mode.app.player2 = xbox(mode.app.width*(2/3), 1, mode.app.colorPlayer2)189 else:190 mode.app.player2 = fighter(mode.app.width*(2/3), mode.app.colorPlayer2)191 else:192 print("No controllers detected")193 mode.app.setActiveMode(mode.app.colorSelectSingle)194 mode.playerSelect = "P1"195 def mousePressed(mode, event):196 if mode.playerSelect == "P1":197 if 120 <= event.y <= 200: 198 if 40 <= event.x <= 220: 199 mode.app.colorPlayer1 = "red"200 mode.playerSelect = "P2"201 if 230 <= event.x <= 410: 202 mode.app.colorPlayer1 = "green"203 mode.playerSelect = "P2"204 if 420 <= event.x <= 600: 205 mode.app.colorPlayer1 = "blue"206 mode.playerSelect = "P2"207 elif 220 <= event.y <= 300:208 if 40 <= event.x <= 220: 209 mode.app.colorPlayer1 = "cyan"210 mode.playerSelect = "P2"211 if 230 <= event.x <= 410: 212 mode.app.colorPlayer1 = "yellow"213 mode.playerSelect = "P2"214 if 420 <= event.x <= 600: 215 mode.app.colorPlayer1 = "magenta"216 mode.playerSelect = "P2"217 else:218 if 120 <= event.y <= 200: 219 if 40 <= event.x <= 220: 220 mode.app.colorPlayer2 = "red"221 mode.app.setActiveMode(Battle())222 if 230 <= event.x <= 410: 223 mode.app.colorPlayer2 = "green"224 mode.app.setActiveMode(Battle())225 if 420 <= event.x <= 600: 226 mode.app.colorPlayer2 = "blue"227 mode.app.setActiveMode(Battle())228 elif 220 <= event.y <= 300:229 if 40 <= event.x <= 220: 230 mode.app.colorPlayer2 = "cyan"231 mode.app.setActiveMode(Battle())232 if 230 <= event.x <= 410: 233 mode.app.colorPlayer2 = "yellow"234 mode.app.setActiveMode(Battle())235 if 420 <= event.x <= 600: 236 mode.app.colorPlayer2 = "magenta"237 mode.app.setActiveMode(Battle())238 def drawColors(mode, canvas):239 canvas.create_rectangle(40, 120, 220, 200, fill="red")240 canvas.create_rectangle(230, 120, 410, 200, fill="green")241 canvas.create_rectangle(420, 120, 600, 200, fill="blue")242 canvas.create_rectangle(40, 220, 220, 300, fill="cyan")243 canvas.create_rectangle(230, 220, 410, 300, fill="yellow")244 canvas.create_rectangle(420, 220, 600, 300, fill="magenta")245 def redrawAll(mode, canvas):246 mode.app._canvas.delete(ALL)247 canvas.create_text(mode.app.width/2, 80, text=f"{mode.playerSelect} Select Your Color", font="arial 30 bold")248 mode.drawColors(canvas)249class Battle(Mode):250 def appStarted(mode):251 mode.background = mode.loadImage("https://img.resized.co/entertainment/eyJkYXRhIjoie1widXJsXCI6XCJodHRwOlxcXC9cXFwvczMtZXUtd2VzdC0xLmFtYXpvbmF3cy5jb21cXFwvZW50ZXJ0YWlubWVudGllXFxcL3N0b3JhZ2VcXFwvaW1hZ2VzX2NvbnRlbnRcXFwvcmVjdGFuZ2xlXFxcLzYyMHgzNzJcXFwvdW5uYW1lZDYyMDE2MTEzMTgxOTcwNS5qcGdcIixcIndpZHRoXCI6NjQwLFwiaGVpZ2h0XCI6Mzg0LFwiZGVmYXVsdFwiOlwiaHR0cHM6XFxcL1xcXC9lbnRlcnRhaW5tZW50LmllXFxcL2ltYWdlc1xcXC9uby1pbWFnZS5wbmdcIn0iLCJoYXNoIjoiZDgzYjBmNzVhNmY5YWViMTRmMjM1MjQxOTBhMGI5NWIyZDE0NjY4OCJ9/unnamed620161131819705.jpg")252 mode.background = ImageTk.PhotoImage(mode.background)253 254 mode.count = 0255 mode.timeLeft = 60256 mode.timerDelay = 1257 mode.winner = None258 fighter.GRAVITY = -0.5 * mode.timerDelay259 fighter.FLOOR = mode.height - 20260 for player in fighter._registry:261 player.health = fighter.startingHealth262 mode.app.player1.color = mode.app.colorPlayer1263 mode.app.player2.color = mode.app.colorPlayer2264 print(mode.app.player1.color, mode.app.player2.color)265 mode.app.player1.opponent = mode.app.player2266 mode.app.player2.opponent = mode.app.player1267 mode.limbWidth = body.LW268 mode.game = True269 def timerFired(mode):270 mode.count += 1271 fighter.applyGravity()272 for i in range(len(fighter._registry)):273 fighter.threads[i] = threading.Thread(target=fighter._registry[i].getInput)274 fighter.threads[i].start()275 for i in range(len(fighter._registry)):276 fighter.threads[i].join()277 if mode.count % 66 == 0:278 fighter.updateFrames()279 mode.check4Winner()280 281 if mode.count % 1000 == 0:282 mode.timeLeft -= 1283 def keyPressed(mode, event):284 for player in fighter._registry:285 if not isinstance(player, AI) and not isinstance(player, xbox):286 if event.key in {"w", "Up"}:287 player.analogStick(('l_thumb_y', 1))288 elif event.key in {"a", "Left"}:289 player.analogStick(('l_thumb_x', -1))290 elif event.key in {"s", "Down"}:291 player.analogStick(('l_thumb_y', -1))292 elif event.key in {"d", "Right"}:293 player.analogStick(('l_thumb_x', 1))294 elif event.key == "j":295 player.buttonLog.join(13)296 player.move()297 elif event.key == "k":298 player.buttonLog.join(14)299 player.move()300 elif event.key == "n":301 player.buttonLog.join(15)302 player.move()303 elif event.key == "m":304 player.buttonLog.join(16)305 player.move()306 def check4Winner(mode):307 if mode.timeLeft > 0:308 if mode.app.player1.health <= 0:309 mode.winner = "Player 2"310 mode.game = False311 elif mode.app.player2.health <= 0:312 mode.winner = "Player 1"313 mode.game = False314 else:315 if mode.app.player1.health <= mode.app.player2.health:316 mode.winner = "Player 2"317 mode.game = False318 else:319 mode.winner = "Player 1"320 mode.game = False321 def mousePressed(mode, event):322 if not mode.game and ((mode.width/2 - 100) <= event.x <= (mode.width/2 + 100)):323 if mode.height*(2/3) - 20 <= event.y <= mode.height*(2/3) + 20:324 mode.app.setActiveMode(Battle())325 elif mode.height*(7/9) - 20 <= event.y <= mode.height*(7/9) + 20:326 mode.app.setActiveMode(mode.app.splashScreen)327 elif mode.height*(8/9) - 20 <= event.y <= mode.height*(8/9) + 20:328 mode.app.quit()329 def drawPlayers(mode, canvas):330 for player in fighter._registry:331 color = player.color332 # Draw Left Arm333 leftShoulderX, leftShoulderY = player.body.shoulderL334 leftElbowX, leftElbowY = player.body.elbowL335 leftHandX, lefthandY = player.body.handL336 canvas.create_line(leftShoulderX, leftShoulderY,337 leftElbowX, leftElbowY,338 fill=color, width=mode.limbWidth)339 canvas.create_line(leftElbowX, leftElbowY,340 leftHandX, lefthandY,341 fill=color, width=mode.limbWidth)342 # Draw Right Arm343 rightShoulderX, rightShoulderY = player.body.shoulderR344 rightElbowX, rightElbowY = player.body.elbowR345 rightHandX, rightHandY = player.body.handR346 canvas.create_line(rightShoulderX, rightShoulderY,347 rightElbowX, rightElbowY,348 fill=color, width=mode.limbWidth)349 canvas.create_line(rightElbowX, rightElbowY,350 rightHandX, rightHandY,351 fill=color, width=mode.limbWidth)352 # Draw Left Leg353 leftHipX, leftHipY = player.body.hipL354 leftKneeX, leftKneeY = player.body.kneeL355 leftHandX, leftFootY = player.body.footL356 canvas.create_line(leftHipX, leftHipY,357 leftKneeX, leftKneeY,358 fill=color, width=mode.limbWidth)359 canvas.create_line(leftKneeX, leftKneeY,360 leftHandX, leftFootY,361 fill=color, width=mode.limbWidth)362 # Draw Right Leg363 rightHipX, rightHipY = player.body.hipR364 rightKneeX, rightKneeY = player.body.kneeR365 rightHandX, rightFootY = player.body.footR366 canvas.create_line(rightHipX, rightHipY,367 rightKneeX, rightKneeY,368 fill=color, width=mode.limbWidth)369 canvas.create_line(rightKneeX, rightKneeY,370 rightHandX, rightFootY,371 fill=color, width=mode.limbWidth)372 # Draw the Torso373 # Done like this to allow for better animations in future374 canvas.create_polygon(player.body.shoulderL, player.body.shoulderR, 375 player.body.hipR, player.body.hipL, 376 fill=color, width=0)377 # Draw the Head378 x,y = player.body.head379 r = body.HR380 canvas.create_oval(x-r, y-r, x+r, y+r, fill=color, width=0)381 def healthColor(mode, player):382 healthPercent = player.health / fighter.startingHealth383 if healthPercent < 0.2: return "red"384 elif healthPercent < 0.5: return "orange"385 elif healthPercent < 0.8: return "yellow"386 else: return "green"387 def drawHealthBars(mode, canvas):388 389 canvas.create_rectangle(0, 20, mode.app.player1.health, 40,390 fill=mode.healthColor(mode.app.player1))391 canvas.create_text(mode.app.width/2, 40, text=str(mode.timeLeft),392 fill="white", font="arial 40 bold")393 canvas.create_rectangle(mode.width - mode.app.player2.health, 20,394 mode.width, 40, fill=mode.healthColor(mode.app.player2))395 canvas.create_text(20, 30, text="P1")396 canvas.create_text(mode.width - 20, 30, text="P2")397 def drawBackground(mode, canvas):398 canvas.create_image(mode.width/2, mode.height/2,399 image=mode.background)400 def drawGameOver(mode, canvas):401 # Rematch402 canvas.create_rectangle((mode.width/2 - 100), mode.height*(2/3) - 20 ,403 (mode.width/2 + 100), mode.height*(2/3) + 20,404 fill="lime")405 canvas.create_text(mode.width/2, mode.height*(2/3), text="Rematch?")406 # Title Screen407 canvas.create_rectangle((mode.width/2 - 100), mode.height*(7/9) - 20 ,408 (mode.width/2 + 100), mode.height*(7/9) + 20,409 fill="lime")410 canvas.create_text(mode.width/2, mode.height*(7/9), text="Return to Title Screen")411 #Quit412 canvas.create_rectangle((mode.width/2 - 100), mode.height*(8/9) - 20 ,413 (mode.width/2 + 100), mode.height*(8/9) + 20,414 fill="lime")415 canvas.create_text(mode.width/2, mode.height*(8/9), text="Quit")416 def redrawAll(mode, canvas):417 if mode.count % 66 > 0:418 return419 mode.app._canvas.delete(ALL)420 if mode.game:421 mode.drawBackground(canvas)422 mode.drawPlayers(canvas)423 mode.drawHealthBars(canvas)424 else:425 mode.drawGameOver(canvas)426 canvas.create_text(mode.width/2, mode.height/2, text=f"{mode.winner} Wins!",427 font="ariel 40 bold",fill="black")...
display.py
Source:display.py
1############################################################################2#3# QuadcopeRPI- SW for controlling a quadcopter by RPI4#5# Copyright (C) 2014 Oscar Ferrato (solenero tech)6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU General Public License as published by8# the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10# This program is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13# GNU General Public License for more details.14# You should have received a copy of the GNU General Public License15# along with this program. If not, see <http://www.gnu.org/licenses/>.16# Contact me at:17# solenero.tech@gmail.com18# solenerotech.wordpress.com19##############################################################################20#2014.10.20 finalize display21#removed all the reference to screen in the rest of the code22import curses23import threading24from time import sleep, time25import logging26class display(threading.Thread):27#here i can manage the display as a parallel thread28 def __init__(self, quadricopter, refreshtime=0.2):29 threading.Thread.__init__(self)30 self.logger = logging.getLogger('myQ.display')31 self.myQ = quadricopter32 self.cycling = True33 self.screen = curses.initscr()34 self.logQ = curses.newpad(3, 81)35 self.padQ = curses.newpad(11, 81)36 self.padModeQ = curses.newpad(11, 81)37 self.refreshtime = refreshtime38 self.paused = False39 self.currentMode = -140 self.firstcycle = True41 def displayPadQ(self):42 #self.padQ.clear()43 self.padQ.redrawwin()44 i = 045 self.padQ.addstr(i, 0, '|-------------------------------------------------|')46 i = 147 self.padQ.addstr(i, 00, '|motor')48 self.padQ.addstr(i, 10, '|')49 self.padQ.addstr(i, 11, self.myQ.motor[0].name)50 self.padQ.addstr(i, 20, '|')51 self.padQ.addstr(i, 21, self.myQ.motor[1].name)52 self.padQ.addstr(i, 30, '|')53 self.padQ.addstr(i, 31, self.myQ.motor[2].name)54 self.padQ.addstr(i, 40, '|')55 self.padQ.addstr(i, 41, self.myQ.motor[3].name)56 self.padQ.addstr(i, 50, '|')57 i = 258 self.padQ.addstr(i, 0, '|W')59 self.padQ.addstr(i, 10, '|W')60 self.padQ.addstr(i, 11, '%.1f' % self.myQ.motor[0].getW())61 self.padQ.addstr(i, 20, '|')62 self.padQ.addstr(i, 21,'%.1f' % self.myQ.motor[1].getW())63 self.padQ.addstr(i, 30, '|')64 self.padQ.addstr(i, 31,'%.1f' % self.myQ.motor[2].getW())65 self.padQ.addstr(i, 40, '|')66 self.padQ.addstr(i, 41,'%.1f' % self.myQ.motor[3].getW())67 self.padQ.addstr(i, 50, '|')68 i = 369 self.padQ.addstr(i, 0, '|-------------------------------------------------|')70 i = 471 self.padQ.addstr(i, 00, '|')72 self.padQ.addstr(i, 10, '|')73 self.padQ.addstr(i, 11, 'Roll')74 self.padQ.addstr(i, 20, '|')75 self.padQ.addstr(i, 21, 'Pitch')76 self.padQ.addstr(i, 30, '|')77 self.padQ.addstr(i, 31, 'Yaw')78 self.padQ.addstr(i, 40, '|')79 self.padQ.addstr(i, 41, 'Throttle')80 self.padQ.addstr(i, 50, '|')81 i = 582 self.padQ.addstr(i, 00, '|target')83 self.padQ.addstr(i, 10, '|')84 self.padQ.addstr(i, 11, '%.1f' % self.myQ.rc.roll)85 self.padQ.addstr(i, 20, '|')86 self.padQ.addstr(i, 21, '%.1f' % self.myQ.rc.pitch)87 self.padQ.addstr(i, 30, '|')88 self.padQ.addstr(i, 31, '%.1f' % self.myQ.rc.yaw)89 self.padQ.addstr(i, 40, '|')90 self.padQ.addstr(i, 41, '%4d' % self.myQ.rc.throttle)91 self.padQ.addstr(i, 50, '|')92 i = 693 self.padQ.addstr(i, 00, '|current')94 self.padQ.addstr(i, 10, '|')95 self.padQ.addstr(i, 11, '%.1f' % self.myQ.sensor.roll)96 self.padQ.addstr(i, 20, '|')97 self.padQ.addstr(i, 21, '%.1f' % self.myQ.sensor.pitch)98 self.padQ.addstr(i, 30, '|')99 self.padQ.addstr(i, 31, '%.1f' % self.myQ.sensor.yaw)100 self.padQ.addstr(i, 40, '|')101 self.padQ.addstr(i, 41, '%4d' % self.myQ.rc.throttle)102 self.padQ.addstr(i, 50, '|')103 i = 7104 self.padQ.addstr(i, 0, '|-------------------------------------------------|')105 i = 0106 self.padQ.addstr(i, 51, '----------------------------|')107 i = 1108 self.padQ.addstr(i, 51, 'Mode : %2d' % self.myQ.rc.mode)109 self.padQ.addstr(i, 65, '|Temp: %.1f' % self.myQ.sensor.temp)110 self.padQ.addstr(i, 79, '|')111 i = 2112 self.padQ.addstr(i, 51, 'Command: %2d' % self.myQ.rc.command)113 self.padQ.addstr(i, 65, '|')114 self.padQ.addstr(i, 79, '|')115 i = 3116 self.padQ.addstr(i, 51, '----------------------------|')117 i = 4118 self.padQ.addstr(i, 51, ' | P | I | D |')119 i = 5120 self.padQ.addstr(i, 51, 'roll')121 self.padQ.addstr(i, 58, '|%.3f ' % self.myQ.pidR.kp)122 self.padQ.addstr(i, 65, '|%.3f ' % self.myQ.pidR.ki)123 self.padQ.addstr(i, 72, '|%.3f |' % self.myQ.pidR.kd)124 i = 6125 self.padQ.addstr(i, 51, 'r rate')126 self.padQ.addstr(i, 58, '|%.3f ' % self.myQ.pidR_rate.kp)127 self.padQ.addstr(i, 65, '|%.3f ' % self.myQ.pidR_rate.ki)128 self.padQ.addstr(i, 72, '|%.3f |' % self.myQ.pidR_rate.kd)129 i = 7130 self.padQ.addstr(i, 51, '')131 self.padQ.addstr(i, 79, '|')132 i = 7133 self.padQ.addstr(i, 51, '----------------------------|')134 i = 8135 self.padQ.addstr(i, 00, '| j < Roll > k ')136 self.padQ.addstr(i, 20, '| i < Pitch > m ')137 self.padQ.addstr(i, 40, '| a < yaw > s')138 self.padQ.addstr(i, 60, '| w < Throttle > z')139 self.padQ.addstr(i, 79, '|')140 i = 9141 self.padQ.addstr(i, 0, '|------------------------------|SPACEBAR to KILL|------------------------------|')142 self.padQ.refresh(0, 0, 0, 0, 9, 79)143 def displayMode_welcome(self):144 i = 1145 self.padModeQ.addstr(i, 00, 'welcome')146 self.padModeQ.clrtoeol()147 i = 2148 self.padModeQ.addstr(i, 00, '')149 self.padModeQ.clrtoeol()150 i = 3151 self.padModeQ.addstr(i, 00, '')152 self.padModeQ.clrtoeol()153 i = 4154 self.padModeQ.addstr(i, 00, '')155 self.padModeQ.clrtoeol()156 i = 5157 self.padModeQ.addstr(i, 00, '')158 self.padModeQ.clrtoeol()159 i = 6160 self.padModeQ.addstr(i, 00, '')161 self.padModeQ.clrtoeol()162 i = 7163 self.padModeQ.addstr(i, 00, '')164 self.padModeQ.clrtoeol()165 i = 8166 self.padModeQ.addstr(i, 00, '')167 self.padModeQ.clrtoeol()168 i = 9169 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')170 def displayMode_imu(self):171 i = 1172 self.padModeQ.addstr(i, 00, 'Follow the next steps to calibrate IMU')173 self.padModeQ.clrtoeol()174 i = 2175 self.padModeQ.addstr(i, 00, 'BASIC calibration')176 self.padModeQ.clrtoeol()177 i = 3178 self.padModeQ.addstr(i, 00, ' PRESS 1 and wait 5 seconds')179 self.padModeQ.clrtoeol()180 i = 4181 self.padModeQ.addstr(i, 00, 'FINE calibration')182 self.padModeQ.clrtoeol()183 i = 5184 self.padModeQ.addstr(i, 00, ' 1)PRESS 3 and wait 5 seconds')185 self.padModeQ.clrtoeol()186 i = 6187 self.padModeQ.addstr(i, 00, ' 2)Turn the drone 180 around yaw')188 self.padModeQ.clrtoeol()189 i = 7190 self.padModeQ.addstr(i, 00, ' 3)PRESS 5 and wait 5 seconds')191 self.padModeQ.clrtoeol()192 i = 8193 self.padModeQ.addstr(i, 00, 'Calibration data will be stored in IMU.cfg')194 self.padModeQ.clrtoeol()195 i = 9196 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')197 def displayMode_esc(self):198 i = 1199 self.padModeQ.addstr(i, 00, 'Follow the next steps to initialize ESCs')200 self.padModeQ.clrtoeol()201 i = 2202 self.padModeQ.addstr(i, 00, '1)FIX the Motor steady,remove the Props,connect the motor to ESC')203 self.padModeQ.clrtoeol()204 i = 3205 self.padModeQ.addstr(i, 00, '2)Disconnect the ESC power cables')206 self.padModeQ.clrtoeol()207 i = 4208 self.padModeQ.addstr(i, 00, '3)PRESS 9 to ack the motor start')209 self.padModeQ.clrtoeol()210 i = 5211 self.padModeQ.addstr(i, 00, '4)Select the ESC pressing 0|3')212 self.padModeQ.clrtoeol()213 i = 6214 self.padModeQ.addstr(i, 00, '5)Press 5 to ack to init ESC - ATT: throttle will be set to max')215 self.padModeQ.clrtoeol()216 i = 7217 self.padModeQ.addstr(i, 00, '6)Now Connect ESC power and wait beep-beep')218 self.padModeQ.clrtoeol()219 i = 8220 self.padModeQ.addstr(i, 00, '7)Press 6 to complete procedure (throttle to 0')221 self.padModeQ.clrtoeol()222 i = 9223 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')224 def displayMode_motor(self):225 i = 1226 self.padModeQ.addstr(i, 00, 'FIRST : Press 9 to ack the motor start')227 self.padModeQ.clrtoeol()228 i = 2229 self.padModeQ.addstr(i, 00, 'COMMAND > 0 Select M0 (default)')230 self.padModeQ.clrtoeol()231 i = 3232 self.padModeQ.addstr(i, 00, 'COMMAND > 1 Select M1')233 self.padModeQ.clrtoeol()234 i = 4235 self.padModeQ.addstr(i, 00, 'COMMAND > 2 Select M2')236 self.padModeQ.clrtoeol()237 i = 5238 self.padModeQ.addstr(i, 00, 'COMMAND > 3 Select M3')239 self.padModeQ.clrtoeol()240 i = 6241 self.padModeQ.addstr(i, 00, 'Use Throttle to modify motor speed')242 self.padModeQ.clrtoeol()243 i = 7244 self.padModeQ.addstr(i, 00, '')245 self.padModeQ.clrtoeol()246 i = 8247 self.padModeQ.addstr(i, 00, '')248 self.padModeQ.clrtoeol()249 i = 9250 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')251 def displayMode_pid(self):252 i = 1253 self.padModeQ.addstr(i, 00, 'FIRST : Press 9 to ack the motor start')254 self.padModeQ.clrtoeol()255 i = 2256 self.padModeQ.addstr(i, 00, 'COMMAND > 0 NO PID control')257 self.padModeQ.clrtoeol()258 i = 3259 self.padModeQ.addstr(i, 00, 'COMMAND > 1 PID control roll')260 self.padModeQ.clrtoeol()261 i = 4262 self.padModeQ.addstr(i, 00, 'COMMAND > 2 Switch tune RollRate/Roll')263 self.padModeQ.clrtoeol()264 i = 5265 self.padModeQ.addstr(i, 00, 'Tune Roll Rate/roll PID:')266 self.padModeQ.clrtoeol()267 i = 6268 self.padModeQ.addstr(i, 00, 'COMMAND > 3<P>4 5<I>6 7<D>8')269 self.padModeQ.clrtoeol()270 i = 7271 self.padModeQ.addstr(i, 00, '')272 self.padModeQ.clrtoeol()273 i = 8274 self.padModeQ.addstr(i, 00, '')275 self.padModeQ.clrtoeol()276 i = 9277 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')278 def displayMode_flying(self):279 i = 1280 self.padModeQ.addstr(i, 00, 'FIRST : Press 9 to ack the motor start')281 self.padModeQ.clrtoeol()282 i = 2283 self.padModeQ.addstr(i, 00, 'COMMAND > 0 Netscan activation (to check continously the connection)')284 self.padModeQ.clrtoeol()285 i = 3286 self.padModeQ.addstr(i, 00, 'COMMAND > 1 Use PID value set 1')287 self.padModeQ.clrtoeol()288 i = 4289 self.padModeQ.addstr(i, 00, 'COMMAND > 2 Use PID value set 2')290 self.padModeQ.clrtoeol()291 i = 5292 self.padModeQ.addstr(i, 00, 'COMMAND > 3 Use PID value set 3')293 self.padModeQ.clrtoeol()294 i = 6295 self.padModeQ.addstr(i, 00, 'COMMAND > 4 Activate PID Control')296 self.padModeQ.clrtoeol()297 i = 7298 self.padModeQ.addstr(i, 00, '')299 self.padModeQ.clrtoeol()300 i = 8301 self.padModeQ.addstr(i, 00, '')302 self.padModeQ.clrtoeol()303 i = 9304 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')305 def displayMode_uav(self):306 i = 1307 self.padModeQ.addstr(i, 00, 'FIRST : Press 9 to ack the motor start')308 self.padModeQ.clrtoeol()309 i = 2310 self.padModeQ.addstr(i, 00, 'COMMAND > 0 NO PID control')311 self.padModeQ.clrtoeol()312 i = 3313 self.padModeQ.addstr(i, 00, 'COMMAND > 1 PID control roll')314 self.padModeQ.clrtoeol()315 i = 4316 self.padModeQ.addstr(i, 00, 'COMMAND > 2 3 sec pulse roll 0|3 for 18 sec')317 self.padModeQ.clrtoeol()318 i = 5319 self.padModeQ.addstr(i, 00, 'COMMAND > 3 3 sec pulse roll -3|3 for 18 sec')320 self.padModeQ.clrtoeol()321 i = 6322 self.padModeQ.addstr(i, 00, 'COMMAND > 4 variations for 20 sec')323 self.padModeQ.clrtoeol()324 i = 7325 self.padModeQ.addstr(i, 00, '')326 self.padModeQ.clrtoeol()327 i = 8328 self.padModeQ.addstr(i, 00, '')329 self.padModeQ.clrtoeol()330 i = 9331 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')332 def displayMode_about(self):333 i = 1334 self.padModeQ.addstr(i, 00, '')335 self.padModeQ.clrtoeol()336 i = 2337 self.padModeQ.addstr(i, 00, '')338 self.padModeQ.clrtoeol()339 i = 3340 self.padModeQ.addstr(i, 00, '')341 self.padModeQ.clrtoeol()342 i = 4343 self.padModeQ.addstr(i, 00, '')344 self.padModeQ.clrtoeol()345 i = 5346 self.padModeQ.addstr(i, 00, '')347 self.padModeQ.clrtoeol()348 i = 6349 self.padModeQ.addstr(i, 00, '')350 self.padModeQ.clrtoeol()351 i = 7352 self.padModeQ.addstr(i, 00, '')353 self.padModeQ.clrtoeol()354 i = 8355 self.padModeQ.addstr(i, 00, '')356 self.padModeQ.clrtoeol()357 i = 9358 self.padModeQ.addstr(i, 0, '|------------------------------------------------------------------------------|')359 def displayModeQ(self):360 self.padModeQ.redrawwin()361 #if self.currentMode == self.myQ.rc.mode and not self.firstcycle:362 #return363 self.currentMode = self.myQ.rc.mode364 self.firstcycle = False365 i = 0366 self.padModeQ.addstr(i, 00, '|_WELCOME_')367 self.padModeQ.addstr(i, 10, '|___IMU___')368 self.padModeQ.addstr(i, 20, '|___ESC___')369 self.padModeQ.addstr(i, 30, '|__MOTOR__')370 self.padModeQ.addstr(i, 40, '|___PID___')371 self.padModeQ.addstr(i, 50, '|__Flying_')372 self.padModeQ.addstr(i, 60, '|___UAV___')373 self.padModeQ.addstr(i, 70, '|__ABOUT__')374 self.padModeQ.addstr(i, 79, '|')375 i = 0376 if self.myQ.rc.mode == self.myQ.rc.MODE_WELCOME or self.myQ.rc.mode == self.myQ.rc.MODE_UNDEF:377 self.padModeQ.addstr(i, 00, '|_WELCOME_', curses.A_REVERSE)378 self.displayMode_welcome()379 elif self.myQ.rc.mode == self.myQ.rc.MODE_IMU:380 self.padModeQ.addstr(i, 10, '|___IMU___', curses.A_REVERSE)381 self.displayMode_imu()382 elif self.myQ.rc.mode == self.myQ.rc.MODE_ESC:383 self.padModeQ.addstr(i, 20, '|___ESC___', curses.A_REVERSE)384 self.displayMode_esc()385 elif self.myQ.rc.mode == self.myQ.rc.MODE_MOTOR:386 self.padModeQ.addstr(i, 30, '|__MOTOR__', curses.A_REVERSE)387 self.displayMode_motor()388 elif self.myQ.rc.mode == self.myQ.rc.MODE_PID_TUNING:389 self.padModeQ.addstr(i, 40, '|___PID___', curses.A_REVERSE)390 self.displayMode_pid()391 elif self.myQ.rc.mode == self.myQ.rc.MODE_FLYING:392 self.padModeQ.addstr(i, 50, '|__Flying_', curses.A_REVERSE)393 self.displayMode_flying()394 elif self.myQ.rc.mode == self.myQ.rc.MODE_UAV:395 self.padModeQ.addstr(i, 60, '|___UAV___', curses.A_REVERSE)396 self.displayMode_uav()397 elif self.myQ.rc.mode == self.myQ.rc.MODE_ABOUT:398 self.padModeQ.addstr(i, 70, '|__ABOUT__', curses.A_REVERSE)399 self.displayMode_about()400 self.padModeQ.addstr(i, 79, '|')401 self.padModeQ.refresh(0, 0, 10, 0, 20, 79)402 def displayLog(self):403 #self.logQ.redrawwin()404 i = 0405 #do not use redrawwin here, in order to show always last message406 self.logQ.addstr(i, 00, '') # used to set the cursor in a fixed position407 #self.logQ.clrtoeol()408 self.logQ.refresh(0, 0, 22, 0, 23, 79)409 def run(self):410 self.logger.debug('Display running...')411 # turn off input echoing412 curses.noecho()413 # respond to keys immediately (don't wait for enter)414 curses.cbreak()415 curses.curs_set(0)416 # map arrow keys to special v1alues417 self.screen.keypad(True)418 sleep(1)419 self.screen.clear()420 initTime = time()421 counterPerf = 0 # used for performance tests422 while self.cycling is True:423 if self.paused is False:424 #self.screen.clear()425 self.displayPadQ()426 self.displayModeQ()427 self.displayLog()428 sleep(self.refreshtime)429 #used for performance test only430 doPerf = True431 if doPerf is True:432 counterPerf += 1433 if counterPerf == 100:434 self.logger.info('1000 cycles time:' + str((time() - initTime) * 10))435 doPerf = False436 self.logger.debug('Display stopped')437 def stop(self):438 self.cycling = False439 sleep(self.refreshtime + 0.1)440 self.screen.clear()441 self.screen.addstr(0, 0, '')442 self.logger.debug('Display stopping...')443 self.screen.keypad(0)444 curses.curs_set(1)445 curses.nocbreak()446 curses.echo()...
xf86vmode.py
Source:xf86vmode.py
1'''Wrapper for Xxf86vm2Generated with:3tools/genwrappers.py xf86vmode4Do not modify this file.5'''6__docformat__ = 'restructuredtext'7__version__ = '$Id$'8import ctypes9from ctypes import *10import pyglet.lib11_lib = pyglet.lib.load_library('Xxf86vm')12_int_types = (c_int16, c_int32)13if hasattr(ctypes, 'c_int64'):14 # Some builds of ctypes apparently do not have c_int6415 # defined; it's a pretty good bet that these builds do not16 # have 64-bit pointers.17 _int_types += (ctypes.c_int64,)18for t in _int_types:19 if sizeof(t) == sizeof(c_size_t):20 c_ptrdiff_t = t21class c_void(Structure):22 # c_void_p is a buggy return type, converting to int, so23 # POINTER(None) == c_void_p is actually written as24 # POINTER(c_void), so it can be treated as a real pointer.25 _fields_ = [('dummy', c_int)]26import pyglet.libs.x11.xlib27X_XF86VidModeQueryVersion = 0 # /usr/include/X11/extensions/xf86vmode.h:488528X_XF86VidModeGetModeLine = 1 # /usr/include/X11/extensions/xf86vmode.h:488629X_XF86VidModeModModeLine = 2 # /usr/include/X11/extensions/xf86vmode.h:488730X_XF86VidModeSwitchMode = 3 # /usr/include/X11/extensions/xf86vmode.h:488831X_XF86VidModeGetMonitor = 4 # /usr/include/X11/extensions/xf86vmode.h:488932X_XF86VidModeLockModeSwitch = 5 # /usr/include/X11/extensions/xf86vmode.h:489033X_XF86VidModeGetAllModeLines = 6 # /usr/include/X11/extensions/xf86vmode.h:489134X_XF86VidModeAddModeLine = 7 # /usr/include/X11/extensions/xf86vmode.h:489235X_XF86VidModeDeleteModeLine = 8 # /usr/include/X11/extensions/xf86vmode.h:489336X_XF86VidModeValidateModeLine = 9 # /usr/include/X11/extensions/xf86vmode.h:489437X_XF86VidModeSwitchToMode = 10 # /usr/include/X11/extensions/xf86vmode.h:489538X_XF86VidModeGetViewPort = 11 # /usr/include/X11/extensions/xf86vmode.h:489639X_XF86VidModeSetViewPort = 12 # /usr/include/X11/extensions/xf86vmode.h:489740X_XF86VidModeGetDotClocks = 13 # /usr/include/X11/extensions/xf86vmode.h:489941X_XF86VidModeSetClientVersion = 14 # /usr/include/X11/extensions/xf86vmode.h:490042X_XF86VidModeSetGamma = 15 # /usr/include/X11/extensions/xf86vmode.h:490143X_XF86VidModeGetGamma = 16 # /usr/include/X11/extensions/xf86vmode.h:490244X_XF86VidModeGetGammaRamp = 17 # /usr/include/X11/extensions/xf86vmode.h:490345X_XF86VidModeSetGammaRamp = 18 # /usr/include/X11/extensions/xf86vmode.h:490446X_XF86VidModeGetGammaRampSize = 19 # /usr/include/X11/extensions/xf86vmode.h:490547X_XF86VidModeGetPermissions = 20 # /usr/include/X11/extensions/xf86vmode.h:490648CLKFLAG_PROGRAMABLE = 1 # /usr/include/X11/extensions/xf86vmode.h:490849XF86VidModeNumberEvents = 0 # /usr/include/X11/extensions/xf86vmode.h:491950XF86VidModeBadClock = 0 # /usr/include/X11/extensions/xf86vmode.h:492251XF86VidModeBadHTimings = 1 # /usr/include/X11/extensions/xf86vmode.h:492352XF86VidModeBadVTimings = 2 # /usr/include/X11/extensions/xf86vmode.h:492453XF86VidModeModeUnsuitable = 3 # /usr/include/X11/extensions/xf86vmode.h:492554XF86VidModeExtensionDisabled = 4 # /usr/include/X11/extensions/xf86vmode.h:492655XF86VidModeClientNotLocal = 5 # /usr/include/X11/extensions/xf86vmode.h:492756XF86VidModeZoomLocked = 6 # /usr/include/X11/extensions/xf86vmode.h:492857XF86VidModeNumberErrors = 7 # /usr/include/X11/extensions/xf86vmode.h:492958XF86VM_READ_PERMISSION = 1 # /usr/include/X11/extensions/xf86vmode.h:493159XF86VM_WRITE_PERMISSION = 2 # /usr/include/X11/extensions/xf86vmode.h:493260class struct_anon_93(Structure):61 __slots__ = [62 'hdisplay',63 'hsyncstart',64 'hsyncend',65 'htotal',66 'hskew',67 'vdisplay',68 'vsyncstart',69 'vsyncend',70 'vtotal',71 'flags',72 'privsize',73 'private',74 ]75INT32 = c_int # /usr/include/X11/Xmd.h:13576struct_anon_93._fields_ = [77 ('hdisplay', c_ushort),78 ('hsyncstart', c_ushort),79 ('hsyncend', c_ushort),80 ('htotal', c_ushort),81 ('hskew', c_ushort),82 ('vdisplay', c_ushort),83 ('vsyncstart', c_ushort),84 ('vsyncend', c_ushort),85 ('vtotal', c_ushort),86 ('flags', c_uint),87 ('privsize', c_int),88 ('private', POINTER(INT32)),89]90XF86VidModeModeLine = struct_anon_93 # /usr/include/X11/extensions/xf86vmode.h:495491class struct_anon_94(Structure):92 __slots__ = [93 'dotclock',94 'hdisplay',95 'hsyncstart',96 'hsyncend',97 'htotal',98 'hskew',99 'vdisplay',100 'vsyncstart',101 'vsyncend',102 'vtotal',103 'flags',104 'privsize',105 'private',106 ]107struct_anon_94._fields_ = [108 ('dotclock', c_uint),109 ('hdisplay', c_ushort),110 ('hsyncstart', c_ushort),111 ('hsyncend', c_ushort),112 ('htotal', c_ushort),113 ('hskew', c_ushort),114 ('vdisplay', c_ushort),115 ('vsyncstart', c_ushort),116 ('vsyncend', c_ushort),117 ('vtotal', c_ushort),118 ('flags', c_uint),119 ('privsize', c_int),120 ('private', POINTER(INT32)),121]122XF86VidModeModeInfo = struct_anon_94 # /usr/include/X11/extensions/xf86vmode.h:4975123class struct_anon_95(Structure):124 __slots__ = [125 'hi',126 'lo',127 ]128struct_anon_95._fields_ = [129 ('hi', c_float),130 ('lo', c_float),131]132XF86VidModeSyncRange = struct_anon_95 # /usr/include/X11/extensions/xf86vmode.h:4980133class struct_anon_96(Structure):134 __slots__ = [135 'vendor',136 'model',137 'EMPTY',138 'nhsync',139 'hsync',140 'nvsync',141 'vsync',142 ]143struct_anon_96._fields_ = [144 ('vendor', c_char_p),145 ('model', c_char_p),146 ('EMPTY', c_float),147 ('nhsync', c_ubyte),148 ('hsync', POINTER(XF86VidModeSyncRange)),149 ('nvsync', c_ubyte),150 ('vsync', POINTER(XF86VidModeSyncRange)),151]152XF86VidModeMonitor = struct_anon_96 # /usr/include/X11/extensions/xf86vmode.h:4990153class struct_anon_97(Structure):154 __slots__ = [155 'type',156 'serial',157 'send_event',158 'display',159 'root',160 'state',161 'kind',162 'forced',163 'time',164 ]165Display = pyglet.libs.x11.xlib.Display166Window = pyglet.libs.x11.xlib.Window167Time = pyglet.libs.x11.xlib.Time168struct_anon_97._fields_ = [169 ('type', c_int),170 ('serial', c_ulong),171 ('send_event', c_int),172 ('display', POINTER(Display)),173 ('root', Window),174 ('state', c_int),175 ('kind', c_int),176 ('forced', c_int),177 ('time', Time),178]179XF86VidModeNotifyEvent = struct_anon_97 # /usr/include/X11/extensions/xf86vmode.h:5002180class struct_anon_98(Structure):181 __slots__ = [182 'red',183 'green',184 'blue',185 ]186struct_anon_98._fields_ = [187 ('red', c_float),188 ('green', c_float),189 ('blue', c_float),190]191XF86VidModeGamma = struct_anon_98 # /usr/include/X11/extensions/xf86vmode.h:5008192# /usr/include/X11/extensions/xf86vmode.h:5018193XF86VidModeQueryVersion = _lib.XF86VidModeQueryVersion194XF86VidModeQueryVersion.restype = c_int195XF86VidModeQueryVersion.argtypes = [POINTER(Display), POINTER(c_int), POINTER(c_int)]196# /usr/include/X11/extensions/xf86vmode.h:5024197XF86VidModeQueryExtension = _lib.XF86VidModeQueryExtension198XF86VidModeQueryExtension.restype = c_int199XF86VidModeQueryExtension.argtypes = [POINTER(Display), POINTER(c_int), POINTER(c_int)]200# /usr/include/X11/extensions/xf86vmode.h:5030201XF86VidModeSetClientVersion = _lib.XF86VidModeSetClientVersion202XF86VidModeSetClientVersion.restype = c_int203XF86VidModeSetClientVersion.argtypes = [POINTER(Display)]204# /usr/include/X11/extensions/xf86vmode.h:5034205XF86VidModeGetModeLine = _lib.XF86VidModeGetModeLine206XF86VidModeGetModeLine.restype = c_int207XF86VidModeGetModeLine.argtypes = [POINTER(Display), c_int, POINTER(c_int), POINTER(XF86VidModeModeLine)]208# /usr/include/X11/extensions/xf86vmode.h:5041209XF86VidModeGetAllModeLines = _lib.XF86VidModeGetAllModeLines210XF86VidModeGetAllModeLines.restype = c_int211XF86VidModeGetAllModeLines.argtypes = [POINTER(Display), c_int, POINTER(c_int), POINTER(POINTER(POINTER(XF86VidModeModeInfo)))]212# /usr/include/X11/extensions/xf86vmode.h:5048213XF86VidModeAddModeLine = _lib.XF86VidModeAddModeLine214XF86VidModeAddModeLine.restype = c_int215XF86VidModeAddModeLine.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeModeInfo), POINTER(XF86VidModeModeInfo)]216# /usr/include/X11/extensions/xf86vmode.h:5055217XF86VidModeDeleteModeLine = _lib.XF86VidModeDeleteModeLine218XF86VidModeDeleteModeLine.restype = c_int219XF86VidModeDeleteModeLine.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeModeInfo)]220# /usr/include/X11/extensions/xf86vmode.h:5061221XF86VidModeModModeLine = _lib.XF86VidModeModModeLine222XF86VidModeModModeLine.restype = c_int223XF86VidModeModModeLine.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeModeLine)]224# /usr/include/X11/extensions/xf86vmode.h:5067225XF86VidModeValidateModeLine = _lib.XF86VidModeValidateModeLine226XF86VidModeValidateModeLine.restype = c_int227XF86VidModeValidateModeLine.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeModeInfo)]228# /usr/include/X11/extensions/xf86vmode.h:5073229XF86VidModeSwitchMode = _lib.XF86VidModeSwitchMode230XF86VidModeSwitchMode.restype = c_int231XF86VidModeSwitchMode.argtypes = [POINTER(Display), c_int, c_int]232# /usr/include/X11/extensions/xf86vmode.h:5079233XF86VidModeSwitchToMode = _lib.XF86VidModeSwitchToMode234XF86VidModeSwitchToMode.restype = c_int235XF86VidModeSwitchToMode.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeModeInfo)]236# /usr/include/X11/extensions/xf86vmode.h:5085237XF86VidModeLockModeSwitch = _lib.XF86VidModeLockModeSwitch238XF86VidModeLockModeSwitch.restype = c_int239XF86VidModeLockModeSwitch.argtypes = [POINTER(Display), c_int, c_int]240# /usr/include/X11/extensions/xf86vmode.h:5091241XF86VidModeGetMonitor = _lib.XF86VidModeGetMonitor242XF86VidModeGetMonitor.restype = c_int243XF86VidModeGetMonitor.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeMonitor)]244# /usr/include/X11/extensions/xf86vmode.h:5097245XF86VidModeGetViewPort = _lib.XF86VidModeGetViewPort246XF86VidModeGetViewPort.restype = c_int247XF86VidModeGetViewPort.argtypes = [POINTER(Display), c_int, POINTER(c_int), POINTER(c_int)]248# /usr/include/X11/extensions/xf86vmode.h:5104249XF86VidModeSetViewPort = _lib.XF86VidModeSetViewPort250XF86VidModeSetViewPort.restype = c_int251XF86VidModeSetViewPort.argtypes = [POINTER(Display), c_int, c_int, c_int]252# /usr/include/X11/extensions/xf86vmode.h:5111253XF86VidModeGetDotClocks = _lib.XF86VidModeGetDotClocks254XF86VidModeGetDotClocks.restype = c_int255XF86VidModeGetDotClocks.argtypes = [POINTER(Display), c_int, POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(POINTER(c_int))]256# /usr/include/X11/extensions/xf86vmode.h:5120257XF86VidModeGetGamma = _lib.XF86VidModeGetGamma258XF86VidModeGetGamma.restype = c_int259XF86VidModeGetGamma.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeGamma)]260# /usr/include/X11/extensions/xf86vmode.h:5126261XF86VidModeSetGamma = _lib.XF86VidModeSetGamma262XF86VidModeSetGamma.restype = c_int263XF86VidModeSetGamma.argtypes = [POINTER(Display), c_int, POINTER(XF86VidModeGamma)]264# /usr/include/X11/extensions/xf86vmode.h:5132265XF86VidModeSetGammaRamp = _lib.XF86VidModeSetGammaRamp266XF86VidModeSetGammaRamp.restype = c_int267XF86VidModeSetGammaRamp.argtypes = [POINTER(Display), c_int, c_int, POINTER(c_ushort), POINTER(c_ushort), POINTER(c_ushort)]268# /usr/include/X11/extensions/xf86vmode.h:5141269XF86VidModeGetGammaRamp = _lib.XF86VidModeGetGammaRamp270XF86VidModeGetGammaRamp.restype = c_int271XF86VidModeGetGammaRamp.argtypes = [POINTER(Display), c_int, c_int, POINTER(c_ushort), POINTER(c_ushort), POINTER(c_ushort)]272# /usr/include/X11/extensions/xf86vmode.h:5150273XF86VidModeGetGammaRampSize = _lib.XF86VidModeGetGammaRampSize274XF86VidModeGetGammaRampSize.restype = c_int275XF86VidModeGetGammaRampSize.argtypes = [POINTER(Display), c_int, POINTER(c_int)]276# /usr/include/X11/extensions/xf86vmode.h:5156277XF86VidModeGetPermissions = _lib.XF86VidModeGetPermissions278XF86VidModeGetPermissions.restype = c_int279XF86VidModeGetPermissions.argtypes = [POINTER(Display), c_int, POINTER(c_int)]280__all__ = ['X_XF86VidModeQueryVersion', 'X_XF86VidModeGetModeLine',281'X_XF86VidModeModModeLine', 'X_XF86VidModeSwitchMode',282'X_XF86VidModeGetMonitor', 'X_XF86VidModeLockModeSwitch',283'X_XF86VidModeGetAllModeLines', 'X_XF86VidModeAddModeLine',284'X_XF86VidModeDeleteModeLine', 'X_XF86VidModeValidateModeLine',285'X_XF86VidModeSwitchToMode', 'X_XF86VidModeGetViewPort',286'X_XF86VidModeSetViewPort', 'X_XF86VidModeGetDotClocks',287'X_XF86VidModeSetClientVersion', 'X_XF86VidModeSetGamma',288'X_XF86VidModeGetGamma', 'X_XF86VidModeGetGammaRamp',289'X_XF86VidModeSetGammaRamp', 'X_XF86VidModeGetGammaRampSize',290'X_XF86VidModeGetPermissions', 'CLKFLAG_PROGRAMABLE',291'XF86VidModeNumberEvents', 'XF86VidModeBadClock', 'XF86VidModeBadHTimings',292'XF86VidModeBadVTimings', 'XF86VidModeModeUnsuitable',293'XF86VidModeExtensionDisabled', 'XF86VidModeClientNotLocal',294'XF86VidModeZoomLocked', 'XF86VidModeNumberErrors', 'XF86VM_READ_PERMISSION',295'XF86VM_WRITE_PERMISSION', 'XF86VidModeModeLine', 'XF86VidModeModeInfo',296'XF86VidModeSyncRange', 'XF86VidModeMonitor', 'XF86VidModeNotifyEvent',297'XF86VidModeGamma', 'XF86VidModeQueryVersion', 'XF86VidModeQueryExtension',298'XF86VidModeSetClientVersion', 'XF86VidModeGetModeLine',299'XF86VidModeGetAllModeLines', 'XF86VidModeAddModeLine',300'XF86VidModeDeleteModeLine', 'XF86VidModeModModeLine',301'XF86VidModeValidateModeLine', 'XF86VidModeSwitchMode',302'XF86VidModeSwitchToMode', 'XF86VidModeLockModeSwitch',303'XF86VidModeGetMonitor', 'XF86VidModeGetViewPort', 'XF86VidModeSetViewPort',304'XF86VidModeGetDotClocks', 'XF86VidModeGetGamma', 'XF86VidModeSetGamma',305'XF86VidModeSetGammaRamp', 'XF86VidModeGetGammaRamp',...
crawArticle.py
Source:crawArticle.py
1# crawArticle.py2# coding=utf-83# author=zhouj4import re5import urllib6import datetime7import time8from bs4 import BeautifulSoup9from agent import *10from match import *11from formatter import *12#é»è®¤utf-8 ç¼ç 13reload(sys)14sys.setdefaultencoding('utf-8')15#è·åæç« title16def get_title(soup, mode):17 #éæ¥é误信æ¯18 if mode == 0 or mode == 1:19 title = soup.select('.arc-tit')20 elif mode == 2 or mode == 3:21 title = soup.select('.left521')22 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:23 title = soup.find('h1')24 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:25 title = soup.select('h1[class="title"]')26 elif mode == 14:27 title = soup.select('h1[class="article-title"]')28 elif mode == 15:29 title = soup.select('.title')30 if type(title) == list :31 for i in range(0, title.__len__()):32 title[i] = str(title[i])33 title = "".join(title)34 r = r'>([\s\S]*?)<'35 re_title = re.compile(r)36 titles = re.findall(re_title, str(title))37 return titles[0].strip()38#è·åæç« å
容39def get_content(soup, mode):40 if mode == 0 or mode == 1:41 content = soup.select('.arc-body')42 elif mode == 2 or mode == 3:43 content = soup.select('.left523')44 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:45 content = soup.select('.note-editing-area')46 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:47 content = soup.select('.post-content')48 elif mode == 14:49 content = soup.select('.article-content')50 elif mode == 15:51 content = soup.select('.visible-sm')52 for i in range(0, content.__len__()):53 content[i] = str(content[i])54 return "".join(content)55#对äºvrzincç½ç«çæ¶é´ç¹æ®å¤ç56def vrzinc_get_time(create_time):57 r = r'</i>([\s\S]*?)</span>'58 re_time = re.compile(r)59 create_time = re.findall(re_time, create_time)60 #对äºvrzincç½ç« ç¹æ®å¤ç61 mytime = re.findall(r'\((.*?)\)', create_time[0])62 if mytime.__len__() > 0:63 return time.strftime("%Y-") + mytime[0]64 else:65 if create_time[0].find('天') != -1 :66 re_time = re.compile(r'[0-9]+')67 create_time = re.findall(re_time, create_time[0])68 cur_time = datetime.datetime.now()69 d = int(create_time[0])70 return (cur_time - datetime.timedelta(days=d)).strftime("%Y-%m-%d")71 return time.strftime("%Y-%m-%d")72#è·åæç« æ¶é´73def get_time(soup, mode):74 if mode == 0 or mode == 1:75 create_time = soup.select('.time')76 elif mode == 2 or mode == 3:77 create_time = soup.select('.left522')78 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:79 create_time = soup.select('.data-item')80 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:81 create_time = soup.select('.postclock')82 elif mode == 14:83 create_time = soup.select('time[class="muted"]')84 elif mode == 15:85 create_time = soup.select('.data-item')86 for i in range(0, create_time.__len__()):87 create_time[i] = str(create_time[i])88 create_time = "".join(create_time)89 #æåæ¶é´90 if mode == 0 or mode == 1:91 r = r'>(.+)<'92 elif mode == 2 or mode == 3:93 r = r'åå¸æ¶é´ï¼(.+?)\s'94 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:95 r = r'[0-9]*-[0-9]*?-[0-9]*'96 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:97 return vrzinc_get_time(create_time)98 elif mode == 14 or mode == 15:99 r = r'[0-9]*-[0-9]*?-[0-9]*'100 re_time = re.compile(r)101 create_time = re.findall(re_time, create_time)102 103 return create_time[0]104#è·åæç« å¾ç105def get_img(content, mode):106 reg = r'src="(.+?)"'107 imgre = re.compile(reg)108 imglist = re.findall(imgre,content)109 imgDir = '/Users/zhoujl/Desktop/vr/auto/images/'110 imgDir1 ='./'111 if mode == 0 or mode == 1:112 imgDir = imgDir + 'c/'113 elif mode == 2 or mode == 3:114 imgDir = imgDir + 'd/'115 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:116 imgDir = imgDir + 'a/'117 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:118 imgDir = imgDir + 'b/'119 elif mode == 14:120 imgDir = imgDir + 'e/'121 flag = 0122 preimage = './images/common.jpg'123 for imgurl in imglist:124 r=r'.+/(.+)'125 imgName=re.compile(r)126 imgName=re.findall(imgName,imgurl)127 imgPath=imgDir+imgName[0]128 imgPath=imgPath.replace('-moduo', '')129 try:130 #ä¸è½½å¾ç131 urllib.urlretrieve(imgurl, imgPath)132 except IOError:133 print "Error: 没ææ¾å°å¾ç" + imgurl134 #ææ¬ä¸å¾çè·¯å¾æ¿æ¢135 imgPath = imgPath.replace('/Users/zhoujl/Desktop/vr/auto', '.')136 content = content.replace(imgurl, imgPath)137 #æ·»å é¢è§å¾138 if flag == 0:139 preimage = imgPath140 flag = 1141 return content, preimage142def get_source(mode):143 if mode == 0 or mode == 1:144 return 'ç¾åº¦VR'145 elif mode == 2 or mode == 3:146 return 'VRæ¥æ¥'147 elif mode == 4 or mode == 5 or mode == 6 or mode == 7:148 return 'moduoéå¤'149 elif mode == 8 or mode == 9 or mode == 10 or mode == 11 or mode == 12 or mode == 13:150 return 'vrzinc'151 elif mode == 14:152 return 'VRç§æç½'153def get_label(title, content):154 flag = 0155 if title.find('Oculus') != -1 or content.find('Oculus') != -1:156 label = 'Oculus'157 flag = 1158 if title.find('HTC') != -1 or content.find('HTC') != -1:159 if flag == 1:160 label = label + '|' + 'HTC'161 else:162 label = 'HTC'163 flag = 1164 if title.find('PSVR') != -1 or content.find('PSVR') != -1 or title.find('索尼') != -1 or content.find('索尼') != -1:165 if flag == 1:166 label = label + '|' + '索尼'167 else:168 label = '索尼'169 flag = 1170 if flag == 1:171 return label172 return ''173#ç¬åæç« ,并åæsqlè¯å¥174def get_article(url, mode):175 #è·åæç« html176 html = url_user_agent(url, mode)177 soup = BeautifulSoup(html, "html.parser")178 #è·åæ¶é´ãæ é¢179 title = get_title(soup,mode).decode('utf-8')180 time = get_time(soup, mode)181 #æ¯å¦æå该æç« 182 if title_match(title, mode) == False:183 return False,'','','','','','',''184 if time_match(time, mode) == False:185 return False,'','','','','','',''186 if (title.__len__() == 0):187 return False,'','','','','','',''188 #æåå
容189 content = get_content(soup, mode)190 #è¾åº æ£ç¡®æ ¼å¼191 preinfo, content = arrage_art_content(content, mode)192 #è·åæ ç¾193 label = get_label(title, content)194 #è·åæç« å¾ç195 content, preimage = get_img(content,mode)196 source = get_source(mode)...
ops.py
Source:ops.py
1from enum import Enum, Flag, auto2class Mode(Flag):3 """Enum of program running modes."""4 5 Signature = auto()6 Application = auto()7Mode.__module__ = "pyteal"8class Op(Enum):9 """Enum of program opcodes."""10 err = "err", Mode.Signature | Mode.Application11 sha256 = "sha256", Mode.Signature | Mode.Application12 keccak256 = "keccak256", Mode.Signature | Mode.Application13 sha512_256 = "sha512_256", Mode.Signature | Mode.Application14 ed25519verify = "ed25519verify", Mode.Signature15 add = "+", Mode.Signature | Mode.Application16 minus = "-", Mode.Signature | Mode.Application17 div = "/", Mode.Signature | Mode.Application18 mul = "*", Mode.Signature | Mode.Application19 lt = "<", Mode.Signature | Mode.Application20 gt = ">", Mode.Signature | Mode.Application21 le = "<=", Mode.Signature | Mode.Application22 ge = ">=", Mode.Signature | Mode.Application23 logic_and = "&&", Mode.Signature | Mode.Application24 logic_or = "||", Mode.Signature | Mode.Application25 eq = "==", Mode.Signature | Mode.Application26 neq = "!=", Mode.Signature | Mode.Application27 logic_not = "!", Mode.Signature | Mode.Application28 len = "len", Mode.Signature | Mode.Application29 itob = "itob", Mode.Signature | Mode.Application30 btoi = "btoi", Mode.Signature | Mode.Application31 mod = "%", Mode.Signature | Mode.Application32 bitwise_or = "|", Mode.Signature | Mode.Application33 bitwise_and = "&", Mode.Signature | Mode.Application34 bitwise_xor = "^", Mode.Signature | Mode.Application35 bitwise_not = "~", Mode.Signature | Mode.Application36 mulw = "mulw", Mode.Signature | Mode.Application37 addw = "addw", Mode.Signature | Mode.Application38 int = "int", Mode.Signature | Mode.Application39 byte = "byte", Mode.Signature | Mode.Application40 addr = "addr", Mode.Signature | Mode.Application41 arg = "arg", Mode.Signature42 txn = "txn", Mode.Signature | Mode.Application43 global_ = "global", Mode.Signature | Mode.Application44 gtxn = "gtxn", Mode.Signature | Mode.Application45 load = "load", Mode.Signature | Mode.Application46 store = "store", Mode.Signature | Mode.Application47 txna = "txna", Mode.Signature | Mode.Application48 gtxna = "gtxna", Mode.Signature | Mode.Application49 bnz = "bnz", Mode.Signature | Mode.Application50 bz = "bz", Mode.Signature | Mode.Application51 b = "b", Mode.Signature | Mode.Application52 return_ = "return", Mode.Signature | Mode.Application53 pop = "pop", Mode.Signature | Mode.Application54 dup = "dup", Mode.Signature | Mode.Application55 dup2 = "dup2", Mode.Signature | Mode.Application56 concat = "concat", Mode.Signature | Mode.Application57 substring = "substring", Mode.Signature | Mode.Application58 substring3 = "substring3", Mode.Signature | Mode.Application59 balance = "balance", Mode.Application60 app_opted_in = "app_opted_in", Mode.Application61 app_local_get = "app_local_get", Mode.Application62 app_local_get_ex = "app_local_get_ex", Mode.Application63 app_global_get = "app_global_get", Mode.Application64 app_global_get_ex = "app_global_get_ex", Mode.Application65 app_local_put = "app_local_put", Mode.Application66 app_global_put = "app_global_put", Mode.Application67 app_local_del = "app_local_del", Mode.Application68 app_global_del = "app_global_del", Mode.Application69 asset_holding_get = "asset_holding_get", Mode.Application70 asset_params_get = "asset_params_get", Mode.Application71 def __new__(cls, value: str, mode: Mode):72 obj = object.__new__(cls)73 obj._value_ = value74 return obj75 def __init__(self, value: str, mode: Mode):76 self.mode = mode...
JamEvoModes.py
Source:JamEvoModes.py
...21 self._push_pad_mode.handle_shift(shift_value)22 super(JamEvoModes, self).notify_shift(shift_value)23 # Override24 @subject_slot('value')25 def _do_pad_mode(self, value):26 if self.__pad_down and value == 0:27 if self._mode_group != MG_PAD:28 self._is_push_mode = self.is_shift_down()29 if self._is_push_mode:30 self.enter_push_pad_mode()31 else:32 self.enter_pad_mode()33 else:34 self.enter_clip_mode()35 self._mode_group = MG_CLIP36 self.__pad_down = value != 037 # Override38 def selected_mode(self, value):39 if value == 'push_pad_mode':40 self.enter_push_pad_mode(False)41 else:42 super(JamEvoModes, self).selected_mode(value)43 # Override44 def __handle_possible_instrument_change(self):45 drum_device = find_drum_device(self.song().view.selected_track)46 if drum_device:47 if self._mode == self._pad_mode:48 self.enter_pad_mode()49 elif self._mode == self._push_pad_mode:50 self.enter_push_pad_mode()51 elif self._mode == self._step_mode:52 self.enter_step_mode(False, True)53 elif self._mode == self._drum_pad_mode:54 if self._is_push_mode:55 self.enter_push_pad_mode()56 else:57 self.enter_pad_mode()58 elif self._mode == self._drum_step_mode:59 self.enter_step_mode(False, True)60 def enter_push_pad_mode(self, show_info = True, check_drum_device = 0):61 if show_info:62 self._show_msg_callback('Push Style PAD Mode')63 selected_track = self.song().view.selected_track64 if not selected_track or not selected_track.has_midi_input:65 return66 drum_device = find_drum_device(selected_track)67 if drum_device:68 with self.rebuild():69 self._mode.exit()70 self._mode.spec_unbind()71 self._mode = self._drum_pad_mode72 self._light_button(1)73 self._mode.enter()74 else:...
qdedit.py
Source:qdedit.py
1f = Function(void, 'SetPort',2 (GrafPtr, 'thePort', InMode),3)4functions.append(f)5f = Function(CursHandle, 'GetCursor',6 (short, 'cursorID', InMode),7)8functions.append(f)9f = Function(void, 'SetCursor',10 (Cursor_ptr, 'crsr', InMode),11)12functions.append(f)13f = Function(void, 'ShowCursor',14)15functions.append(f)16f = Function(void, 'LineTo',17 (short, 'h', InMode),18 (short, 'v', InMode),19)20functions.append(f)21f = Function(void, 'SetRect',22 (Rect, 'r', OutMode),23 (short, 'left', InMode),24 (short, 'top', InMode),25 (short, 'right', InMode),26 (short, 'bottom', InMode),27)28functions.append(f)29f = Function(void, 'OffsetRect',30 (Rect, 'r', InOutMode),31 (short, 'dh', InMode),32 (short, 'dv', InMode),33)34functions.append(f)35f = Function(void, 'InsetRect',36 (Rect, 'r', InOutMode),37 (short, 'dh', InMode),38 (short, 'dv', InMode),39)40functions.append(f)41f = Function(void, 'UnionRect',42 (Rect_ptr, 'src1', InMode),43 (Rect_ptr, 'src2', InMode),44 (Rect, 'dstRect', OutMode),45)46functions.append(f)47f = Function(Boolean, 'EqualRect',48 (Rect_ptr, 'rect1', InMode),49 (Rect_ptr, 'rect2', InMode),50)51functions.append(f)52f = Function(void, 'FrameRect',53 (Rect_ptr, 'r', InMode),54)55functions.append(f)56f = Function(void, 'InvertRect',57 (Rect_ptr, 'r', InMode),58)59functions.append(f)60f = Function(void, 'FillRect',61 (Rect_ptr, 'r', InMode),62 (Pattern_ptr, 'pat', InMode),63)64functions.append(f)65f = Function(void, 'CopyRgn',66 (RgnHandle, 'srcRgn', InMode),67 (RgnHandle, 'dstRgn', InMode),68)69functions.append(f)70f = Function(void, 'SetRectRgn',71 (RgnHandle, 'rgn', InMode),72 (short, 'left', InMode),73 (short, 'top', InMode),74 (short, 'right', InMode),75 (short, 'bottom', InMode),76)77functions.append(f)78f = Function(void, 'OffsetRgn',79 (RgnHandle, 'rgn', InMode),80 (short, 'dh', InMode),81 (short, 'dv', InMode),82)83functions.append(f)84f = Function(void, 'UnionRgn',85 (RgnHandle, 'srcRgnA', InMode),86 (RgnHandle, 'srcRgnB', InMode),87 (RgnHandle, 'dstRgn', InMode),88)89functions.append(f)90f = Function(void, 'XorRgn',91 (RgnHandle, 'srcRgnA', InMode),92 (RgnHandle, 'srcRgnB', InMode),93 (RgnHandle, 'dstRgn', InMode),94)95functions.append(f)96f = Function(Boolean, 'EqualRgn',97 (RgnHandle, 'rgnA', InMode),98 (RgnHandle, 'rgnB', InMode),99)100functions.append(f)101f = Function(void, 'FrameRgn',102 (RgnHandle, 'rgn', InMode),103)104functions.append(f)105f = Function(void, 'PaintRgn',106 (RgnHandle, 'rgn', InMode),107)108functions.append(f)109f = Function(void, 'InvertRgn',110 (RgnHandle, 'rgn', InMode),111)112functions.append(f)113f = Function(void, 'FillRgn',114 (RgnHandle, 'rgn', InMode),115 (Pattern_ptr, 'pat', InMode),116)117functions.append(f)118f = Function(Boolean, 'GetPixel',119 (short, 'h', InMode),120 (short, 'v', InMode),121)122functions.append(f)123f = Function(Boolean, 'PtInRect',124 (Point, 'pt', InMode),125 (Rect_ptr, 'r', InMode),126)127functions.append(f)128f = Function(void, 'DrawText',129 (TextThingie, 'textBuf', InMode),130 (short, 'firstByte', InMode),131 (short, 'byteCount', InMode),132)...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data.data.median.firstView.SpeedIndex);7 });8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11 if (err) return console.error(err);12 wpt.getTestResults(data.data.testId, function(err, data) {13 if (err) return console.error(err);14 console.log(data.data.median.firstView.SpeedIndex);15 });16});17runTest(url, options, callback)18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20 if (err)
Using AI Code Generation
1var wpt = require('webpagetest');2var wptClient = wpt('www.webpagetest.org');3wptClient.getLocations(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10{ data: 11 { location: 12 [ { id: 'Dulles:Chrome',13 browser: 'Chrome' },14 { id: 'Dulles:Firefox',15 browser: 'Firefox' },16 { id: 'Dulles_IE8',17 browser: 'IE8' },18 { id: 'Dulles_IE9',19 browser: 'IE9' },20 { id: 'Dulles_IE10',21 browser: 'IE10' },22 { id: 'Dulles_IE11',23 browser: 'IE11' },24 { id: 'Dulles:Opera',25 browser: 'Opera' },26 { id: 'Dulles:Safari',27 browser: 'Safari' },28 { id: 'Dulles_iOS',
Using AI Code Generation
1var wpt = require('wpt');2wpt.getLocations(function(err, data) {3 if (err) console.log(err);4 console.log(data);5});6 if (err) console.log(err);7 console.log(data);8});9wpt.getTestStatus('130521_6G_1R', function(err, data) {10 if (err) console.log(err);11 console.log(data);12});13wpt.getTestResults('130521_6G_1R', function(err, data) {14 if (err) console.log(err);15 console.log(data);16});17wpt.getTestResults('130521_6G_1R', {video: 1}, function(err, data) {18 if (err) console.log(err);19 console.log(data);20});21wpt.getTestResults('130521_6G_1R', {requests: 1}, function(err, data) {22 if (err) console.log(err);23 console.log(data);24});25wpt.getTestResults('130521_6G_1R', {pagespeed: 1}, function(err, data) {26 if (err) console.log(err);27 console.log(data);28});29wpt.getTestResults('130521_6G_1R', {timeline: 1}, function(err, data) {30 if (err) console.log(err);31 console.log(data);32});33wpt.getTestResults('130521_6G_1R', {breakdown: 1}, function(err, data) {34 if (err) console.log(err);35 console.log(data);36});37wpt.getTestResults('130521_6G_1R', {domains: 1}, function(err, data) {38 if (err) console.log(err);39 console.log(data);40});41wpt.getTestResults('130521_6G_1R', {medianMetric: 1}, function(err, data) {42 if (err) console.log(err);43 console.log(data);44});45wpt.getTestResults('130521_6G_1R', {checklist: 1}, function(err, data) {46 if (err) console.log(err);47 console.log(data);48});
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.mode('mobile', options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.mode(options, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var options = {23};24wpt.mode(options, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('wpt');32var options = {33};34wpt.mode(options, function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42var options = {43};44wpt.mode(options, function(err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});51var wpt = require('wpt');52var options = {53};54wpt.mode(options, function(err, data) {55 if (err) {56 console.log(err);57 } else {58 console.log(data);59 }60});61var wpt = require('wpt');62var options = {
Using AI Code Generation
1var wpt = require('./wpt');2wpt.mode(url, function(data){3 console.log(data);4});5var request = require('request');6var wpt = {7 mode: function(url, callback){8 var options = {9 };10 request(options, function(err, res, body){11 if(err){12 console.log(err);13 return;14 }15 callback(body);16 });17 }18};19module.exports = wpt;20var wpt = require('./wpt');21wpt.mode(url, function(data){22 console.log(data);23 wpt.result(data, function(data){24 console.log(data);25 });26});27var request = require('request');28var wpt = {29 mode: function(url, callback){30 var options = {31 };32 request(options, function(err, res, body){33 if(err){34 console.log(err);35 return;36 }37 callback(body);38 });39 },40 result: function(url, callback){41 var options = {42 };43 request(options, function(err, res, body){44 if(err){45 console.log(err);46 return;47 }48 callback(body);49 });50 }51};52module.exports = wpt;
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9]);3var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9]);4var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9,9]);5var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9,9,9]);6var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9,9,9,9]);7var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9,9,9,9,9]);8var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9,9,9,9,9,9,9,9,9,9]);9var mode = wptoolkit.mode([1,2,3,4,5,5,6,7,7,7,8,9,9
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!!