1
from xpresser import xutils
2
from xpresser.image import Image
3
from xpresser.imagedir import ImageDir
4
from xpresser.imagematch import ImageMatch
5
from xpresser.opencvfinder import OpenCVFinder
11
self._imagedir = ImageDir()
12
self._imagefinder = OpenCVFinder()
14
def load_images(self, path):
15
self._imagedir.load(path)
17
def get_image(self, name):
18
return self._imagedir.get(name)
20
def _compute_focus_point(self, args):
21
if (len(args) == 2 and
22
isinstance(args[0], (int, long)) and
23
isinstance(args[1], (int, long))):
26
if type(args[0]) == ImageMatch:
29
match = self.find(args[0])
33
return match.focus_point
35
def click(self, *args):
36
"""Click on the position specified by the provided arguments.
38
The following examples show valid ways of specifying the position:
40
xp.click("image-name")
44
xutils.click(*self._compute_focus_point(args))
46
def hover(self, *args):
47
"""Hover over the position specified by the provided arguments.
49
The following examples show valid ways of specifying the position:
51
xp.hover("image-name")
55
xutils.hover(*self._compute_focus_point(args))
57
def find(self, image):
58
"""Given an image or an image name, find it on the screen.
60
@param image: Image or image name to be searched for.
61
@return: An ImageMatch instance, or None.
63
if isinstance(image, basestring):
64
image = self._imagedir.get(image)
65
screenshot_image = xutils.take_screenshot()
66
return self._imagefinder.find(screenshot_image, image)