Best Python code snippet using fMBT_python
fmbtx11_conn.py
Source:fmbtx11_conn.py
...173 u'Ã
': "Aring", u'Ã': "Adiaeresis", u'Ã': "Odiaeresis"}174 def __del__(self):175 if self._display:176 libX11.XCloseDisplay(self._display)177 def _typeChar(self, origChar, press=True, release=True, modifiers=[]):178 _modifiers = [libX11.XKeysymToKeycode(179 self._display, libX11.XStringToKeysym(c)) for c in modifiers]180 c = self._specialCharToXString.get(origChar, origChar)181 keysym = libX11.XStringToKeysym(c)182 if keysym == _NoSymbol:183 return False184 keycode = libX11.XKeysymToKeycode(self._display, keysym)185 first = (keycode - self._cMinKeycode.value) * self._cKeysymsPerKeycode.value186 for modifier_index, modifier in enumerate([self._shiftModifier, None, None, self._level3Modifier]):187 # see if a modifier is needed to produce a character188 if modifier == None: continue189 try:190 if isinstance(origChar, str) and chr(self._keysyms[first + modifier_index + 1]) == origChar:191 _modifiers.append(modifier)192 break193 elif isinstance(origChar, unicode) and unichr(self._keysyms[first + modifier_index + 1]) == origChar:194 _modifiers.append(modifier)195 break196 except ValueError: pass197 for m in _modifiers:198 libXtst.XTestFakeKeyEvent(self._display, m, _X_True, _X_CurrentTime)199 libX11.XFlush(self._display)200 if press:201 libXtst.XTestFakeKeyEvent(self._display, keycode, _X_True, _X_CurrentTime)202 if release:203 libXtst.XTestFakeKeyEvent(self._display, keycode, _X_False, _X_CurrentTime)204 libX11.XFlush(self._display)205 for m in _modifiers[::-1]:206 libXtst.XTestFakeKeyEvent(self._display, m, _X_False, _X_CurrentTime)207 libX11.XFlush(self._display)208 return True209 def sendKeyDown(self, key, modifiers=[]):210 return self._typeChar(key, press=True, release=False, modifiers=modifiers)211 def sendKeyUp(self, key, modifiers=[]):212 return self._typeChar(key, press=False, release=True, modifiers=modifiers)213 def sendPress(self, key, modifiers=[]):214 return self._typeChar(key, press=True, release=True, modifiers=modifiers)215 def sendTap(self, x, y, button=1):216 libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), _X_CurrentTime)217 libXtst.XTestFakeButtonEvent(self._display, button, _X_True, _X_CurrentTime)218 libXtst.XTestFakeButtonEvent(self._display, button, _X_False, _X_CurrentTime)219 libX11.XFlush(self._display)220 return True221 def sendTouchMove(self, x, y, button=None):222 libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), _X_CurrentTime)223 libX11.XFlush(self._display)224 return True225 def sendTouchDown(self, x, y, button=1):226 libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), _X_CurrentTime)227 libXtst.XTestFakeButtonEvent(self._display, button, _X_True, _X_CurrentTime)228 libX11.XFlush(self._display)...
player.py
Source:player.py
1from slugify import slugify2import pyfumbbl3from . import field4from . import helper5from .jsonfile import jsonfile6import cibblbibbl7class UnchainedPlayerException(Exception):8 pass9class BasePlayer(metaclass=cibblbibbl.helper.InstanceRepeater):10 config = field.config.CachedConfig()11 configfilename = field.filepath.idfilename12 dummy = field.config.DDField(default="no")13 Id = field.instrep.keyigetterproperty(0)14 matches = field.insts.matchups_matches15 matchups = cibblbibbl.team.Team.matchups16 position = field.inst.position_by_self_positionId17 adminspp = field.config.DDField(18 default=lambda inst, desc: dict()19 )20 prevId = field.config.DDField(21 default = lambda i, d: i.get_prevId(),22 default_set_delete = False,23 )24 prevachievmul = field.config.DDField(default=1)25 prevdeadmatchId = field.config.DDField()26 prevreason = field.config.DDField()27 prevsppmul = field.config.DDField(default=1)28 replays = field.insts.matches_replays29 def __init__(self, playerId,30 name = ...,31 team = ...,32 typechar = ...,33 ):34 self._matchups = {}35 self._name = name36 if name is not ...:37 self._name = helper.norm_name(name)38 self._team = team39 self._typechar = typechar40 self.achievements = set()41 self._nextIds = set()42 if hasattr(self, "get_nextIds"):43 self._nextIds |= self.get_nextIds()44 for p in self.nexts:45 p.prevId = self.Id46 prev = self.prev47 if prev:48 self.prevId = prev.Id # ensure saved in config49 prev._nextIds.add(self.Id)50 def __repr__(self):51 clsname = self.__class__.__name__52 return f'{clsname}({self.Id!r})'53 __str__ = field.inst.id_and_name_str54 __eq__ = field.ordering.eq_when_is55 __lt__ = field.ordering.PropTupCompar("sort_key")56 __le__ = field.ordering.PropTupCompar("sort_key")57 __ne__ = field.ordering.ne_when_is_not58 __gt__ = field.ordering.PropTupCompar("sort_key")59 __ge__ = field.ordering.PropTupCompar("sort_key")60 @staticmethod61 def configfilepathroot():62 return cibblbibbl.data.path / "player"63 @property64 def configfilepath(self):65 return self.configfilepathroot() / self.configfilename66 @property67 def name(self):68 if self._name is ...:69 self._name = helper.norm_name(self.getname)70 return self._name71 @property72 def nexts(self):73 nextIds = self._nextIds74 if nextIds is not None:75 return set(player(Id) for Id in list(nextIds))76 @property77 def prev(self):78 prevId = self.prevId79 if prevId is not None:80 return player(prevId)81 @property82 def team(self):83 if self._team is ...:84 teamId = self.config.get("team")85 if teamId is not None:86 self._team = cibblbibbl.team.Team(int(teamId))87 elif (88 self.prev and isinstance(self.prev, RaisedDeadPlayer)89 ):90 return self.prev.team91 else:92 raise ValueError(f'no team: {self!r}')93 return self._team94 @team.setter95 def team(self, value):96 self._team = value97 self.config["team"] = value.Id98 @team.deleter99 def team(self):100 self._team = ...101 try:102 del self.config["team"]103 except KeyError:104 pass105 @property106 def typechar(self):107 if self._typechar is ...:108 self._typechar = self.config.get("typechar")109 return self._typechar110 @typechar.setter111 def typechar(self, value):112 self._typechar = value113 self.config["typechar"] = value114 @typechar.deleter115 def typechar(self):116 self._typechar = ...117 try:118 del self.config["typechar"]119 except KeyError:120 pass121 # TODO prevId setter which backchains instantly122 def get_prevId(self):123 return None124 def prespp(self, matchup):125 value = matchup.performance(self).get("prespp", 0)126 matchId = matchup.match.Id127 for matchId1, value1 in self.adminspp.items():128 if int(matchId1) <= matchId:129 value += value1130 return value131class MercenaryPlayer(BasePlayer):132 permanent = field.common.Constant(False)133 prevsppmul = field.config.DDField(default=0)134 status = field.common.Constant("Active")135 @property136 def getname(self):137 replayId, playerId = self.Id[5:].split("-")138 Re = cibblbibbl.replay.Replay(int(replayId))139 Te = cibblbibbl.team.Team(int(playerId.split("M")[0]))140 with Re as Re:141 D = Re.normteamdata[Te]142 for d in D["playerArray"]:143 if d["playerId"] == self.Id: # ! NOT playerId144 break145 else:146 raise Exception(f'not found: {self.Id}')147 return d["playerName"]148 @property149 def positionId(self):150 replayId, playerId = self.Id[5:].split("-")151 Re = cibblbibbl.replay.Replay(int(replayId))152 Te = cibblbibbl.team.Team(int(playerId.split("M")[0]))153 with Re as Re:154 D = Re.normteamdata[Te]155 for d in D["playerArray"]:156 if d["playerId"] == self.Id: # ! NOT playerId157 break158 else:159 raise Exception(f'not found: {self.Id}')160 return d["positionId"]161 @property162 def sort_key(self):163 Id = self.Id[5:].replace("M", "-")164 idvals = tuple(int(x) for x in Id.split("-"))165 return (1000,) + idvals166 @property167 def team(self):168 return "Mercenary"169 @property170 def typechar(self):171 return "M"172 def prespp(self, matchup):173 return 0174class NormalPlayer(BasePlayer):175 apiget = field.fumbblapi.CachedFUMBBLAPIGetField(176 pyfumbbl.player.get,177 )178 permanent = field.common.Constant(True)179 positionId = field.common.DiggedKeys(180 "apiget", "position", "id",181 )182 status = field.common.DiggedKeys("apiget", "status")183 @property184 def getname(self):185 if self._name is ...:186 if "name" in self.config:187 self._name = self.config["name"]188 else:189 self._name = self.apiget["name"]190 return self._name191 @property192 def team(self):193 team = BasePlayer.team.fget(self)194 if team is None:195 prev = self.prev196 if isinstance(self.prev, RaisedDeadPlayer):197 self._team = self.prev.team198 return self._team199 team = team.setter(BasePlayer.team.fset)200 team = team.deleter(BasePlayer.team.fdel)201 @property202 def typechar(self):203 typechar = BasePlayer.typechar.fget(self)204 if typechar is None:205 self._typechar = "R"206 return self._typechar207 typechar = typechar.setter(BasePlayer.typechar.fset)208 typechar = typechar.deleter(BasePlayer.typechar.fdel)209 @property210 def sort_key(self):211 return (1, int(self.Id))212Player = NormalPlayer213class RaisedDeadPlayer(BasePlayer):214 getname = field.common.DiggedAttr("prev", "getname")215 permanent = field.common.Constant(True)216 prevsppmul = field.config.DDField(default=0)217 @property218 def next(self):219 nextId = self.nextId220 return (player(nextId) if nextId is not None else None)221 @property222 def nextId(self):223 nextId = self.Id.split("_")[-1]224 if nextId.startswith("UNKNOWN"):225 raise UnchainedPlayerException(226 f'unchained raised dead player: {self.Id}'227 )228 elif nextId != "0":229 return nextId230 @property231 def positionId(self):232 return self.Id.split("_")[0].split("-")[1]233 @property234 def prevdeadmatchId(self):235 matchId = self.config.get("prevdeadmatchId")236 if matchId:237 return matchId238 if isinstance(self.prev, RaisedDeadPlayer):239 return self.prev.prevdeadmatchId240 prevdeadmatchId = prevdeadmatchId.setter(241 field.config.setter("prevdeadmatchId")242 )243 prevdeadmatchId = prevdeadmatchId.deleter(244 field.config.deleter("prevdeadmatchId")245 )246 @property247 def sort_key(self):248 nextIds = self._nextIds249 if nextIds:250 return (1, int(next(iter(nextIds))) - 0.1)251 else:252 return (1, int(self.prevId) + 0.1)253 @property254 def status(self):255 next = self.next256 if next:257 return next.status258 else:259 return "Retired"260 @property261 def typechar(self):262 return "D"263 def get_nextIds(self):264 nextId = self.nextId265 return ({nextId} if nextId is not None else set())266 def get_prevId(self):267 return self.Id.split("_")[-2]268 def prespp(self, matchup):269 return 0270class StarPlayer(BasePlayer):271 config = field.config.CachedConfig()272 permanent = field.common.Constant(False)273 prevsppmul = field.config.DDField(default=0)274 status = field.config.DDField(default="Active")275 @property276 def configfilepath(self):277 return (278 cibblbibbl.data.path279 / "starplayer"280 / f'{slugify(self.Id[5:])}.json' # exclude STAR- prefix281 )282 @property283 def getname(self):284 return self.Id[5:] # exclude STAR- prefix285 @property286 def position(self):287 return None288 @property289 def positionId(self):290 return None291 @property292 def sort_key(self):293 return (100, self.Id)294 @property295 def team(self):296 return "Star Player"297 @property298 def typechar(self):299 return "S"300 def prespp(self, matchup):301 return 0302def iterexisting():303 directory = Player.configfilepathroot()304 for p in directory.glob("**/*.json"):305 playerId = p.stem306 Pl = player(playerId)307 yield Pl308def player(playerId, **kwargs):309 playerId = str(playerId)310 if playerId.isdecimal():311 return NormalPlayer(playerId, **kwargs)312 elif playerId.startswith("MERC"):313 return MercenaryPlayer(playerId, **kwargs)314 elif playerId.startswith("STAR"):315 return StarPlayer(playerId, **kwargs)316 elif playerId.startswith("RAISED"):317 return RaisedDeadPlayer(playerId, **kwargs)...
fmbtx11.py
Source:fmbtx11.py
...89 '?': "question", '@': "at"}90 def __del__(self):91 if self._display:92 self.libX11.XCloseDisplay(self._display)93 def _typeChar(self, origChar, press=True, release=True):94 modifiers = []95 c = self._specialCharToXString.get(origChar, origChar)96 keysym = self.libX11.XStringToKeysym(c)97 if keysym == self._NoSymbol:98 return False99 keycode = self.libX11.XKeysymToKeycode(self._display, keysym)100 first = (keycode - self._cMinKeycode.value) * self._cKeysymsPerKeycode.value101 for modifier_index, modifier in enumerate([self._shiftModifier, None, None, self._level3Modifier]):102 if modifier == None: continue103 try:104 if chr(self._keysyms[first + modifier_index + 1]) == origChar:105 modifiers.append(modifier)106 break107 except ValueError: pass108 for m in modifiers:109 self.libXtst.XTestFakeKeyEvent(self._display, m, self._X_True, self._X_CurrentTime)110 self.libX11.XFlush(self._display)111 if press:112 self.libXtst.XTestFakeKeyEvent(self._display, keycode, self._X_True, self._X_CurrentTime)113 if release:114 self.libXtst.XTestFakeKeyEvent(self._display, keycode, self._X_False, self._X_CurrentTime)115 self.libX11.XFlush(self._display)116 for m in modifiers[::-1]:117 self.libXtst.XTestFakeKeyEvent(self._display, m, self._X_False, self._X_CurrentTime)118 self.libX11.XFlush(self._display)119 return True120 def sendKeyDown(self, key):121 return self._typeChar(key, press=True, release=False)122 def sendKeyUp(self, key):123 return self._typeChar(key, press=False, release=True)124 def sendPress(self, key):125 return self._typeChar(key, press=True, release=True)126 def sendTap(self, x, y, button=1):127 self.libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), self._X_CurrentTime)128 self.libXtst.XTestFakeButtonEvent(self._display, button, self._X_True, self._X_CurrentTime)129 self.libXtst.XTestFakeButtonEvent(self._display, button, self._X_False, self._X_CurrentTime)130 self.libX11.XFlush(self._display)131 return True132 def sendTouchMove(self, x, y):133 self.libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), self._X_CurrentTime)134 self.libX11.XFlush(self._display)135 return True136 def sendTouchDown(self, x, y, button=1):137 self.libXtst.XTestFakeMotionEvent(self._display, self._current_screen, int(x), int(y), self._X_CurrentTime)138 self.libXtst.XTestFakeButtonEvent(self._display, button, self._X_True, self._X_CurrentTime)139 self.libX11.XFlush(self._display)...
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!!