Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 18, 2016
1 parent a6321c8 commit b24f64d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
37 changes: 11 additions & 26 deletions atx/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
from atx import imutils


log = logutils.getLogger(__name__)
log.setLevel(logging.DEBUG)
log = logutils.getLogger('atx')
log.setLevel(logging.INFO)

FindPoint = collections.namedtuple('FindPoint', ['pos', 'confidence', 'method', 'matched'])
UINode = collections.namedtuple('UINode', [
'xml',
Expand All @@ -47,7 +48,6 @@
'index', 'resource_id',
'text', 'content_desc',
'package'])
# Bounds = collections.namedtuple('Bounds', ['left', 'top', 'right', 'bottom'])

__dir__ = os.path.dirname(os.path.abspath(__file__))
__tmp__ = os.path.join(__dir__, '__cache__')
Expand Down Expand Up @@ -117,23 +117,21 @@ def __init__(self, device, name=None, timeout=None):
self.touched = {}
self.timeout = timeout

def on(self, image=None, actions=None, text=None):
def on(self, pattern, text=None):
"""Trigger when some object exists
Args:
image: string location of an image
flags: ACTION_TOUCH | ACTION_QUIT
pattern: image filename or Pattern
text: For uiautomator
Returns:
None
"""
if isinstance(image, basestring):
self._stored_selector = Pattern(image)
if isinstance(pattern, basestring):
self._stored_selector = Pattern(pattern)
elif text:
self._stored_selector = self._dev(text=text)

if actions:
self._events.append(Watcher.Event(image, actions))
self._stored_selector = None
else:
self._stored_selector = pattern
return self

def touch(self):
Expand All @@ -156,22 +154,10 @@ def _match(self, selector, screen):
''' returns position(x, y) or None'''
if isinstance(selector, Pattern):
ret = self._dev.exists(selector.image, screen=screen)
log.debug('watch match: %s, confidence: %s', selector, ret)
if ret is None:
return None
return ret.pos

# exists = False
# if ret.method == consts.IMAGE_MATCH_METHOD_TMPL:
# if ret.confidence > 0.8:
# exists = True
# # else:
# # print("Skip confidence:", ret.confidence)
# elif ret.method == consts.IMAGE_MATCH_METHOD_SIFT:
# matches, total = ret.confidence
# if 1.0*matches/total > 0.5:
# exists = True

# if exists:
elif isinstance(selector, AutomatorDeviceObject):
if not selector.exists:
return None
Expand Down Expand Up @@ -204,7 +190,6 @@ def _run_watch(self):
if time.time() - start_time > self.timeout:
raise errors.WatchTimeoutError("Watcher(%s) timeout %s" % (self.name, self.timeout,))
sys.stdout.write("Watching %4.1fs left: %4.1fs\r" %(self.timeout, self.timeout-time.time()+start_time))
#log.debug("Watching %4.1fs left: %4.1fs\r" %(self.timeout, self.timeout-time.time()+start_time))
sys.stdout.flush()
sys.stdout.write('\n')

Expand Down
3 changes: 2 additions & 1 deletion atx/tkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

log = logutils.getLogger('tkgui')
log.setLevel(logging.DEBUG)
log.debug("GUI Started.")


def insert_code(filename, code, save=True, marker='# ATX CODE END'):
""" Auto append code """
Expand Down Expand Up @@ -357,6 +357,7 @@ def mainloop(self):


def main(serial, **kwargs):
log.debug("GUI Started.")
d = atx.connect(serial, **kwargs)
gui = CropIDE('AirtestX IDE SN: %s' % serial, device=d)
gui.mainloop()
Expand Down
18 changes: 5 additions & 13 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import time
import atx
import logging
from atx import consts
print 'Version:', atx.version

Expand All @@ -11,18 +12,6 @@
# print d.screenshot('screen.png')

def screenshot():
# height = d.info['displayHeight']
# height = 1920 # this is for my phone
# params = '{x}x{y}@{x}x{y}/{r}'.format(
# x=d.info['displayWidth'], y=height, r=d.info['displayRotation'])
# start = time.time()
# command = 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {} -s > /data/local/tmp/screen2.png'.format(params)
# # print d.touch_image('a.png')
# d.shell(command)
# os.system('adb pull /data/local/tmp/screen2.png')
# print time.time()-start
# Image now save in screen2.png
# d._minicap()
start = time.time()
#d.screenshot_method = consts.SCREENSHOT_METHOD_MINICAP
d.screenshot('ttt.png')
Expand All @@ -39,7 +28,10 @@ def touch():
d.touch_image('button.png')

if __name__ == '__main__':

log = logging.getLogger('atx')
log.setLevel(logging.DEBUG)
with d.watch('simulator', 10) as w:
w.on(atx.Pattern("mmm.png", offset=(-79, -13))).click()
# # stop_app()
#print 'inside'
#screenshot()
Expand Down

0 comments on commit b24f64d

Please sign in to comment.