How to use analyze_tracks method in ATX

Best Python code snippet using ATX Github


Full Screen

...352 e = self.touches[i]353 if e is None:354 continue355 if e.msg == HC.TOUCH_DOWN and now - e.time > self.long_press_delay:356 self.analyze_tracks(TouchTimeoutEvent(now, HC.TOUCH_PRESS_TIMEOUT, i))357 self.touches[i] = None358 elif e.msg == HC.TOUCH_UP and now - e.time > self.double_tap_delay:359 self.analyze_tracks(TouchTimeoutEvent(now, HC.TOUCH_FOLLOW_TIMEOUT, i))360 self.touches[i] = None361 elif e.msg == HC.TOUCH_MOVE and now - e.time > self.move_stop_delay:362 self.analyze_tracks(TouchTimeoutEvent(now, HC.TOUCH_MOVESTOP_TIMEOUT, i))363 self.touches[i] = None364 except:365 traceback.print_exc()366367 print 'process done.'368369 def handle_event(self, event):370 self.dispatch_event(event.msg, event)371 if event.msg & HC.KEY_ANY:372 self.dispatch_event(HC.KEY_ANY, event)373 else:374 self.dispatch_event(HC.TOUCH_ANY, event)375 self.analyze_tracks(event)376377 def dispatch_event(self, msg, event):378 func = self.dispatch_map.get(msg)379 if func is None:380 return381 try:382 func(event)383 except:384 traceback.print_exc()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,545 HC.TOUCH_FOLLOW_TIMEOUT : TRIGGERED,546 },547 STAGE_1: {548 HC.TOUCH_MOVE: NOTACTIVE,549 HC.TOUCH_PRESS_TIMEOUT : NOTACTIVE,550 HC.TOUCH_FOLLOW_TIMEOUT : TRIGGERED,551 }552 },553 HC.GST_SWIPE: {554 NOTACTIVE: { HC.TOUCH_DOWN: ACTIVE },555 ACTIVE: { HC.TOUCH_UP: NOTACTIVE, HC.TOUCH_MOVE: STAGE_1},556 STAGE_1: { HC.TOUCH_UP: NOTACTIVE, HC.TOUCH_MOVE: STAGE_2 },557 STAGE_2: { HC.TOUCH_UP: TRIGGERED, HC.TOUCH_MOVESTOP_TIMEOUT: TRIGGERED},558 },559 }560561 def __init__(self, queue):562 super(self.__class__, self).__init__(queue)563 self.state = {}564 for k in self.state_map:565 self.state[k] = NOTACTIVE566 print self.state_map567568 def analyze_tracks(self, event):569 for k, v in self.state.iteritems():570 s = self.state_map.get(k, {}).get(v, {}).get(event.msg)571 if s is not None:572 self.state[k] = s573 triggered = False574 for k, v in self.state.iteritems():575 if v == TRIGGERED:576 print 'trigger event', k577 triggered = True578 if triggered:579 for k in self.state:580 self.state[k] = NOTACTIVE581582class AndroidInputHookManager(object): ...

Full Screen

Full Screen Github


Full Screen

1import re2from setuptools import setup3 4 5with open("", "rb") as f:6 description ="utf-8")7 8setup(9 name = "analyze_tracks",10 packages = ["analyze_tracks"],11 entry_points = {12 "console_scripts": ['analyze_tracks_cli = analyze_tracks.main_cli:main']13 },14 version = "0.1",15 description = description,16 long_description = description,17 author = "Christoph Sommer",18 author_email = "",...

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?