How To Print To Screen?

Asked by Melissa 33

I'm trying to detect various things in one region, using a for list. anyways after it detects an image in the list I can get it to highlight the region for a second, so when the highlight box pops up I know that it found something, and once I terminate the program I can look at the console output and see what it detected from the list. but how do I get sikuli to "print" a message on the screen for a couple of seconds similar to how it can show a highlight for a couple of seconds? I want to know what it found without having to terminate the program.

I already know about popup but I don't want anything like that (if it can be helped). I want something similar to highlights, where a red box pops up for X amount of time, I would want some red text to pop up for X amount of time?

for example I have:

regionName.highlight(5) # highlights the 'regionName' region for 5 seconds

I want something like:

coordsVar = (212, 480)
coordsVar.Printtoscreen("hello", 2) # prints "hello" in red text at the coordsVar coordinates for 2 seconds

Is this possible?

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

have a look at the still experimental feature guide:
https://sikulix-2014.readthedocs.io/en/latest/extensions/sikuli-guide/index.html#sikuli-guide

an example:
import guide as GD
reg = getCenter().grow(100) #.highlight(2)
GD.rectangle(reg)
GD.text(reg, "hallo")
GD.show(2)

Revision history for this message
Melissa 33 (melbarque) said :
#2

Thank you this is exactly what I was looking for.

Revision history for this message
Melissa 33 (melbarque) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Melissa 33 (melbarque) said :
#4

Actually I have one more simple question. in your example code would it be possible to use GD.text and click() at the same time? what I might want a script to do is click a picture yet at the same time show a message while its clicking things. for example the program could pop up saying "clicking picture 321.png" at the same time as its actually clicking said picture, so the user could know right away what the program is doing

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

not at the same time, but directly after the annotation has disappeared:

import guide as GD
Settings.MoveMouseDelay = 0 # no delay at mouse move
img = Pattern("img.png").targetOffset(9,15)
hover(img) # move mouse to found image
# show annotation
reg = getLastMatch()
GD.rectangle(reg)
GD.text(reg, "clicking img.png")
GD.show(2)
# annotation vanished
click() # clicks the last match

Revision history for this message
Melissa 33 (melbarque) said :
#6

but I want to do it at the same time. for example right now I have a simple game macro that clicks a few images, and I want a friend to be able to use it, and I want it to show an annotation at the same time as a click so they can see what is happening live, but if I do GD.show(3) the game macro is constantly pausing for 3 seconds every time it shows an annotation before every click. I understand it is working as intended, but is there any way for me to change the functionality to what I want?

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

IMHO something shown on the screen, that should be of any value for the user, must be there for at least 2 seconds.

So even if you show only for 2 seconds and click in real parallel (when? at the beginning, in the middle or towards the end of the annotation?) the game will change the screen around the annotation, while the annotation sis still visible and might not fit with the new game state.

But anyways:
To click somehow in parallel with the annotation, you have to detach it to a thread and take care, that the annotation does not overlay the click point.

This will need some more synch actions between the main workflow and the annotations.

Revision history for this message
Melissa 33 (melbarque) said :
#8

thanks I think that's what I was looking for.

basically my script is

while True:
    click(image1)
    GD.text(image1, "here is image1")
    GD.show(3)
    click(image2)
    GD.text(image2, "here is image2")
    GD.show(3)
    #and it keeps continuing to click and show text like this with more images

I have no idea what you mean by detach it to a thread and take care, but I'm new to programming and I was using sikuli to learn python

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

I just made some tests and I have to admit, that with the Guide feature there is no way, to achieve what you want, since the annotation overlay covers the whole screen and might not hinder finding, but the click will not work (does not click through).

So a compromise might be:

match = find(img)
GD.text(match, "hallo"); GD.show(2)
click(match)
GD.text(match, "hallo"); GD.show(1)

If this is not sufficient for you, then you will be lost for now (thread programming, Java GUI programming, ...).

Sorry, more I cannot do for you, due to lack of time.

Revision history for this message
Melissa 33 (melbarque) said :
#10

Don't say sorry, you have already helped me so much by making sikuli. thanks for the response