guibot.target module

SUMMARY

Classes and functionality related to sought targets on screen.

INTERFACE

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

property similarity

Getter for readonly attribute.

Returns:

similarity required for the image to be matched

Return type:

float

property 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, **kwargs)[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: Target

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

property filename

Getter for readonly attribute.

Returns:

filename of the image

Return type:

str

property width

Getter for readonly attribute.

Returns:

width of the image

Return type:

int

property height

Getter for readonly attribute.

Returns:

height of the image

Return type:

int

property pil_image

Getter for readonly attribute.

Returns:

image data of the image

Return type:

PIL.Image

load(filename, use_cache=True, **kwargs)[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=None, text_filename=None, match_settings=None)[source]

Bases: Target

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

load(filename, **kwargs)[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(id, match_settings=None)[source]

Bases: Target

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

load(filename, **kwargs)[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: 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.

load(steps_filename, **kwargs)[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