sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #54840
[Question #689956]: Trouble using onChange in a for loop
New question #689956 on Sikuli:
https://answers.launchpad.net/sikuli/+question/689956
Hello,
I am using Sikulix-IDE-2.0.4
My screen size is 1920*1080
I am trying to run a for loop that click on a region, wait until the screen changes, then click on a region, and so on :
I have tried to use onChange to check that the screen changes, but havent figured out how to do it properly.
I have tried 2 approaches :
1) onChange outside for loop :
time_to_change_map = 10.0
time_to_load_map = 2.0
Settings.ObserveScanRate = 1.0 / time_to_load_map
def map_change_handler(event):
event.stopObserver()
wait(1)
def change_map(regions, custom_time_to_change_map=time_to_change_map):
# regions = list of the regions where to click
onChange(1000000, map_change_handler)
for r in regions:
click(r)
# Wait until we change of map and it loads
observe(custom_time_to_change_map + time_to_load_map)
It seems that once the event has once be triggered in the first iteration of the loop,
it is always considered as changed, so it doesn't wait to change map.
Is there a way to reset the event in the handler ?
2) onChange inside the for loop
time_to_change_map = 10.0
time_to_load_map = 2.0
Settings.ObserveScanRate = 1.0 / time_to_load_map
def map_change_handler(event):
event.stopObserver()
wait(1)
def change_map(regions, custom_time_to_change_map=time_to_change_map):
# regions = list of the regions where to click
for r in regions:
click(r)
# Wait until we change of map and it loads
onChange(1000000, map_change_handler)
observe(custom_time_to_change_map + time_to_load_map)
Here it seems to create a new event each time, so at the iteration N of the loop, the handler is called N times, which is dirty and makes N times wait(1). I know i can put the wait(1) outside of the handler, but anyway I don't want the handler to be called N times, and I don't want to fill the memory with events.
Is there a way to remove the events once consumed by the handler ? I tried with region.getEvents() but it isn't working.
Best Regards
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.