Observer looking for patterns during while an application is running

Asked by surfdork

Hi,

I want to add addictionary or observer to the following code. The vdict or observer is used to respond to events such as an error message

I want to add a check for a specifc image before the following executes and call it as a function.

So, is there a code example that shows how to include a vdict that I could include with the function?
What about configuring an observer() I'm using win7 and recall this is a problem?
The simple function I'm working with is below

BTW, good to be back to work. Raimund, I owe you a revised MHT of the netbeans doc.

def DPILogin96():
        loginuser = input ("Please enter your user login")
        password = ("skyroom") #input ("Please enter your password")
        setBundlePath("Z:\\ZZlogin\\") # Sets path of image location in this case the test share

        #doubleClick("launch96DPI.png") # Launches SkyRoom by clicking on the desktop icon
                type(Pattern().similar(0.00).targetOffset(-178,14), loginuser)
        wait(2)
        type(Pattern().similar(0.00).targetOffset(-177,79), password)
        wait(2)
        click (Pattern().targetOffset(0, 260))
        wait(5)
        if exists(, 0): # waiting for new user Eula display
           click (Pattern().targetOffset(-59, 11))
        wait(5)
        if exists(, 0):
           popup("login failed")
           exit()
        popup("login complete")
        exit()

Question information

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

Hi --- all the best

--- comment on VDict:
until now I have not really found a usage, that really makes some sense. On top it lacks some dictionary typical methods.

Images are used as keys and with vd[image] the key is searched by applying the find algorithms. some more specific methods are available to identify a key-image.

So since you have to have the image, to find the VDict entry, you need to do some applicable (e.g. correct w and h) capturing before, to use the VDict. When testing 10.0 I made some experiments, finally made some suggestions to improve (not yet happened), laid it aside and never touched it again since then.

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

--- comment on observer feature

I just made a test on Win7 (again ;-) and it is not running as expected (bug 604514)
#--- script
theBrowser = "c:\\program files\\internet explorer\\iexplore.exe"

switchApp( theBrowser )
wait(2)
type("google.com\n")
isGoogle ="1289290533911.png" # the google logo
wait(isGoogle, 10)

reg = selectRegion() # to speed things up

def ofGoogle(e):
 print "vanished", time.time()

def onGoogle(e):
 print "came up", time.time()

reg.onVanish(isGoogle, ofGoogle)
reg.onAppear(isGoogle, onGoogle)
print "starting observation", time.time()
reg.observe(15, True)

wait(3)
switchApp( theBrowser ) # new empty browser window overlays current
wait(3)
type(Key.F4, KEY_ALT) # window with google back again
wait(3)
#--- end script

So just make your own test and see what happens (for me it is not working)

In the bug a patch (don't know whether this solves the Windows problems) is mentioned as already incorporated, but the new release is still missing (patched after release of 10.2)

--- So what are the alternatives?

--- observe with background=False (Standard)
can be substituted with some intelligent while True;, if (not) exists(img,0) and may be def()'s.

--- observe with background=True (after observe() the script continues, observation is parallel to the script)
put the intelligent things in a def() and submit it with the threading feature to a subprocess. Besides the fact that it is running, it is more fexible (parameters are possible, you can implement some locking and communicate on status e.g. using a dictionary as parameter, waiting times and search frequencies can be adjusted, ... ).

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

--- comment on your def() above

I guess you know it:
the exit()'s should be replaced al least by return True respectively return False.

usage:
if DPILogin96():
   pass # successful: do something
else:
   pass # not successful: do something else

Can you help with this problem?

Provide an answer of your own, or ask surfdork for more information if necessary.

To post a message you must log in.