From f91063264b300b95f2a3b128d7bbf9322a0b26f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E8=80=81=E5=B8=88?= Date: Tue, 27 Jun 2017 16:23:29 +0800 Subject: [PATCH 1/2] ignore .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fa44ab7..bb27678 100755 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ AUTHORS *.trace/ *.tiff .ipynb_checkpoints +.idea/ From d41845e52a11daed6636f40883c6608dad21d882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E8=80=81=E5=B8=88?= Date: Fri, 7 Jul 2017 10:45:57 +0800 Subject: [PATCH 2/2] android support png auto-resolution by same scale of both width and height --- atx/base.py | 47 ++++++++++++++++++++++++++++++++++++++++++ atx/drivers/android.py | 4 ++-- atx/drivers/mixin.py | 7 +++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/atx/base.py b/atx/base.py index c99de53..45146ec 100644 --- a/atx/base.py +++ b/atx/base.py @@ -7,8 +7,12 @@ import random import string import time +import cv2 import logging import threading +from PIL import Image +from fractions import Fraction +import imutils from atx import strutils @@ -203,6 +207,49 @@ def lookup_image(fsearch, width=0, height=0): return filepath +def strip_fraction(some_name_prefix): + post = None + wid, ht = None, None + if '@' in some_name_prefix: + post = some_name_prefix.split('@')[-1] + if '.' in some_name_prefix: + post = some_name_prefix.split('.')[-1] + if post is not None and 'x' in post: + swid, sht = post.split('x') + wid, ht = int(swid), int(sht) + return (wid, ht) + + +def resolution_scaling(fsearch, width=0, height=0): + if height == 0: + return None + matched_path = None + factor = 1.0 + dirname = os.path.dirname(fsearch) + for file in os.listdir(dirname): + prefix, _ = os.path.splitext(file) + wid, ht = strip_fraction(prefix) + if Fraction(width, height) == Fraction(wid, ht): + factor = 1.0 * width / wid + matched_path = os.path.join(dirname, file) + break + if Fraction(height, width) == Fraction(wid, ht): + factor = 1.0 * width / ht + matched_path = os.path.join(dirname, file) + break + if matched_path: + _img = imutils.open(matched_path) + if factor > 1.0: + return cv2.resize(_img, (0, 0), fx=factor, fy=factor, interpolation=cv2.INTER_CUBIC) + elif factor < 1.0: + _height, _width = _img.shape[:2] + size = (int(_width * factor), int(_height * factor)) + return cv2.resize(_img, size, interpolation=cv2.INTER_AREA) + else: + return _img + return None + + def nameddict(name, props): """ Point = nameddict('Point', ['x', 'y']) diff --git a/atx/drivers/android.py b/atx/drivers/android.py index defe517..bdf3453 100644 --- a/atx/drivers/android.py +++ b/atx/drivers/android.py @@ -153,7 +153,7 @@ def current_package_name(self): return self.info['currentPackageName'] def is_app_alive(self, package_name): - """ Deprecated: use current_package_name instaed. + """ Deprecated: use current_package_name instead. Check if app in running in foreground """ return self.info['currentPackageName'] == package_name @@ -166,7 +166,7 @@ def sleep(self, secs=None): @property def display(self): - """Virtual keyborad may get small d.info['displayHeight'] + """Virtual keyboard may get small d.info['displayHeight'] """ if self.__display: return self.__display diff --git a/atx/drivers/mixin.py b/atx/drivers/mixin.py index 8106556..60087ef 100644 --- a/atx/drivers/mixin.py +++ b/atx/drivers/mixin.py @@ -28,7 +28,6 @@ from atx.base import nameddict from atx.drivers import Pattern, Bounds, FindPoint - warnings.simplefilter('default') __dir__ = os.path.dirname(os.path.abspath(__file__)) @@ -102,7 +101,11 @@ def last_screenshot(self): def _open_image_file(self, path): realpath = base.lookup_image(path, self.__screensize[0], self.__screensize[1]) if realpath is None: - raise IOError('file not found: {}'.format(path)) + res = base.resolution_scaling(path, self.__screensize[0], self.__screensize[1]) + if res is not None: + return res + else: + raise IOError('file not found: {}'.format(path)) return imutils.open(realpath) def pattern_open(self, image):