How to use handle_gesture method in ATX

Best Python code snippet using ATX Github


Full Screen

...385386 def analyze_tracks(self, event):387 pass388389 def handle_gesture(self, msg, tracks):390 event = GestureEvent(msg, tracks)391 func = self.dispatch_map.get(msg)392 if func is None:393 return394 try:395 func(event)396 except:397 traceback.print_exc()398399## NOT COMPLEMENTED ##400class SimpleGestureRecognizer(GestureRecognizer):401402 N_FINGER = 2403404 def analyze_tracks(self, event):405 # handle one-finger and two-finger gestures only406 # means a third finger will be ignored even if one of the407 # first two fingers leaves the screen.408 i = event.slotid409410 # begin guesture when touch down411 if event.msg == HC.TOUCH_DOWN:412 if len(self.track_slots) == self.N_FINGER and i not in self.track_slots:413 return414 if self.tracks[i] is None:415 self.tracks[i] = []416 self.track_slots.add(i)417 self.tracks[i].append(event)418 return419420 if self.tracks[i] is None:421 return422423 if event.msg == HC.TOUCH_FOLLOW_TIMEOUT:424 self.tracks[i] = []425 elif event.msg == HC.TOUCH_PRESS_TIMEOUT:426 # print ''.join([HCREPR.get(e.msg) for e in self.tracks[i]]), 'long press'427 self.tracks[i] = []428 elif event.msg == HC.TOUCH_MOVESTOP_TIMEOUT:429 # print ''.join([HCREPR.get(e.msg) for e in self.tracks[i]]), 'drag'430 self.tracks[i] = []431 if len(self.track_slots) == 2:432 for s in self.track_slots:433 print s, ''.join([HCREPR.get(e.msg) for e in self.tracks[s]])434 print435 elif event.msg == HC.TOUCH_UP:436 self.tracks[i].append(event)437 if len(self.track_slots) == 2:438 for s in self.track_slots:439 print s, ''.join([HCREPR.get(e.msg) for e in self.tracks[s]])440 print441 self.tracks[i] = None442 self.track_slots.discard(i)443 else: # TOUCH_MOVE444 self.tracks[i].append(event)445 return446447 # check for pinch/pan448 if len(self.track_slots) == 2:449 t1, t2 = [self.tracks[s] for s in self.track_slots]450 if len(t1) == 0 or len(t2) == 0 or len(t1) + len(t2) < 6:451 return452 # make copy and check distance changing453 t1, t2 = t1[:], t2[:]454 dists = []455 while len(dists) < 5:456 e1, e2 = t1[-1], t2[-1]457 dx, dy = e1.x-e2.x, e1.y-e2.y458 dists.append(dx*dx+dy*dy)459 if e1.time < e2.time:460 if len(t2) == 1:461 break462 else:463 t2.pop()464 else:465 if len(t1) == 1:466 break467 else:468 t1.pop()469 print [dists[j+1]-dists[j] for j in range(len(dists)-1)]470 # just keep latest position471 for s in self.track_slots:472 self.tracks[s] = self.tracks[s][-1:]473474class RegexpGestureRecognizer(GestureRecognizer):475476 N_FINGER = 1477478 def analyze_tracks(self, event):479 # handle one-finger gestures only480 i = event.slotid481482 # begin guesture when touch down483 if event.msg == HC.TOUCH_DOWN:484 if len(self.track_slots) == self.N_FINGER and i not in self.track_slots:485 return486 if not self.tracks[i]:487 self.tracks[i] = []488 self.track_slots.add(i)489 self.tracks[i].append(event)490 return491492 if self.tracks[i] is None:493 return494495 s = ''.join([HCREPR.get(e.msg) for e in self.tracks[i]])496497 if event.msg == HC.TOUCH_FOLLOW_TIMEOUT:498 if re.match('^DM?U$', s):499 self.handle_gesture(HC.GST_TAP, self.tracks[i][:])500 elif re.match('^(DM?U)+DM?U$', s):501 self.handle_gesture(HC.GST_MULTI_TAP, self.tracks[i][:])502 self.tracks[i] = None503 self.track_slots.discard(i)504 elif event.msg == HC.TOUCH_MOVESTOP_TIMEOUT:505 if re.match('^D?MM+$', s):506 self.handle_gesture(HC.GST_DRAG, self.tracks[i][:])507 self.tracks[i] = []508 elif event.msg == HC.TOUCH_PRESS_TIMEOUT:509 if s == 'D':510 self.handle_gesture(HC.GST_LONG_PRESS, self.tracks[i][:])511 self.tracks[i] = []512 elif event.msg == HC.TOUCH_UP:513 self.tracks[i].append(event) # note: it's not the same with s after add514 if s == '':515 self.handle_gesture(HC.GST_LONG_PRESS_RELEASE, [event])516 elif re.match('^D?MM+$', s):517 self.handle_gesture(HC.GST_SWIPE, self.tracks[i][:])518 self.tracks[i] = []519 elif _MULTI_TAP_NUM == 1 and re.match('^DM?$', s):520 self.handle_gesture(HC.GST_TAP, self.tracks[i][:])521 self.tracks[i] = []522 elif _MULTI_TAP_NUM > 1 and re.match('^(DM?U){%d}DM?$' % (_MULTI_TAP_NUM-1,), s):523 self.handle_gesture(HC.GST_MULTI_TAP, self.tracks[i][:])524 self.tracks[i] = []525 elif event.msg == HC.TOUCH_MOVE:526 if re.match('^(DU)+D$', s):527 if s == 'DUD':528 self.handle_gesture(HC.GST_TAP, self.tracks[i][:-1])529 else:530 self.handle_gesture(HC.GST_MULTI_TAP, self.tracks[i][:-1])531 self.tracks[i] = self.tracks[i][-1:]532 self.tracks[i].append(event)533534NOTACTIVE, ACTIVE, STAGE_1, STAGE_2, TRIGGERED = range(5)535536## NOT COMPLEMENTED ##537class StateMachineGestureRecognizer(GestureRecognizer):538539 state_map = {540 HC.GST_TAP: {541 NOTACTIVE: { HC.TOUCH_DOWN : ACTIVE },542 ACTIVE: {543 HC.TOUCH_MOVE: STAGE_1,544 HC.TOUCH_PRESS_TIMEOUT : NOTACTIVE, ...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:


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

Run ATX automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?