onChange not detecting changes

Asked by Greg Howell

Raiman,

So I'm working on this tracking tool that shows on a map (like a googlemaps satellite view) where there was movement. It does this by showing these little red stars where the movement was detected. The little stars are about 40-50 pixels large. What I wanted to do is keep a log of the position the stars come up on the screen. So I coded up a section below and it runs the code, but I never detect these stars showing up although I can clearly see them when I run the program. I've read through several other posts on using the onChange function and thought I had it correct, but I must be doing something wrong. Can you please take a look? I've only included what is applicable here. This is obviously within a class and there's other classes involved. The self.resfile is just a file_io class that has functions for reading and writing to a result text file. I know for sure it's entering my watch_for_tracks method and it's clicking on the start_tracking_icon, and then waiting the full 45 seconds for something to appear, but my "changed" method never gets called. I know that because nothing gets written to my file. But I did write a line before I called watch_for_tracks and that works so I know my file_io works (I use it for several other working programs too).

Or is there a better way altogether to do this?

    def changed(event):
        self.resfile.write_string("Change observed\n")
        for ch in event.changes:
            center_loc = ch.getCenter()
            self.resfile.write_string("Observed track at " + str(center_loc.x) +
                                      ", " + str(center_loc.y) + "\n")

    def watch_for_tracks(self, tracking_icon):

        start_tracking_icon = self.toolbar_reg.exists(tracking_icon)
        if (start_tracking_icon):
            click(start_tracking_icon)
            self.watch_region.highlight(1)
            self.watch_region.onChange(25, self.changed)
            self.watch_region.observe(background=True)

            wait(45)
            self.watch_region.stopObserver()
            click(start_tracking_icon)
        else:
            self.resfile.write_string("Was not able to see the enable tracking icon \n")
            self.breakscript(None)

    def breakscript(self, event):
        exit(1)

Question information

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

what version of Sikuli?

in 1.0.1 there is a problem with FOREVER, which is the default in your case.

if 1.0.1 try this:
      self.watch_region.observe(60, background=True)
      wait(45)

Revision history for this message
Greg Howell (ghowell) said :
#2

Yes, it is 1.0.1. And that was it! Solved my problem. Thank you so much for such a quick response. This totally makes my day to see this work! :)