Can't get observer() to work…

Asked by Glowing Crystalline Entity

This is the 2015-09-25 daily.

I have Python code like:

            leftRegion = <some region>

            changeEvent = leftRegion.onChange()
            if not leftRegion.observe(True):
                print "Could not start observer"
                exit()

The program always exits (i.e., the observation can't start), with debug/error messages like:

[debug] Region: R[544,943 790x83]@S(0): observer CHANGE : 1443785667124 with: 50
[debug] Region: observe: starting in R[544,943 790x83]@S(0) for 1.0 seconds
[debug] Observer: resetting observe states for R[544,943 790x83]@S(0)
[debug] Observing: add observer: now running 1 observer(s)

[debug] Observer: update result: Patterns: false
[debug] Observer: update result: Changes: true

[debug] Observer: update result: Patterns: false
[debug] Observer: update result: Changes: true

[debug] Observer: update result: Patterns: false

[debug] Observer: update result: Changes: true

[debug] Observer: update result: Patterns: false
[debug] Observer: update result: Changes: true

[debug] Region: observe: stopped due to timeout in R[544,943 790x83]@S(0) for 1.0 seconds
Could not start observer
[debug] Sikulix: cleanUp: 0
[info] Exit code: 0
[debug] Exit code: 0
[debug] Sikulix: cleanUp: 0

So the observer can't start… or it does start, but only runs for 1 second? (and what's the "Changes: true" bit? There's nothing changing on the screen at this point.)

If I try: leftRegion.observe(FOREVER, True), it tells me the observe functions expects 0-1 arguments, not 2.

If I try leftRegion.observe(background=True) (with or without a time arg), it tells me observe doesn't take any keyword arguments:

[error] script [ DOFFOptions ] stopped with error in line 235
[error] TypeError ( observe(): takes no keyword arguments )
[error] --- Traceback --- error source first line: module ( function ) statement 60: AssignmentTasks ( collectComplete ) if not leftRegion.observe(FOREVER, background=True):
[error] --- Traceback --- end --------------
[debug] Sikulix: cleanUp: 0

Any ideas?

(Oh, and it slows down my mouse too. ;-) )

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

Sorry for the inconvenience:
I just realized, that the docs are not really up-to-date.

So just for you in advance:

These are the options you have:

--- observe in foreground (script is paused at the observe)
someRegion.observe() # observes FOREVER
someRegion.observe(time) # observes for the given time

--- observe in background (script continues immediately after observe is started)
someRegion.observeInBackground(time) # observes for the given time

--- this is deprecated
someRegion.observe(time, background = True)
... with the additional impact, that someRegion must be a Jython level Region object (in doubt cast using Region(someRegion))

Revision history for this message
Glowing Crystalline Entity (glowingcrystallineentity) said :
#2

Ok, that seems to be working. Thanks!

The logging is a bit odd, though. Region.isObserving() often reports false, though there still seem to be observers. Region.stopObserver() also /says/ it stops the observer… then some other logs say the observer isn't stopped, and when I put an observer on another region, it reports "n + 1" observers… i.e., I get a monotonically increasing number of observers.

None of this seems to be a problem though -- my code is doing what it needs to at this point.

So thanks again for the early documentation. :)

Revision history for this message
Glowing Crystalline Entity (glowingcrystallineentity) said :
#3

Thanks RaiMan, that solved my question.

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

Thank YOU for this valuable feedback.

I will revise the logging of course, to make it more clear.

Revision history for this message
Glowing Crystalline Entity (glowingcrystallineentity) said :
#5

No worries. Thanks for looking at the logging. :)