Switching off all currently active highlighting

Asked by Rainer

I have a situation where I need to highlight various regions. Sometimes more than one should be highlighted at the same time, depending on the content of the screen, and I cannot know in advance which regions will be highlighted and for how long they should remain highlighted. As the script needs to continue, I must start the highlighting without a time parameter.

The problem here is to stop the highlighting. I cannot just highlight the region again without a time parameter, because if it is not highlighted, I will get highlighted. I tried to highlight it for a specific time, but that does not cancel the highlighting that was started without a time parameter.

I could of course track all started highlighting, and then cancel exactly the highlightings that are active. I wonder whether there might exist a (probably not documented) command that cancels the highlighting of a region, if it is on, but does not start it? Or a command to cancel all active highlightings?

Thank you.

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:

This question was reopened

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

(org.sikuli.script.) ScreenHighlighter.closeAll()

Revision history for this message
Rainer (formulator) said :
#2

Thank you so far.

So far I tried that in in the IDE, but could not make it work ("name 'ScreenHighlighter' is not defined", 'javapackage' object has no attribute 'ScreenHighlighter'")

Do I need to import something before I can use that?

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

somewhere at the script top:
import org.sikuli.script.ScreenHighlighter as SH

... and later where needed
SH.closeAll()

Revision history for this message
Rainer (formulator) said :
#4

'import org.sikuli.script.ScreenHighlighter as SH' – 'Import Error: No module named ScreenHighlighter'

I had already tried
'Import org.sikuli.script.SikulixForJython' (from my IntelliJ setup),
which did not result in an error, but did not achieve anything wrt my problem.

I am obviously still lacking some basic understanding of the various components required for SikuliX …

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

sorry, should have looked into ;-)

import org.sikuli.util.ScreenHighlighter as SH

Revision history for this message
Rainer (formulator) said :
#6

That worked! Thank you!

Are there more of such beautiful undocumented features that we could use :-) ?

Revision history for this message
Rainer (formulator) said :
#7

Thanks RaiMan, that solved my question.

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

--- Are there more of such beautiful undocumented features that we could use :-) ?
not really.
This one is a side effect of the need, to switch off all active highlights, when a script ends.

... but I will make it official as Region::highlightOff()

Revision history for this message
Rainer (formulator) said :
#9

That sounds great, thank you.

Could you eventually consider a Region::highlightOn() as well (to make sure that a Region is highlighted)?

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

ok, convinced ;-)

Revision history for this message
RaiMan (raimund-hocke) said :
#11
Revision history for this message
Rainer (formulator) said :
#12

Behaves unexpectedly on my system:

highlight(True) highlights for 1 second, the scripts pauses, highlight is cancelled

highlight(False) highlights for 2 seconds, the script pauses. Does not cancel a previously active highlight.

(Build 196, Win 7 Pro, Java 8_201)

Could you check that, please?

highlightOff() works as expected.

Another detail: Env.getSikuliVersion() results in "1.1.4-SNAPSHOT". Would it be possible to include the date and/or the build number?

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

I have to check.
Seems to be a problem with the mapping of the Jython highlight(True/False) to the Java level Region.highlight(boolean).
I have to admit, that I only tested at the Java level ;-)

... so thanks for testing.

For the version info (good idea ;-) i will make a request bug.

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

As already guessed: True/False as parameter to a Java API function are given as Integer 1 and 0.

So I had to revise the API accordingly:

--- for the individual highlight
highlightOn()
highlightOff()

--- for all highlights
highlightAllOff()

I will revise the docs.
Testing appreciated.

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

--- Another detail: Env.getSikuliVersion() results in "1.1.4-SNAPSHOT". Would it be possible to include the date and/or the build number?

added Env.getSikuliVersionBuild() (see: bug 1817043)

Revision history for this message
Rainer (formulator) said :
#16

Did some testing, the functionality seems to basically work, although I am not sure whether it works as intended everywhere :)

I noticed a couple of things:

highlightOff() turns green in the IDE (so it is correctly recognized), whereas highlightOn() and highlightAllOff() stay black (although they work as expected).

reg.highlight("GREEN") → reg is highlighted in green as expected
reg.highlight("BLUE") → reg highlight color is not changed to blue, instead the green highlight is cancelled.
Is this the intended behavior?

reg.highlight("GREEN") → reg is highlighted in green as expected
reg.highlight(1, "BLUE") → reg is highlighted in blue for one second, than is highlighted in green again and stays that way
Is this the intended behavior?

reg.highlight("GREEN") → reg is highlighted in green as expected
reg.highlightOff() → highlight is cancelled as expected
reg.highlightOn() → (no color parameter) highlight is turned on in red, not in the last used color
Is this the intended behavior?

Regards,
Rainer

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

again thanks - very helpful.

case 1: I guess you are talking about the "syntax-coloring" in the IDE. I have simply have to update a list. Coloring and function processing have nothing to do with one another ;-) still just manual work.

case 2: not intended. should turn to blue and stay. a bug.

case 3: intended. the on/off-highlights and the timed ones are independent from each other.

case 4: intended. I Thought about this, but it is too much implementation effort, to track the highlight history of a region. So you have to "remember" it yourself.

Revision history for this message
Rainer (formulator) said :
#18

Case 1: Yue guessed right :) Yes, I was talking about the syntax coloring. I already suspected that this requires just a "manual" addition of the new keywords to some kind of list.

Case 2: agreed, should work differently

Case 3: perfectly valid, just so that we know it

Case 4: the same. If we know the behavior, we can program everything accordingly.

Just noticed the following:

Highligting for a specific time results in a log entry (if activated):
[log] highlight R[840,0 840x525]@S(0) for 1.0 secs color: BLUE

highlightOn/Off/AllOff does not seem to create a log entry.
Shouldn't those actions be logged too?

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

--- Shouldn't those actions be logged too?
Yes ;-)

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

should be available now.

Revision history for this message
Rainer (formulator) said :
#21

Tested all highlighting cases, everything now works as intended.

The logging also works for all events. I just noted a little detail:
For "timed" highlights, the color is indicated whenever a specific color was requested. This is not the case for all the new highlighting options. If it is not too much work, could you please make the logging behavior consistent and always provide the color info too, if the default color is not used?

Thank you very much by the way, these new highlighting options are very much appreciated!

Revision history for this message
Rainer (formulator) said :
#22

The added build info in Env.getSikuliVersionBuild() also works nicely. We can finally stop writing it down after every download :)

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

Thanks for your systematic testing and feedback.

Of course I will add the color info to the logs - simply missed that.

Revision history for this message
Rainer (formulator) said :
#24

Thanks RaiMan, that solved my question.