← 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

    Status: Open => Answered

RaiMan proposed the following answer:
---1. Thanx
... for that really interesting example.
The documentation and presentation of your work is outstanding.

---2. Installation of Sikuli and Java 6

on Windows 32-Bit systems, the program folder (standard installation folder) is:
C:\Program Files\

on Windows 64-Bit systems, there are 2 folders:
C:\Program Files\     for 32-Bit software
C:\Program Files (x86)\    for 64-bit software

In your ReadMe file this is not clear, since you mix up these folders:
These programs will install to c:\Program Files\Sikuli and c:\Program Files (x86)\Java respectively. 

---3. Sikuli bug 729260
This is not a bug, it was the user's misunderstanding of what constant references to objects mean in Python.

The SCREEN variable is a constant reference to Screen(0) (the primary
screen). Since the monitor preferences are only evaluated at script
start, using SCREEN instead of Screen(0) only avoids additional screen
objects.

#fix for Sikuli bug #729260
xScreen = SCREEN.x
yScreen = SCREEN.y
wScreen = SCREEN.w
hScreen = SCREEN.h
regionScreen = (xScreen,yScreen,wScreen,hScreen)
hoverPoint = getCenter()

This block currently does not really make sense, since regionScreen is
not used anywhere in your script and the zScreen are the same as
SCREEN.z and do never change while the script runs.

Since you use setROI() to restrict the search region in your hot key
handlers, the searches are always done on Screen(0) (SCREEN).

A more flexible solution would be to define the main areas
(ControlBarRegion, NextEpisodeRegion) once in you script as global
variables and then use region.method()

e.g. in toggleNetFlixFullScreen
ControlBarRegion.click("fullscreen.png")

This would allow, to add multi monitor support easily to the script.

Naming hoverPoint as screenCenter would make things clearer, when
reading the code.

---4. Handling FindFailed exceptions
It might be, that you have foreseen every eventual odd situation (I cannot judge), but if you did not, it is very hard to find reasons for the script's odd behavior because of "image not found" situations.

You switched of the FindFailed handling globally:
setFindFailedResponse(SKIP)

This might be, because you want to use the return value of find() in
your workflow decisions.

The recommendation is, to use exists() for situations, where you have to
decide how to proceed and let FindFails happen, where you did not expect
them.

example:
# from netFlixLaunch

    netFlixLoading = wait("netflixlogo.png",8)
    if netFlixLoading:

better:
    if exists("netflixlogo.png",8):

It does the same, but you can leave FindFailed exceptions to be raised.

There are more examples throughout the script.

---5: repetitive usage of setROI()
When using setROI(), the ROI for the object SCREEN is set to the given region and it is maintained until it is set to another region or reset to the whole screen.

So if you call setControlBarRegion at the beginning of a workflow, it is
not needed again, if you are targeting the same ROI.

e.g. in netFlixLaunch
the lines 21 and 29 are not necessary

But as already mentioned above: I would prefer to use region.method()
instead of setRoi(); method()

---6: type("O", KeyModifier.ALT+KeyModifier.SHIFT+KeyModifier.CTRL)
You trigger a hot key inside your script, to run the handler.
-1. if the user would change the hot key, he would have to go into your code, to adapt this.
-2. you do not need that, just use: netFlixLaunch(None) to run your Netflix startup stuff inline

---7: using, what is already found

e.g. in goNextEpisode

    nextEpisodeControl = find("nextepisode.png")
    if nextEpisodeControl:
        setNextEpisodeRegion()
        click("nextepisode.png")

better:

    if exists("nextepisode.png"):
        click(getLastMatch())

More examples in the script

---8: setAutoWaitTimeout(.1)
... does not make sense.
A GUI does not behave the same in the time or on different machines. The default of 3 seconds is a good standard value for the average situation. There are many people out there, who set the AutoWaitTimeout to a high value (e.g. 60 seconds), to be on the safe side for most situations. This does not harm, since Sikuli's standard maximum is 3 search trials per second, and the search is finished, when the visual object is found.
So setting the value to .1, restricts every search to one trial, which might not be enough on other machines. And it does not speed things up, it only increases the risk off odd behavior, especially in the combination with setFindFailedResponse(SKIP).

The only situation where one might want to restrict to one search trial:
You know, that something MUST be there and you want to do something, if it is not.
For these cases we have:
if exists(some_image, 0): # only one search
    print "it is as expected"
else:
    print "uuuups, what's the matter"

---9:
global subtitleToggleFlag

To avoid this Python specific situation, you might use the Settings
class, to store your own settings:

Settings.mySubtitleToggleFlag = 1

        if Settings.mySubtitleToggleFlag==1:

BTW: if a setting only has 2 values, it is better to use the boolean True/False:
Settings.mySubtitleToggleFlag = False
        if not Settings.mySubtitleToggleFlag:

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