AttributeError: 'Region' object has no attribute 'StopObserver'

Asked by Carla Granberg

Hello,

I would appreciate your insight on this error, which is reproduced each time I run the sikuli script.
Sikuli Version: Sikuli-X-1.0rc2-linux

CODE BLOCK - based on example in documentation:

                      myFileDownloadRegion = (Region,15,25,1010,698)
                     def myObserverHandler(event):
                              event.region.StopObserver()# stops the observation
                     myFileDownloadRegion.inside().onAppear( '/sikuli/project/UserSecurity.png', myObserverHandler)
<Line 143>myFileDownloadRegion.observe(60)

Error Log:
[error] Stopped [error] An error occurs at line 143
[error] Error message: Traceback (most recent call last):
File "/tmp/sikuli-tmp488639225974608907.py", line 143, in myFileDownloadRegion.observe(60)
File "/tmp/sikuli-tmp488639225974608907.py", line 143, in myFileDownloadRegion.observe(60)
File "/usr/share/sikuli/Sikuli-X-1.0rc2-linux/Sikuli-IDE/sikuli-script.jar/Lib/sikuli/Region.py", line 255, in observe
File "/usr/share/sikuli/Sikuli-X-1.0rc2-linux/Sikuli-IDE/sikuli-script.jar/Lib/sikuli/Region.py", line 223, in targetAppeared
File "/tmp/sikuli-tmp488639225974608907.py", line 135, in myObserverHandler event.region.StopObserver()# stops the observation
AttributeError: 'Region' object has no attribute 'StopObserver'

UPDATE: I have solved this particular issue. observe() should be called without appending the method to the region.

observe(60)

Thanks.
Carla

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

An observe() is always "connected" to a region. Using just observe() "connects" it to the default region SCREEN, which is a constant Region object setup at Sikuli startup as SCREEN = Screen(0). Each Region/Screen method, that is used without a Region/Screen qualifier is automagically used as SCREEN.method().

So in your case, the problem is StopObserver(), which has to be stopObserver()
(see: http://sikuli.org/docx/region.html#Region.stopObserver).

Your "fix" works, because the onAppear() is "connected" to myFileDownloadRegion and the observe() is "connected" to region SCREEN, so the handler is never called in this case and so does not produce the error any more.

This would be a correct version:

myFileDownloadRegion = Region(15,25,1010,698)
def myObserverHandler(event):
    event.region.stopObserver()# stops the observation
myFileDownloadRegion.onAppear( '/sikuli/project/UserSecurity.png', myObserverHandler)
myFileDownloadRegion.observe(60)

BTW: Region.inside() is only there for downward compatibility to Sikuli 0.9. With Sikuli X it makes no sense any longer, since it only returns the region itself.

Revision history for this message
Carla Granberg (cgranberg) said :
#2

Thanks very much for your comments and help!