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

« back to all changes in this revision

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

  • Committer: Chris Wayne
  • Date: 2012-07-05 13:52:37 UTC
  • mfrom: (10.1.6 gtk3-port-with-cairo)
  • Revision ID: chris.wayne@canonical.com-20120705135237-7f52h9sfxwu279dr
Merging in gtk3 support with simple cv, adding debian packaging

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
 
 
21
 
 
22
DEFAULT_SIMILARITY = 0.98
 
23
 
 
24
 
 
25
class Image(object):
 
26
    """An image. :-)
 
27
 
 
28
    @ivar name: The human-oriented name of this image. May be None.
 
29
 
 
30
    @ivar similarity: The similarity tolerance to be used when searching
 
31
        for this image.
 
32
 
 
33
        Varies between 0.0 and 1.0, where 1.0 is a perfect match.  Defaults
 
34
        to the value of DEFAULT_SIMILARITY when not specified in the image
 
35
        data.
 
36
 
 
37
    @ivar focus_delta: (dx, dy) pair added to the center position to
 
38
        find where to click. 
 
39
 
 
40
        For instance, if the *center* of the image is found at 200, 300 and
 
41
        the focus_point is (10, -20) the click will actually happen at the
 
42
        screen position (210, 280).
 
43
 
 
44
        When not specified, (0, 0) is assumed, which means click in the
 
45
        center of the image itself.
 
46
 
 
47
    @ivar width: The width of the image.
 
48
 
 
49
    @ivar height: The height of the image.
 
50
 
 
51
    @ivar filename: Filename of the image.
 
52
 
 
53
    @ivar array: Numpy array with three dimensions (rows, columns, RGB).
 
54
 
 
55
    @ivar cache: Generic storage for data associated with this image, used
 
56
        by the image finder, for instance.
 
57
    """
 
58
 
 
59
    def __init__(self, name=None, similarity=None, focus_delta=None,
 
60
                 width=None, height=None, filename=None, array=None):
 
61
        if similarity is None:
 
62
            similarity = DEFAULT_SIMILARITY
 
63
        if focus_delta is None:
 
64
            focus_delta = (0, 0)
 
65
 
 
66
        if not (0 < similarity < 1):
 
67
            raise ValueError("Similarity out of range: %.2f" % similarity)
 
68
 
 
69
        self.name = name
 
70
        self.similarity = similarity
 
71
        self.focus_delta = focus_delta
 
72
        self.width = width
 
73
        self.height = height
 
74
        self.filename = filename
 
75
        self.array = array
 
76
        self.cache = {}