How to increment values in array

Asked by Milind Warade

Hi,

I am writing code, in which text file is used as :
(11,50,12)
(11,52,21)
(12,15,20)
(12,30,45)

Check the script:

def myHandler(event):
    wait(2)
    click("1349867277615-1.png")
    type('v', KeyModifier.CTRL)
    wait(2)
    until = list(time.localtime())
    until[3:6]=eval(arr[1]) # hour minute second # DON'T KNOW HOW TO HANDLE THE ARR IN INCREMENTAL
    timeUntil = time.mktime(tuple(until))
    timeToWait = int(timeUntil - time.time())
    if timeToWait < 1:
        timeToWait1 = (86400 + int(timeUntil - time.time()))
        wait(timeToWait1)
    else:
        wait(timeToWait)
    click("submit-2.png")
    wait(8)
    click("clear-1.png")
    wait(2)

# Main function
setThrowException(True)
wait(2)
import array
arr=[]
f=open("D:\\DPTT_XML\\Time.txt","r")
fout = open("D:\\DPTT_XML\\Time-results.txt","w")

for line in f.readlines():
    arr.append(line.strip()) # get rid of newline
f.close()
wait(2)
click("1348813496420-12.png")
wait(1)
# For clock in for Employee E3
type("D:\\DPTT_XML\\E3.txt")
wait(1)
type(Key.ENTER)
wait(1)
type('a', KeyModifier.CTRL)
type('c', KeyModifier.CTRL)
type(Key.F4, KeyModifier.ALT)
wait(1)
# Open firefox
click("1348813496420-12.png")
wait(5)
click("earthprogram-9.png")
type("firefox" + Key.ENTER)
wait(5)
type("t", KeyModifier.CTRL)
wait(5)
type("https://localhost:9043/IDS/TestIDS.jsp" + Key.ENTER)
wait("RequestXMLRe-3.png",20)
click("DSservi0ehds-1.png")
type(Key.END )
type (Key.BACKSPACE)
type("http://localhost:9080/IDS/service/ids/")
type(Key.TAB)
type('v', KeyModifier.CTRL)
wait(2)
until = list(time.localtime())
until[3:6]=eval(arr[0]) # hour minute second # HERE I AM GETTING VALUE FROM ARR [0] AS I HAVE NOT CALLED THE myhandler
timeUntil = time.mktime(tuple(until))
timeToWait = int(timeUntil - time.time())
if timeToWait < 1:
    timeToWait1 = (86400 + int(timeUntil - time.time()))
    wait(timeToWait1)
else:
    wait(timeToWait)
click("submit-2.png")
wait(8)
click("clear-1.png")
wait(2)
# For clock in for Employee E6
click("1348813496420-12.png")
wait(1)
type("D:\\DPTT_XML\\E6.txt")
wait(1)
type(Key.ENTER)
wait(1)
type('a', KeyModifier.CTRL)
type('c', KeyModifier.CTRL)
type(Key.F4, KeyModifier.ALT)
wait(2)
onAppear("submitclear.png", myHandler) # HERE I WANT IT SHOULD TAKE VALUE FROM ARR [1]
observe(10)
wait(2)
# For clock in for Employee E5
click("1348813496420-12.png")
wait(1)
type("D:\\DPTT_XML\\E5.txt")
wait(1)
type(Key.ENTER)
wait(1)
type('a', KeyModifier.CTRL)
type('c', KeyModifier.CTRL)
type(Key.F4, KeyModifier.ALT)
wait(2)
onAppear("submitclear.png", myHandler) # HERE I WANT IT SHOULD TAKE VALUE FROM ARR [2]
observe(10)
wait(2)
# For clock in for Employee E2
click("1348813496420-12.png")
wait(1)
type("D:\\DPTT_XML\\E2.txt")
wait(1)
type(Key.ENTER)
wait(1)
type('a', KeyModifier.CTRL)
type('c', KeyModifier.CTRL)
type(Key.F4, KeyModifier.ALT)
wait(2)
onAppear("submitclear.png", myHandler) # HERE I WANT IT SHOULD TAKE VALUE FROM ARR [3]
observe(10)
wait(2)

Not able to increment the array values when handler is used.
Please help me out.

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

Principally there is a trick to transfer parameters to the handler (there is a Q&A around here).

But in these cases I use the region to transfer such values to the handler.

# the observe part
SCREEN.currentTimeEntry = arr[1]
onAppear("submitclear.png", myHandler) # HERE I WANT IT SHOULD TAKE VALUE FROM ARR [1]
observe(10)

# the handler part
    until[3:6]=eval(event.region.currentTimeEntry)

- the region you are using is the whole screen, hence region is SCREEN
- SCREEN.currentTimeEntry = arr[1] stores the content of arr[1] as a value in the region object SCREEN
- in the handler event.region is the current observed region (hence SCREEN in this case)
- so event.region.currentTimeEntry retrieves the stored value

Revision history for this message
Milind Warade (warademilind) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Milind Warade (warademilind) said :
#3

Thanks Raiman.
Problem is solved.