Script Exception after region highlight

Asked by matteoa

Hello all,
With the script below (a part of a much longer script), after "vncReg.highlight(2)" I have this error:
[error] Error caused by: Traceback (most recent call last): File "c:\TEstBug.sikuli\TEstBug.py", line 4, in <module> vncReg.highlight(2) AttributeError: 'org.sikuli.script.Region' object has no attribute '__exit__'

That I had not with older versions of Sikulix.
This happens with running inside the IDE and from Pycharm, no differences in error messages
How could I fix this error?
My environment is :
1.1.4-SNAPSHOT-2019-01-16_07:30/Windows10.0/Java8(64)1.8.0_191-b12
Thanks in advance

This is the minimum script to show the error, the images are the connection button and the refresh button of the ultravnc window, line 4 mentioned in the error message is "vncReg.highlight(2)"
appVNC= App(r'"c:\UltraVNC\vncviewer.exe"')
appVNC.open(0)
vncReg=appVNC.focusedWindow()
vncReg.highlight(2)
with vncReg:
    click("1544788207679.png")

and this is the full console output:
[log] highlight R[773,299 374x401]@S(0) for 2.0 secs

[error] script [ TEstBug ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Projects\DataPurchase\REACT\SikuliX\Test_h20\TEstBug.sikuli\TEstBug.py", line 4, in <module> vncReg.highlight(2) AttributeError: 'org.sikuli.script.Region' object has no attribute '__exit__'

1.1.4-SNAPSHOT-2018-12-31_16:24/Windows10.0/Java8(64)1.8.0_191-b12

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
masuo
Solved:
Last query:
Last reply:
Revision history for this message
matteoa (matteoa) said :
#1

shorter version of the script, I don't think I could restrict it more, same error message shown:

appVNC= App(r'"c:\Projects\DataPurchase\REACT\SikuliX\Test_h20\UltraVNC\vncviewer.exe"')
appVNC.open(0)
vncReg=appVNC.focusedWindow()
vncReg.highlight(2)
with vncReg:
    click("1544788207679.png")

Revision history for this message
Best masuo (masuo-ohara) said :
#2

See document.
https://sikulix-2014.readthedocs.io/en/latest/region.html#grouping-method-calls-with-region

If you get strange results or errors in the with block (e.g. syntax error __enter__ is not defined for this region) cast your Region object to a scripting level Region object using
castedRegion = Region(regionNotWorking) and use castedRegion in the with clause or do it like this:

Revision history for this message
matteoa (matteoa) said :
#3

Thanks a lot!

Revision history for this message
matteoa (matteoa) said :
#4

Thanks masuo, that solved my question.