Detecting screen changes in a region

Asked by arminius

    while True:
    bigScreenReg = Region(1242,57,123,640)
    bigScreenReg.highlight(3)
    r = bigScreenReg
    r.onChange(100, changed)
    Settings.isChanged = False

    r.observe(5) # observing for 5 seconds (script pauses here)

    if Settings.isChanged: # check wether the handler was called (because there where changes)
        popup('there have been changes')
    else:
        print "there haven't been any changes"
    continue

It seems to be highlighting when there are changes in the region, but the popup never get's activated, the log just forever is filled with "there haven't been any changes" even though there were definitely changes in the region that I observed.

Basically I just want it to throw a popup when there are changes in the region.

Question information

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

"Settings.isChanged" is your own variable?

Now, Settings.isChanged is set False in your codes and Settings.isChanged is not modified anywhere.

You have to add code in function "changed" to modify the value of Settings.isChanged to True.

Revision history for this message
arminius (arminius75) said :
#2

not my variable, I found it on a google search and tried to get it to work, but found this one way easier.

    def changeHandler(event):
        event.region.somethingChanged = True
        event.region.stopObserver()
    while True:
        nav = Region(129,59,221,266)
        nav.onChange(5,changeHandler)
        nav.somethingChanged = False
        nav.observe(5)
        if nav.somethingChanged:
            print "changed within observation time"
            popup('changed within observation time')
        if not nav.somethingChanged:
            print "did not change within observation time"
        continue