~xpresser-team/xpresser/xpresser-with-special-keys

« back to all changes in this revision

Viewing changes to debian/python-xpresser/usr/share/pyshared/xpresser/imagematch.py

  • Committer: Chris Wayne
  • Date: 2012-07-05 15:56:48 UTC
  • Revision ID: chris.wayne@canonical.com-20120705155648-5kmc3gih12slvr7y
Adding debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (c) 2010 Canonical
3
 
#
4
 
# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
5
 
#
6
 
# This file is part of the Xpresser GUI automation library.
7
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
#
20
 
from xpresser.errors import XpresserError
21
 
 
22
 
 
23
 
class ImageMatchError(XpresserError):
24
 
    """Error raised due to an ImageMatch related problem (really!)."""
25
 
 
26
 
 
27
 
class ImageMatch(object):
28
 
    """An image found inside another image.
29
 
 
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,
34
 
        where 1.0 == 100%.
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
38
 
        of the found image.
39
 
    """
40
 
 
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.")
48
 
 
49
 
        self.image = image
50
 
        self.x = x
51
 
        self.y = y
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])