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

Commit

Permalink
fix spell
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 16, 2016
1 parent 9bc6d3c commit 1d28652
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion atx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from atx.consts import *
from atx.errors import *
from atx.device import Patten
from atx.device import Pattern
from atx import imutils


Expand Down
22 changes: 11 additions & 11 deletions atx/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
'.*DisplayViewport{valid=true, .*orientation=(?P<orientation>\d+), .*deviceWidth=(?P<width>\d+), deviceHeight=(?P<height>\d+).*')


class Patten(object):
class Pattern(object):
def __init__(self, image, offset=(0, 0), anchor=0):
self._name = None
self._image = imutils.open(image)
self._offset = offset

if isinstance(image, basestring):
self._name = image
self._offset = offset

@property
def image(self):
Expand All @@ -62,7 +63,6 @@ def offset(self):
return self._offset



class Watcher(object):
ACTION_CLICK = 1 <<0
ACTION_TOUCH = 1 <<0
Expand Down Expand Up @@ -90,7 +90,7 @@ def on(self, image=None, actions=None, text=None):
None
"""
if isinstance(image, basestring):
self._stored_selector = Patten(image)
self._stored_selector = Pattern(image)
elif text:
self._stored_selector = self._dev(text=text)

Expand All @@ -117,7 +117,7 @@ def __exit__(self, type, value, traceback):

def _match(self, selector, screen):
''' returns position(x, y) or None'''
if isinstance(selector, Patten):
if isinstance(selector, Pattern):
ret = self._dev.match(selector.image, screen=screen)
if ret is None:
return None
Expand Down Expand Up @@ -219,22 +219,22 @@ def match(self, img, screen=None):
Raises:
SyntaxError: when image_match_method is invalid
"""
if not isinstance(img, Patten):
selector = Patten(img)
if not isinstance(img, Pattern):
selector = Pattern(img)
# search_img = imutils.open(img)
search_img = selector.image
if screen is None:
screen = self.screenshot()

offx, offy = offset = selector.offset
dx, dy = selector.offset
# image match
screen = imutils.from_pillow(screen) # convert to opencv image
if self.image_match_method == consts.IMAGE_MATCH_METHOD_TMPL:
if self.resolution is not None:
ow, oh = self.resolution
fx, fy = 1.0*self.display.width/ow, 1.0*self.display.height/oh
search_img = cv2.resize(search_img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_CUBIC)
offx, offy = int(offx*fx), int(offy*fy)
dx, dy = int(dx*fx), int(dy*fy)

# TODO(useless)
# cv2.imwrite('resize-tmp.png', search_img)
Expand All @@ -249,7 +249,7 @@ def match(self, img, screen=None):
return None
(x, y) = ret['result']
# fix by offset
position = (x+offx, y+offy)
position = (x+dx, y+dy)
confidence = ret['confidence']
return FindPoint(position, confidence, self.image_match_method)

Expand Down Expand Up @@ -293,7 +293,7 @@ def click_image(self, img, timeout=20.0, wait_change=False):
if found and wait_change:
start_time = time.time()
while time.time()-start_time < timeout:
screen_img = self.screenshot()
# screen_img = self.screenshot()
ret = self.match(search_img)
if ret is None:
break
Expand Down
2 changes: 1 addition & 1 deletion atx/tkgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _save_crop(self):
if self._offset == (0, 0):
self._gencode_text.set('click_image("%s")' % save_to)
else:
code = 'click_image(atx.ImageSelector("{name}", offset=({x}, {y})))'.format(
code = 'click_image(atx.Pattern("{name}", offset=({x}, {y})))'.format(
name=save_to, x=self._offset[0], y=self._offset[1])
self._gencode_text.set(code)

Expand Down

0 comments on commit 1d28652

Please sign in to comment.