Thursday 5 April 2012

Windows Themes - Determining the Windows Version

In order to make generic libraries, it is sometimes necessary to make decisions based on the current OS and Version under test. This is accomplished through the global Environment (Env) class. In the example below, the script loads one of two sets of Sikuli images depending on the OS and Version under test. The ..\WindowsXP\ and ..\Windows7\\ directories would contain Sikuli image (.PNG) files that have the same name, but whose image contents differ with the Windows Theme used on each OS.

"""Select a different set of images to use in the script depending on the OS/Version."""

if (Env.getOS() == OS.WINDOWS):
    # OS Version returns [ Major, ".", Minor ]
    OSVersionMajor = Env.getOSVersion()[0] 
    OSVersionMinor = Env.getOSVersion()[2] 
    if OSVersionMajor == "5":
        myImagePath = "c:\\Documents and Settings\\admin\\My Documents\\Sikuli\\images\\WindowsXP\\"
    elif OSVersionMajor == "6":
        myImagePath = "c:\\Documents and Settings\\admin\\My Documents\\Sikuli\\images\\Windows7\\"
    else:
        popup("Unsupported version of Windows. Exiting")  
        exit()    
    addImagePath(myImagePath)

Further Reading:
04-05-2012
Sikuli X-1.0rc3 (r905)