2
# Copyright (c) 2010 Canonical
4
# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
6
# This file is part of the Xpresser GUI automation library.
8
# Xpresser is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU Lesser General Public License version 3,
10
# as published by the Free Software Foundation.
12
# Xpresser is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
from xpresser.errors import XpresserError
23
class ImageMatchError(XpresserError):
24
"""Error raised due to an ImageMatch related problem (really!)."""
27
class ImageMatch(object):
28
"""An image found inside another image.
30
@ivar image: The image found.
31
@ivar x: Position in the X axis where the image was found.
32
@ivar y: Position in the Y axis where the image was found.
33
@ivar similarity: How similar to the original image the match was,
35
@ivar focus_point: The position in the screen which this image match
36
represents. This is useful for clicks, hovering, etc. If no delta
37
was specified in the image data itself, this will map to the center
41
def __init__(self, image, x, y, similarity):
42
if image.height is None:
43
raise ImageMatchError("Image.height was None when trying to "
44
"create an ImageMatch with it.")
45
if image.width is None:
46
raise ImageMatchError("Image.width was None when trying to "
47
"create an ImageMatch with it.")
52
self.similarity = similarity
53
self.focus_point = (x + image.width//2 + image.focus_delta[0],
54
y + image.height//2 + image.focus_delta[1])