Observer running in the background, closing dialogs on popup

Asked by Simon K

I'm trying to create a script that will close certain windows/dialogs on popup - it i important that it runs in the background and closes the popups asap.

If I understand correctly, I can use the onAppear with observe set to infinite and background set to true.

My problem here is that I'd like to build a library of images that the onAppear handler would act on, so:

a =image1, image2, image3, image4

def myHandler(event):
 wait(cross)
        click(getLastMatch)
 print "it happened"

onAppear(a, myHandler)
observe(FOREVER, background = True)

1. Am I checking the library correctly?

2. How to make sure that the main script will not terminate/continue before the handler finishes closing the dialogs? For example:
while True:
   freeze the main script
   run the handler
   resume the script

3. Currently my script finds the main script image faster than the image from the library, thus not allowing the handler to close the dialog. I am unable to create a region for the library "a", because they all appear in different spots on the screen.
Is there any way to create a specific region for each of the images or something like that?

Thats a lot of questions, hopefully someone can help me :)!

Question information

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

--- parallel or sequentially?
first you have to decide, wether the images should be observed in parallel or sequentially. In the first case, you need one observer (and because one region can only have one observer) and one region per image. In the latter case you can define as many (theoretically ;-) events onXXX per region.

--- whole screen or region
to boost performance it is always a good idea, to restrict the search region so it is not the whole screen (each search in average takes about on second).

--- case parallel
# we use a dictionary, the regions have to be different objects!
a = {region1 : image1, region2 : image2, region3 : image3, region4 : image4}

def myHandler(event):
    event.region.nearby(100).click(cross) # guess it is the close "button"
    print "it happened"

# each image is observed in its own region
for r in a:
    r.onAppear(a{r})
    r.observe(FOREVER, background = True)

--- case sequentially
# we use a list
a = (image1, image2, image3, image4)

def myHandler(event):
    event.region.nearby(100).click(cross) # guess it is the close "button"
    print "it happened"

# each image is observed in its own region
r = Region(some_region)
for i in a:
    r.onAppear(a[i])
r.observe(FOREVER, background = True)

--- How to make sure that the main script will not terminate/continue before the handler finishes closing the dialogs?
principally you can use one or more global variables to communicate between the handlers and the main script.
easier to script is to use Sikulis Settings class:
Settings.myVariable = False
this can be used everywhere without any additional actions.

Can you help with this problem?

Provide an answer of your own, or ask Simon K for more information if necessary.

To post a message you must log in.