Why do I need to call highlight two times

Asked by Mikael Wallin

My code: (in java)

1. screen.setRect(x1, y1, w1, h1).highlight();
2. popup("check 1");
3. screen.setRect(x2, y2, w2, h2).highlight();
4. popup("check 2");

At step 4 I don't see any highlight. To see the highlight I need to add an additional highlight.

1. screen.setRect(x1, y1, w1, h1).highlight();
2. popup("check 1");
3. screen.setRect(x2, y2, w2, h2).highlight();
4. screen.setRect(x2, y2, w2, h2).highlight();
5. popup("check 2");

Why?

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
RaiMan (raimund-hocke) said :
#1

I cannot see this behavior with version 1.1.0 (Mac and Windows)

Revision history for this message
Mikael Wallin (l-mikael) said :
#2

I am using 1.1.0 (downloaded and installed yesterday, sikulixsetupIDE-1.1.0-20150622.231444-112-forsetup.jar) , and Mac.

Still see the behaviour.

Revision history for this message
Mikael Wallin (l-mikael) said :
#3

The log explains it. It seems there is an underlying toggle function.

[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: true
[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: false
[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: true
[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: false
[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: true
[log] toggle highlight S(0)[0,0 1920x1200] E:Y, T:3,0: false

Which would mean the behaviour is as expected?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

ok, sorry for being blind:

- a highlight is per Region
- each highlight() (no parameters) toggles the highlight on and off

screen.setRect(x,y,w,h) does not define a new Region (the Region still is screen, but it's actual position and dimension is changed)

So if you want to have more than one highlight visible at a time, you need different regions:

Region.create(x1, y1, w1, h1).highlight();
popup("check 1");
Region.create(x2, y2, w2, h2).highlight();
popup("check 2");
org.sikuli.util.ScreenHighlighter.closeAll() # switch both off

Revision history for this message
Mikael Wallin (l-mikael) said :
#5

Thanks RaiMan, that solved my question.