How to use _clearEventQueue method in pyatom

Best Python code snippet using pyatom_python

AXClasses.py

Source: AXClasses.py Github

copy

Full Screen

...182 while len(self.eventList) > 0:183 (nextEvent, args) = self.eventList.popleft()184 nextEvent(*args)185 time.sleep(interval)186 def _clearEventQueue(self):187 """Clear the event queue."""188 if hasattr(self, 'eventList'):189 self.eventList.clear()190 def _queueEvent(self, event, args):191 """Private method to queue events to run.192 Each event in queue is a tuple (event call, args to event call).193 """194 if not hasattr(self, 'eventList'):195 self.eventList = deque([(event, args)])196 return197 self.eventList.append((event, args))198 def _addKeyToQueue(self, keychr, modFlags=0, globally=False):199 """Add keypress to queue.200 Parameters: key character or constant referring to a non-alpha-numeric201 key (e.g. RETURN or TAB)202 modifiers203 global or app specific204 Returns: None or raise ValueError exception.205 """206 # Awkward, but makes modifier-key-only combinations possible207 # (since sendKeyWithModifiers() calls this)208 if not keychr:209 return210 if not hasattr(self, 'keyboard'):211 self.keyboard = AXKeyboard.loadKeyboard()212 if keychr in self.keyboard['upperSymbols'] and not modFlags:213 self._sendKeyWithModifiers(keychr,214 [AXKeyCodeConstants.SHIFT],215 globally)216 return217 if keychr.isupper() and not modFlags:218 self._sendKeyWithModifiers(219 keychr.lower(),220 [AXKeyCodeConstants.SHIFT],221 globally222 )223 return224 if keychr not in self.keyboard:225 self._clearEventQueue()226 raise ValueError('Key %s not found in keyboard layout' % keychr)227 # Press the key228 keyDown = Quartz.CGEventCreateKeyboardEvent(None,229 self.keyboard[keychr],230 True)231 # Release the key232 keyUp = Quartz.CGEventCreateKeyboardEvent(None,233 self.keyboard[keychr],234 False)235 # Set modflags on keyDown (default None):236 Quartz.CGEventSetFlags(keyDown, modFlags)237 # Set modflags on keyUp:238 Quartz.CGEventSetFlags(keyUp, modFlags)239 # Post the event to the given app240 if not globally:241 self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), keyDown))242 self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), keyUp))243 else:244 self._queueEvent(Quartz.CGEventPost, (0, keyDown))245 self._queueEvent(Quartz.CGEventPost, (0, keyUp))246 def _sendKey(self, keychr, modFlags=0, globally=False):247 """Send one character with no modifiers.248 Parameters: key character or constant referring to a non-alpha-numeric249 key (e.g. RETURN or TAB)250 modifier flags,251 global or app specific252 Returns: None or raise ValueError exception253 """254 escapedChrs = {255 '\n': AXKeyCodeConstants.RETURN,256 '\r': AXKeyCodeConstants.RETURN,257 '\t': AXKeyCodeConstants.TAB,258 }259 if keychr in escapedChrs:260 keychr = escapedChrs[keychr]261 self._addKeyToQueue(keychr, modFlags, globally=globally)262 self._postQueuedEvents()263 def _sendKeys(self, keystr):264 """Send a series of characters with no modifiers.265 Parameters: keystr266 Returns: None or raise ValueError exception267 """268 for nextChr in keystr:269 self._sendKey(nextChr)270 def _pressModifiers(self, modifiers, pressed=True, globally=False):271 """Press given modifiers (provided in list form).272 Parameters: modifiers list, global or app specific273 Optional: keypressed state (default is True (down))274 Returns: Unsigned int representing flags to set275 """276 if not isinstance(modifiers, list):277 raise TypeError('Please provide modifiers in list form')278 if not hasattr(self, 'keyboard'):279 self.keyboard = AXKeyboard.loadKeyboard()280 modFlags = 0281 # Press given modifiers282 for nextMod in modifiers:283 if nextMod not in self.keyboard:284 errStr = 'Key %s not found in keyboard layout'285 self._clearEventQueue()286 raise ValueError(errStr % self.keyboard[nextMod])287 modEvent = Quartz.CGEventCreateKeyboardEvent(288 Quartz.CGEventSourceCreate(0),289 self.keyboard[nextMod],290 pressed291 )292 if not pressed:293 # Clear the modflags:294 Quartz.CGEventSetFlags(modEvent, 0)295 if globally:296 self._queueEvent(Quartz.CGEventPost, (0, modEvent))297 else:298 self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), modEvent))299 # Add the modifier flags...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

Your Favorite Dev Browser Has Evolved! The All New LT Browser 2.0

We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.

Do you possess the necessary characteristics to adopt an Agile testing mindset?

To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.

Starting & growing a QA Testing career

The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.

Quick Guide To Drupal Testing

Dries Buytaert, a graduate student at the University of Antwerp, came up with the idea of developing something similar to a chat room. Moreover, he modified the conventional chat rooms into a website where his friends could post their queries and reply through comments. However, for this project, he thought of creating a temporary archive of posts.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

Run pyatom automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful