Skip to content

Commit

Permalink
fix d.settings to self.settings
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 15, 2020
1 parent 2220717 commit 5097b14
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ You can find all key code definitions at [Android KeyEvnet](https://developer.an
d.swipe_ext("right", scale=0.9) # 默认0.9, 滑动距离为屏幕宽度的90%
d.swipe_ext("right", box=(0, 0, 100, 100)) # 在 (0,0) -> (100, 100) 这个区域做滑动
# 实践发现上滑或下滑的时候,从中点开始滑动成功率会高一些
d.swipe_ext("up", scale=0.8) # 代码会vkk
# 还可以使用Direction作为参数
from uiautomator2 import Direction
Expand Down
2 changes: 1 addition & 1 deletion uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def screenshot(self, filename: Optional[str] = None, format="pillow"):
# Always fail in secure page
# 截图失败直接返回一个粉色的图片
# d.settings['default_screenshot'] =
if d.settings['fallback_to_blank_screenshot']:
if not self.settings['fallback_to_blank_screenshot']:
raise IOError("PIL.Image.open IOError", ex)
return Image.new("RGB", self.window_size(), (220, 120, 100))
elif format == 'opencv':
Expand Down
2 changes: 1 addition & 1 deletion uiautomator2/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def draw_point(im: Image.Image, x: int, y: int) -> Image.Image:
return im


def imread(data):
def imread(data) -> np.ndarray:
"""
Args:
data: local path or http url or data:image/base64,xxx
Expand Down
8 changes: 5 additions & 3 deletions uiautomator2/swipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __call__(self,
scale (float): percent of swipe, range (0, 1.0]
box (tuple): None or [lx, ly, rx, ry]
kwargs: used as kwargs in d.swipe
Raises:
ValueError
"""
Expand All @@ -40,6 +41,7 @@ def _swipe(_from, _to):
h_offset = int(width * (1 - scale)) // 2
v_offset = int(height * (1 - scale)) // 2

center = width//2, height//2
left = lx + h_offset, ly + height // 2
up = lx + width // 2, ly + v_offset
right = rx - h_offset, ly + height // 2
Expand All @@ -50,8 +52,8 @@ def _swipe(_from, _to):
elif direction == Direction.RIGHT:
_swipe(left, right)
elif direction == Direction.UP:
_swipe(bottom, up)
_swipe(center, up) # from center to top
elif direction == Direction.DOWN:
_swipe(up, bottom)
_swipe(center, bottom) # from center to bottom
else:
raise ValueError("Unknown direction:", direction)
raise ValueError("Unknown direction:", direction)

0 comments on commit 5097b14

Please sign in to comment.