with: not working with a Match object - cast to Region

Asked by Landy

From this link, http://sikuli.org/docx/match.html#creating-a-match-getting-attributes, it says "http://sikuli.org/docx/match.html#creating-a-match-getting-attributes", Does it mean that class Match is a subclass of class Region?

I ask this question because I have some code like
m = find(XXX)
with m:
    some actions

When I try to run the code, Sikuli reports "AttributeError: 'org.sikuli.script.Match' object has no attribute '__exit__'. Sikuli reports the error occurs at line "m = find(XXX)", but if I comment out the "with m: some actions", "m = find(XXX)" can run without error.

What's wrong with my code? Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Principally, this is the fact: Match is a subclass of Region.

The implementation of with: still has problems with Match and App.window() (it is a known bug)

workaround: cast Match to Region when you want to use with: with a Match object:

m = Region(find(XXX))

Hope it will be fixed with X-1.0rc3.

Revision history for this message
Landy (landy-zhu) said :
#2

Thank you RaiMan. This solution works! :)

Revision history for this message
Landy (landy-zhu) said :
#3

Thanks RaiMan, that solved my question.