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

Glwdev #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ AUTHORS
*.trace/
*.tiff
.ipynb_checkpoints
.idea/
47 changes: 47 additions & 0 deletions atx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'])
Expand Down
4 changes: 2 additions & 2 deletions atx/drivers/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions atx/drivers/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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):
Expand Down