← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #193849]: [EXAMPLE] XBMCFlix-o-mate Automating Netflix Silverlight Controls

 

Question #193849 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/193849

RaiMan posted a new comment:
--1. ok

--2. ok

--3. ok
- hoverPoint = getCenter()
getCenter() returns the center pixel of the current ROI region of SCREEN which is Screen(0)

- showcase
print SCREEN
print "Bounds:", getBounds()
print "ROI:", getROI()
print "Center:", getCenter()

print "\n**** ROI 0,0,100,100"
setROI(0,0,100,100)
print SCREEN
print "Bounds:", getBounds()
print "ROI:", getROI()
print "Center:", getCenter()

print "\n**** ROI reset to screen"
setROI(getBounds())
print SCREEN
print "Bounds:", getBounds()
print "ROI:", getROI()
print "Center:", getCenter()

prints 
Screen(0)[0,0 1920x1200] E:Y, T:3,0
Bounds: java.awt.Rectangle[x=0,y=0,width=1920,height=1200]
ROI: java.awt.Rectangle[x=0,y=0,width=1920,height=1200]
Center: (960,600)

**** ROI 0,0,100,100
Screen(0)[0,0 1920x1200] E:Y, T:3,0
Bounds: java.awt.Rectangle[x=0,y=0,width=1920,height=1200]
ROI: java.awt.Rectangle[x=0,y=0,width=100,height=100]
Center: (50,50)

**** ROI reset to screen
Screen(0)[0,0 1920x1200] E:Y, T:3,0
Bounds: java.awt.Rectangle[x=0,y=0,width=1920,height=1200]
ROI: java.awt.Rectangle[x=0,y=0,width=1920,height=1200]
Center: (960,600)

if you want to use the returns of getBounds() and getROI() as regions, you have to cast them to a Region:
screenCenter = Region(getBounds).getCenter()
ALWAYS returns the center pixel of the screen, no matter what ROI is set.

--4. generally ok, but as an example might lead people the "wrong" way

- Is the timeout for an Exists controlled the same way as for a Find?
exists() is better compared to wait(), which is a find with the possibility for a specific timeout.

so using the standard:
wait(image) # waits 3 seconds
wait(image, 10) # waits 10 seconds
wait(image, 0) # only one search

exists(image) # waits 3 seconds
exists(image, 10) # waits 10 seconds
exists(image, 0) # only one search

to make decisions with wait, you have to generally ignore FindFailed exceptions (as you do) or wrap it into ugly try:except:
So always recommend, to use exists() in all cases, where you want to use if:else:, in all other cases use find() or wait().

--5. ok, see 3.

--6. ok

--7. ok

--8. CPU usage
Yes this is sometimes a problem.
Internally Sikuli searches max 3 times a second for something. With the average searches, you have about 0.5 to 1 second search time (most people do not restrict the search region at all or not enough. In the consequence Sikuli is searching all the time and it is plain CPU usage and the java process gets all it can get.
If it is a problem, you can play with the waitScanRate (e.g. only search every 1.5 seconds).
But the real optimizer is restricting the search region as much as possible.
My first search always is at least restricted to the app window. Then I use every chance to restrict further and try to click on positions relative to matches I already have.
My average search time per find operation is around 0.3 seconds and lower with some scripts.
Since I add some short wait()'s for the GUI reaction, I do not have any problems within CPU usage.

--9. the Settings class exists in Sikuli already. So what you can do is add additional attributes (variable/values), that you want to use globally. You could do this with every global persistent object (like e.g. SCREEN).
I already had solutions using observe(), where I added variables to the region, to communicate between main and handler.
To avoid name conflicts, I always precede these vars with my...

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.