Code for reviewing loading bar through out the script

Asked by Waleed Sadek

Hi,

I'm working on automating a process, the script is almost done! but the problem is when sikuli is alternating between the difference fields of the software -I have to mention that the software is oracle and old as shit- the loading bar starts loading to show that oracle is still processing or busy. I need to write a code that detects when the loading bar starts loading so Sikuli can pause the script and wait for it then continue where it left once the loading bar stops loading, here is what i have so far;

r = Region(1095,959,179,16) # the region were the loading bar is located at
Settings.MoveMouseDelay = 0

def changed(event):
    print "something changed in ", event.region
    for ch in event.changes:
        ch.highlight() # highlight all changes
    sleep(1)
    for ch in event.changes:
        ch.highlight() # turn off the highlights
    wait(Pattern("1396280999791.png").exact(),FOREVER) #a photo of the loading bar while it's not loading/busy
    Settings.isChanged = True
    event.region.stopObserver()
    print "Stopped Loading"

r.highlight(1)
print "Checking loading bar"
r.onChange(25, changed)
Settings.isChanged = False

r.observe(360*24*60*60)

if Settings.isChanged:
    print "Status: Loading"
else:
    print "Status: Not Loading"

I have almost zero knowledge about coding i'm fairly new at this but i know this code works cause i tested it out. So i just need help knowing where to place it in the script cause I need it to constantly be checking the loading bar through out the entire script.

Thanks in advance!

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

if I understand right, then you have some dialog window, that is presented by some Oracle based app with some fields and buttons.

Your script seems to visit some of these fields one after the other and while going to the next field, you have inconsistent waiting times due to internal processing, which in turn is shown by some visual (loading bar).

So you have known fixed places in your workflow, where you need to check the loading bar and might need to wait for Oracle to be ready again.

I think, your observe solution is overkill for that (though I admit it is "attractive" and well done for someone with almost zero knowledge ;-)

I would do it this way - easy and robust:

def myWait(waitTime = 1):
    wait(waitTime) # fixed time to wait before checking loading bar (give good old Oracle some time to wake up ;-)
    Region(1095,959,179,16).exists(Pattern("1396280999791.png").exact(), 60) # 60 stands for max time in secs to wait, adjust it to your needs

usage:
# some code working with a field
# ready to go to next field
myWait() # waits 1 sec and then checks the loading bar, waits until ready
# go to next field and handle it
# ready to go to next field
myWait(2) # waits 2 secs and then checks the loading bar, waits until ready

This works as long, as Oracle comes back within the given max time (here 60 seconds).
If you replace exists with wait, then you will get a FindFailed crash, if there is a case, that exceeds the max time.

Revision history for this message
Waleed Sadek (waleedeldeweny) said :
#2

Yes that was an exact description of my problem, well summed up i must add!

Well I tried the code you have provided and it's working perfectly, thanks Raiman! I can't believe I have not thought of that before, I love the fact that it is so simple as well. I owe you a huge thanks for also helping me out unknowingly. I've been reading your answers for the past month and they've helped me out a lot with my script and understanding Sikuli. So any time I'm at Berlin, beer is on me for sure!

Have an awesome day!

Revision history for this message
Waleed Sadek (waleedeldeweny) said :
#3

Thanks RaiMan, that solved my question.

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

Thanks for kind feedback.

Since I am not living in Berlin but near Frankfurt (northeast at Nidderau), drinking a beer together might be not realistic ;-)
But it is sufficient if you keep an eye on the ongoing activities around Sikuli and may be some day in the future give something back to the community based on your own experiences.

always welcome.