guibot.target module

class guibot.target.Target(match_settings=None)[source]

Bases: object

Target used to obtain screen location for clicking, typing, validation of expected visual output, etc.

static from_data_file(filename)[source]

Read the target type from the extension of the target filename.

Parameters:filename (str) – data filename for the target
Returns:target of type determined from its data filename extension
Return type:target.Target
Raises:errors.IncompatibleTargetFileError if the data file if of unknown type
static from_match_file(filename)[source]

Read the target type and configuration from a match file with the given filename.

Parameters:filename (str) – match filename for the configuration
Returns:target of type determined from its parsed (and generated) settings
Return type:target.Target
__init__(match_settings=None)[source]

Build a target object.

Parameters:match_settings (finder.Finder or None) – predefined configuration for the CV backend if any
__str__()[source]

Provide a constant name ‘target’.

similarity

Getter for readonly attribute.

Returns:similarity required for the image to be matched
Return type:float
center_offset

Getter for readonly attribute.

Returns:offset with respect to the target center (used for clicking)
Return type:location.Location

This clicking location is set in the target in order to be customizable, it is then taken when matching to produce a clicking target for a match.

load(filename)[source]

Load target from a file.

Parameters:filename (str) – name for the target file

If no local file is found, we will perform search in the previously added paths.

save(filename)[source]

Save target to a file.

Parameters:filename (str) – name for the target file
copy()[source]

Perform a copy of the target data and match settings.

Returns:copy of the current target (with settings)
Return type:target.Target
with_center_offset(xpos, ypos)[source]

Perform a copy of the target data with new match settings and with a newly defined center offset.

Parameters:
  • xpos (int) – new offset in the x direction
  • ypos (int) – new offset in the y direction
Returns:

copy of the current target with new center offset

Return type:

target.Target

with_similarity(new_similarity)[source]

Perform a copy of the target data with new match settings and with a newly defined required similarity.

Parameters:new_similarity (float) – new required similarity
Returns:copy of the current target with new similarity
Return type:target.Target
class guibot.target.Image(image_filename=None, pil_image=None, match_settings=None, use_cache=True)[source]

Bases: guibot.target.Target

Container for image data supporting caching, clicking target, file operations, and preprocessing.

__init__(image_filename=None, pil_image=None, match_settings=None, use_cache=True)[source]

Build an image object.

Parameters:
  • image_filename (str or None) – name of the image file if any
  • pil_image (PIL.Image or None) – image data - use cache or recreate if none
  • match_settings (finder.Finder or None) – predefined configuration for the CV backend if any
  • use_cache (bool) – whether to cache image data for better performance
__str__()[source]

Provide the image filename.

filename

Getter for readonly attribute.

Returns:filename of the image
Return type:str
width

Getter for readonly attribute.

Returns:width of the image
Return type:int
height

Getter for readonly attribute.

Returns:height of the image
Return type:int
pil_image

Getter for readonly attribute.

Returns:image data of the image
Return type:PIL.Image
load(filename, use_cache=True)[source]

Load image from a file.

Parameters:
  • filename (str) – name for the target file
  • use_cache (bool) – whether to cache image data for better performance
save(filename)[source]

Save image to a file.

Parameters:filename (str) – name for the target file
Returns:copy of the current image with the new filename
Return type:target.Image

The image is compressed upon saving with a PNG compression setting specified by config.GlobalConfig.image_quality().

class guibot.target.Text(value, match_settings=None)[source]

Bases: guibot.target.Target

Container for text data which is visually identified using OCR or general text detection methods.

__init__(value, match_settings=None)[source]

Build a text object.

Parameters:
  • value (str) – text value to search for
  • match_settings (finder.Finder or None) – predefined configuration for the CV backend if any
__str__()[source]

Provide a part of the text value.

load(filename)[source]

Load text from a file.

Parameters:filename (str) – name for the target file
save(filename)[source]

Save text to a file.

Parameters:filename (str) – name for the target file
distance_to(str2)[source]

Approximate Hungarian distance.

Parameters:str2 (str) – string to compare to
Returns:string distance value
Return type:float
class guibot.target.Pattern(data_filename, match_settings=None)[source]

Bases: guibot.target.Target

Container for abstracted data which is obtained from training of a classifier in order to recognize a target.

__init__(data_filename, match_settings=None)[source]

Build a pattern object.

Parameters:
  • data_filename (str) – name of the text file if any
  • match_settings (finder.Finder or None) – predefined configuration for the CV backend if any
__str__()[source]

Provide the data filename.

load(filename)[source]

Load pattern from a file.

Parameters:filename (str) – name for the target file
save(filename)[source]

Save pattern to a file.

Parameters:filename (str) – name for the target file
class guibot.target.Chain(target_name, match_settings=None)[source]

Bases: guibot.target.Target

Container for multiple configurations representing the same target.

The simplest version of a chain is a sequence of the same match configuration steps performed on a sequence of images until one of them succeeds. Every next step in this chain is a fallback case if the previous step did not succeed.

__init__(target_name, match_settings=None)[source]

Build an chain object.

Parameters:
  • target_name (str) – name of the target for all steps
  • match_settings (finder.Finder or None) – predefined configuration for the CV backend if any
__str__()[source]

Provide the target name.

__iter__()[source]

Provide an interator over the steps.

load(steps_filename)[source]

Load steps from a sequence definition file.

Parameters:steps_filename (str) – names for the sequence definition file
Raises:errors.UnsupportedBackendError if a chain step is of unknown type
Raises:IOError if an chain step line cannot be parsed
save(steps_filename)[source]

Save steps to a sequence definition file.

Parameters:steps_filename (str) – names for the sequence definition file