Best Python code snippet using fMBT_python
eyenfinger.py
Source:eyenfinger.py  
...272    # convert all non-ascii and bad chars to _273    try: s = unicode(s, "utf-8")274    except: pass275    return ''.join([(c, "_")[ord(c)>128 or c in "'\"\\`"] for c in s])276def _coordsToInt((x,y), (width, height)=(None, None)):277    """278    Convert percentages to screen coordinates279    """280    if (width == None or height == None):281        width, height = screenSize()282    if 0.0 <= x <= 1.0 and type(x) == float:283        x = int(round(x * width))284    else:285        x = int(x)286    if 0.0 <= y <= 1.0 and type(y) == float:287        y = int(round(y * height))288    else:289        y = int(y)290    return (x, y)291def setPreprocessFilter(preprocess):292    global _g_preprocess293    _g_preprocess = preprocess294def iSetDefaultClickDryRun(dryRun):295    """296    Set the default value for optional dryRun parameter for iClick*297    functions.298    """299    global _g_defaultClickDryRun300    _g_defaultClickDryRun = dryRun301def iSetDefaultDelayedDrawing(delayedDrawing):302    """303    Set the default for delaying drawing operations on captured304    screenshots.305    If delayedDrawing == False, drawing actions on screenshots (like306    highlighting icon and clicked coordinates) takes place during the307    function execution (like iClickIcon).308    If delayedDrawing == True, the screenshot is saved without309    highlighted areas, and <screenshot filename>.delayeddraw file310    contains all draw commands that can be executed after the test311    run. This may save a lot test execution time and CPU on the device312    that runs eyenfinger.313    The default is False.314    """315    global _g_defaultDelayedDrawing316    _g_defaultDelayedDrawing = delayedDrawing317def iSetDefaultIconMatch(match):318    """319    Set the default icon matching value, ranging from 0 to 1. The320    value will be used in iClickIcon and iVerifyIcon, if the optional321    match parameter is omitted. Value 1.0 will use pixel-perfect322    matching (the default), values below 1.0 will use fuzzy matching.323    Fuzzy matching is EXPERIMENTAL.324    """325    global _g_defaultIconMatch326    _g_defaultIconMatch = match327def iSetDefaultIconColorMatch(colorMatch):328    """329    Set the default color matching value, ranging from 0 to 1. When330    using pixel-perfect matching this will allow given error in pixel331    colors.332    For instance, when comparing 24 bit RGB images, value 0.97 will333    allow 256 - int(256 * .97) = 8 difference on each color channel.334    """335    global _g_defaultIconColorMatch336    _g_defaultIconColorMatch = colorMatch337def iSetDefaultIconOpacityLimit(opacityLimit):338    """339    Set the default minimum opacity for pixels to be matched. Defaults340    to 0.0, all pixels are matched independently of their opacity.341    """342    global _g_defaultIconOpacityLimit343    _g_defaultIconOpacityLimit = opacityLimit344def iSetDefaultInputKeyDevice(deviceName):345    """346    Use deviceName as a default input device for iInputKey.347    iSetDefaultInputKeyDevice("/dev/input/event0")348    iInputKey(["enter"])349    """350    global _g_defaultInputKeyDevice351    _g_defaultInputKeyDevice = deviceName352def iSetDefaultReadWithOCR(ocr):353    """354    Set the default for using OCR when reading images or windows.355    """356    global _g_defaultReadWithOCR357    _g_defaultReadWithOCR = ocr358def screenSize():359    """360    Returns the size of the screen as a pair (width, height).361    """362    if _g_screenSize == (0, 0):363        _getScreenSize()364    return _g_screenSize365def windowSize():366    """367    Returns the size of the window as a pair (width, height).368    Choose a window first, for instance with iRead() or iUseWindow().369    """370    if _g_lastWindow == None:371        raise BadWindowName("undefined window")372    return _g_windowSizes[_g_lastWindow]373def windowXY():374    """375    Returns screen coordinates of the top-left corner of the window as376    a pair (x, y).377    Choose a window first, for instance with iRead() or iUseWindow().378    """379    if _g_lastWindow == None:380        raise BadWindowName("undefined window")381    return _g_windowOffsets[_g_lastWindow]382def imageSize(imageFilename):383    """384    Returns image size as pair (width, height).385    """386    struct_bbox = Bbox(0,0,0,0,0)387    err = eye4graphics.imageDimensions(ctypes.byref(struct_bbox),388                                       imageFilename)389    if err != 0:390        return None, None391    return struct_bbox.right, struct_bbox.bottom392def iRead(windowId = None, source = None, preprocess = None, ocr=None, capture=None, ocrArea=(0, 0, 1.0, 1.0), ocrPageSegModes=(3,)):393    """394    DEPRECATED - use fmbtx11.Screen.refreshScreenshot instead.395    Read the contents of the given window or other source. If neither396    of windowId or source is given, reads the contents of active397    window. iClickWord and iVerifyWord can be used after reading with398    OCR.399    Parameters:400        windowId     id (0x....) or the title of the window to be read.401                     Defaults to None.402        source       name of the file to be read, for instance a screen403                     capture. Defaults to None.404        preprocess   preprocess specification to override the default405                     that is set using setPreprocessFilter. Defaults406                     to None. Set to "" to disable preprocessing before407                     OCR.408        ocr          words will be read using OCR if True409                     (the default). Read object can be used with410                     iClickIcon and iVerifyIcon without OCR, too.411        capture      save image with read words highlighted to this412                     file. Default: None (nothing is saved).413        ocrArea      (top, left, right, bottom) coordinates -414                     area of the image to be read with OCR.415        ocrPageSegModes416                     tuple of integers, see tesseract -pagesegmodes417    Returns list of words detected by OCR from the read object.418    """419    global _g_hocr420    global _g_lastWindow421    global _g_words422    global _g_readImage423    global _g_origImage424    _g_words = None425    _g_readImage = None426    _g_origImage = None427    if ocr == None:428        ocr = _g_defaultReadWithOCR429    if not source:430        iUseWindow(windowId)431        # take a screenshot432        _runcmd("xwd -root -screen -out %s.xwd && convert %s.xwd -crop %sx%s+%s+%s +repage '%s'" %433               (SCREENSHOT_FILENAME, SCREENSHOT_FILENAME,434                _g_windowSizes[_g_lastWindow][0], _g_windowSizes[_g_lastWindow][1],435                _g_windowOffsets[_g_lastWindow][0], _g_windowOffsets[_g_lastWindow][1],436                SCREENSHOT_FILENAME))437        source = SCREENSHOT_FILENAME438    else:439        iUseImageAsWindow(source)440    _g_origImage = source441    orig_width, orig_height = _g_windowSizes[_g_lastWindow][0], _g_windowSizes[_g_lastWindow][1]442    x1, y1 = _coordsToInt(ocrArea[:2], (orig_width, orig_height))443    x2, y2 = _coordsToInt(ocrArea[2:], (orig_width, orig_height))444    if x2 <= x1 or y2 <= y1:445        raise EyenfingerError("Invalid area size: %s => %s" % (ocrArea, (x1, y1, x2, y2)))446    if orig_width <= 0 or orig_height <= 0:447        raise EyenfingerError("Invalid image size: %sx%s" % (orig_width, orig_height))448    if not ocr:449        if capture:450            drawWords(_g_origImage, capture, [], [])451        return []452    if preprocess == None:453        preprocess = _g_preprocess454    # convert to text455    _g_readImage = _g_origImage + "-pp.png"456    if ocrArea == (0, 0, 1.0, 1.0):457        croparea = ""458        wordXOffset = 0459        wordYOffset = 0460    else:461        croparea = "-crop %sx%s+%s+%s +repage" % (x2-x1, y2-y1, x1, y1)462        wordXOffset = x1463        wordYOffset = y1464        # rescale possible resize preprocessing parameter465        resize_m = re.search('-resize ([0-9]+)x([0-9]*)', preprocess)466        if resize_m:467            origXResize = int(resize_m.group(1))468            newXResize = int(origXResize/float(orig_width) * (x2-x1))469            preprocess = (preprocess[:resize_m.start()] +470                          ("-resize %sx" % (newXResize,)) +471                          preprocess[resize_m.end():])472    _g_words = {}473    for psm in ocrPageSegModes:474        cmd = "convert %s %s %s %s && tesseract %s %s -l eng -psm %s hocr" % (475                _g_origImage, croparea, preprocess, _g_readImage,476                _g_readImage, SCREENSHOT_FILENAME, psm)477        _, _g_hocr = _runcmd(cmd)478        hocr_filename = SCREENSHOT_FILENAME + ".html"479        if not os.access(hocr_filename, os.R_OK):480            raise NoOCRResults("HOCR output missing. Tesseract OCR 3.02 or greater required.")481        # store every word and its coordinates482        _g_words.update(_hocr2words(file(hocr_filename).read()))483    # convert word coordinates to the unscaled pixmap484    try:485        ocr_page_line = [line for line in file(hocr_filename).readlines() if "class='ocr_page'" in line][0]486    except IndexError:487        raise NoOCRResults("Could not read ocr_page class information from %s" % (hocr_filename,))488    scaled_width, scaled_height = re.findall('bbox 0 0 ([0-9]+)\s*([0-9]+)', ocr_page_line)[0]489    scaled_width, scaled_height = float(scaled_width) / (float(x2-x1)/orig_width), float(scaled_height) / (float(y2-y1)/orig_height)490    for word in sorted(_g_words.keys()):491        for appearance, (wordid, middle, bbox) in enumerate(_g_words[word]):492            _g_words[word][appearance] = \493                (wordid,494                 (int(middle[0]/scaled_width * orig_width) + wordXOffset,495                  int(middle[1]/scaled_height * orig_height) + wordYOffset),496                 (int(bbox[0]/scaled_width * orig_width) + wordXOffset,497                  int(bbox[1]/scaled_height * orig_height) + wordYOffset,498                  int(bbox[2]/scaled_width * orig_width) + wordXOffset,499                  int(bbox[3]/scaled_height * orig_height) + wordYOffset))500            _log('found "' + word + '": (' + str(bbox[0]) + ', ' + str(bbox[1]) + ')')501    if capture:502        drawWords(_g_origImage, capture, _g_words, _g_words)503    return sorted(_g_words.keys())504def iVerifyWord(word, match=0.33, appearance=1, capture=None):505    """506    DEPRECATED - use fmbtx11.Screen.verifyOcrText instead.507    Verify that word can be found from previously iRead() image.508    Parameters:509        word         word that should be checked510        appearance   if word appears many times, appearance to511                     be clicked. Defaults to the first one.512        match        minimum matching score513        capture      save image with verified word highlighted514                     to this file. Default: None (nothing is saved).515    Returns pair: ((score, matchingWord), (left, top, right, bottom)), where516        score        score of found match (1.0 for perfect match)517        matchingWord corresponding word detected by OCR518        (left, top, right, bottom)519                     bounding box of the word in read image520    Throws BadMatch error if word is not found.521    Throws NoOCRResults error if there are OCR results available522    on the current screen.523    """524    if _g_words == None:525        raise NoOCRResults('iRead has not been called with ocr=True')526    score, matching_word = findWord(word)527    if capture:528        drawWords(_g_origImage, capture, [word], _g_words)529    if score < match:530        raise BadMatch('No matching word for "%s". The best candidate "%s" with score %.2f, required %.2f' %531                            (word, matching_word, score, match))532    return ((score, matching_word), _g_words[matching_word][appearance-1][2])533def iVerifyText(text, match=0.33, capture=None):534    """535    DEPRECATED - use fmbtx11.Screen.verifyOcrText instead.536    Verify that text can be found from previously iRead() image.537    Parameters:538        text         multiple words that should be checked539        match        minimum matching score540        capture      save image with verified text highlighted541                     to this file. Default: None (nothing is saved).542    Returns pair:543        ((score, matchingText), (left, top, right, bottom)), where544        score        score of found match (1.0 for perfect match)545        matchingText corresponding text detected by OCR546        (left, top, right, bottom)547                     bounding box of the text in read image548    Throws BadMatch error if text is not found.549    Throws NoOCRResults error if there are OCR results available550    on the current screen.551    """552    if _g_words == None:553        raise NoOCRResults('iRead has not been called with ocr=True')554    score_text_bbox_list = findText(text, match)555    if len(score_text_bbox_list) == 0:556        raise BadMatch('No match >= %s for text "%s"' % (score, text))557    score, text, bbox = score_text_box_list[0]558    if capture:559        drawBbox(_g_origImage, capture, bbox, "%.2f %s" % (score, text))560    return ((score, matching_text), bbox)561def iVerifyIcon(iconFilename, match=None, colorMatch=None, opacityLimit=None, capture=None, area=(0.0, 0.0, 1.0, 1.0), _origin="iVerifyIcon"):562    """563    DEPRECATED - use fmbtx11.Screen.verifyBitmap instead.564    Verify that icon can be found from previously iRead() image.565    Parameters:566        iconFilename   name of the icon file to be searched for567        match          minimum matching score between 0 and 1.0,568                       1.0 is perfect match (default)569        colorMatch     1.0 (default) requires exact color match. Value570                       below 1.0 defines maximum allowed color571                       difference. See iSetDefaultIconColorMatch.572        opacityLimit   0.0 (default) requires exact color values573                       independently of opacity. If lower than 1.0,574                       pixel less opaque than given value are skipped575                       in pixel perfect comparisons.576        capture        save image with verified icon highlighted577                       to this file. Default: None (nothing is saved).578        area           rectangle (left, top, right, bottom). Search579                       icon inside this rectangle only. Values can be580                       absolute coordinates, or floats in range [0.0,581                       1.0] that will be scaled to image dimensions.582                       The default is (0.0, 0.0, 1.0, 1.0), that is583                       full rectangle.584    Returns pair: (score, (left, top, right, bottom)), where585        score          score of found match (1.0 for perfect match)586        (left, top, right, bottom)587                       bounding box of found icon588    Throws BadMatch error if icon is not found.589    """590    if not eye4graphics:591        _log('ERROR: %s("%s") called, but eye4graphics not loaded.' % (_origin, iconFilename))592        raise EyenfingerError("eye4graphics not available")593    if not _g_origImage:594        _log('ERROR %s("%s") called, but source not defined (iRead not called).' % (_origin, iconFilename))595        raise BadSourceImage("Source image not defined, cannot search for an icon.")596    if not (os.path.isfile(iconFilename) and os.access(iconFilename, os.R_OK)):597        _log('ERROR %s("%s") called, but the icon file is not readable.' % (_origin, iconFilename))598        raise BadIconImage('Icon "%s" is not readable.' % (iconFilename,))599    if match == None:600        match = _g_defaultIconMatch601    if match > 1.0:602        _log('ERROR %s("%s"): invalid match value, must be below 1.0. ' % (_origin, iconFilename,))603        raise ValueError("invalid match value: %s, should be 0 <= match <= 1.0" % (match,))604    if colorMatch == None:605        colorMatch = _g_defaultIconColorMatch606    if not 0.0 <= colorMatch <= 1.0:607        _log('ERROR %s("%s"): invalid colorMatch value, must be between 0 and 1. ' % (_origin, iconFilename,))608        raise ValueError("invalid colorMatch value: %s, should be 0 <= colorMatch <= 1.0" % (colorMatch,))609    if opacityLimit == None:610        opacityLimit = _g_defaultIconOpacityLimit611    if not 0.0 <= opacityLimit <= 1.0:612        _log('ERROR %s("%s"): invalid opacityLimit value, must be between 0 and 1. ' % (_origin, iconFilename,))613        raise ValueError("invalid opacityLimit value: %s, should be 0 <= opacityLimit <= 1.0" % (opacityLimit,))614    if area[0] > area[2] or area[1] >= area[3]:615        raise ValueError("invalid area: %s, should be rectangle (left, top, right, bottom)" % (area,))616    leftTopRightBottomZero = (_coordsToInt((area[0], area[1]), windowSize()) +617                               _coordsToInt((area[2], area[3]), windowSize()) +618                               (0,))619    struct_area_bbox = Bbox(*leftTopRightBottomZero)620    struct_bbox = Bbox(0,0,0,0,0)621    threshold = int((1.0-match)*20)622    err = eye4graphics.findSingleIcon(ctypes.byref(struct_bbox),623                                      _g_origImage, iconFilename, threshold,624                                      ctypes.c_double(colorMatch),625                                      ctypes.c_double(opacityLimit),626                                      ctypes.byref(struct_area_bbox))627    bbox = (int(struct_bbox.left), int(struct_bbox.top),628            int(struct_bbox.right), int(struct_bbox.bottom))629    if err == -1 or err == -2:630        msg = '%s: "%s" not found, match=%.2f, threshold=%s, closest threshold %s.' % (631            _origin, iconFilename, match, threshold, int(struct_bbox.error))632        if capture:633            drawIcon(_g_origImage, capture, iconFilename, bbox, 'red')634        _log(msg)635        raise BadMatch(msg)636    elif err != 0:637        _log("%s: findSingleIcon returned %s" % (_origin, err,))638        raise BadMatch("%s not found, findSingleIcon returned %s." % (iconFilename, err))639    if threshold > 0:640        score = (threshold - int(struct_bbox.error)) / float(threshold)641    else:642        score = 1.0643    if capture:644        drawIcon(_g_origImage, capture, iconFilename, bbox, area=leftTopRightBottomZero[:4])645    return (score, bbox)646def iClickIcon(iconFilename, clickPos=(0.5,0.5), match=None,647               colorMatch=None, opacityLimit=None,648               mouseButton=1, mouseEvent=MOUSEEVENT_CLICK, dryRun=None, capture=None):649    """650    DEPRECATED - use fmbtx11.Screen.tapBitmap instead.651    Click coordinates relative to the given icon in previously iRead() image.652    Parameters:653        iconFilename read icon from this file654        clickPos     position to be clicked,655                     relative to word top-left corner of the bounding656                     box around the word. X and Y units are relative657                     to width and height of the box.  (0,0) is the658                     top-left corner, (1,1) is bottom-right corner,659                     (0.5, 0.5) is the middle point (default).660                     Values below 0 or greater than 1 click outside661                     the bounding box.662        match        1.0 (default) requires exact match. Value below 1.0663                     defines minimum required score for fuzzy matching664                     (EXPERIMENTAL). See iSetDefaultIconMatch.665        colorMatch   1.0 (default) requires exact color match. Value666                     below 1.0 defines maximum allowed color667                     difference. See iSetDefaultIconColorMatch.668        opacityLimit 0.0 (default) requires exact color values669                     independently of opacity. If lower than 1.0,670                     pixel less opaque than given value are skipped671                     in pixel perfect comparisons.672        mouseButton  mouse button to be synthesized on the event, default is 1.673        mouseEvent   event to be synthesized, the default is MOUSEEVENT_CLICK,674                     others: MOUSEEVENT_MOVE, MOUSEEVENT_DOWN, MOUSEEVENT_UP.675        dryRun       if True, does not synthesize events. Still returns676                     coordinates of the clicked position and illustrates677                     the clicked position on the capture image if678                     given.679        capture      name of file where image of highlighted icon and680                     clicked point are saved.681    Returns pair (score, (clickedX, clickedY)), where682        score        score of found match (1.0 for perfect match)683        (clickedX, clickedY)684                     X and Y coordinates of clicked position on the685                     screen.686    Throws BadMatch error if could not find a matching word.687    """688    _DEPRECATED()689    score, bbox = iVerifyIcon(iconFilename, match=match,690                              colorMatch=colorMatch, opacityLimit=opacityLimit,691                              capture=capture, _origin="iClickIcon")692    clickedXY = iClickBox(bbox, clickPos, mouseButton, mouseEvent, dryRun,693                          capture, _captureText = iconFilename)694    return (score, clickedXY)695def iClickWord(word, appearance=1, clickPos=(0.5,0.5), match=0.33,696               mouseButton=1, mouseEvent=1, dryRun=None, capture=None):697    """698    DEPRECATED - use fmbtx11.Screen.tapOcrText instead.699    Click coordinates relative to the given word in previously iRead() image.700    Parameters:701        word         word that should be clicked702        appearance   if word appears many times, appearance to703                     be clicked. Defaults to the first one.704        clickPos     position to be clicked,705                     relative to word top-left corner of the bounding706                     box around the word. X and Y units are relative707                     to width and height of the box.  (0,0) is the708                     top-left corner, (1,1) is bottom-right corner,709                     (0.5, 0.5) is the middle point (default).710                     Values below 0 or greater than 1 click outside711                     the bounding box.712        capture      name of file where image of highlighted word and713                     clicked point are saved.714    Returns pair: ((score, matchingWord), (clickedX, clickedY)), where715        score        score of found match (1.0 for perfect match)716        matchingWord corresponding word detected by OCR717        (clickedX, clickedY)718                     X and Y coordinates of clicked position on the719                     screen.720    Throws BadMatch error if could not find a matching word.721    Throws NoOCRResults error if there are OCR results available722    on the current screen.723    """724    _DEPRECATED()725    (score, matching_word), bbox = iVerifyWord(word, appearance=appearance, match=match, capture=False)726    clickedX, clickedY = iClickBox(bbox, clickPos, mouseButton, mouseEvent, dryRun, capture=False)727    windowId = _g_lastWindow728    _log('iClickWord("%s"): word "%s", match %.2f, bbox %s, window offset %s, click %s' %729         (word, matching_word, score,730          bbox, _g_windowOffsets[windowId],731          (clickedX, clickedY)))732    if capture:733        drawWords(_g_origImage, capture, [word], _g_words)734        drawClickedPoint(capture, capture, (clickedX, clickedY))735    return ((score, matching_word), (clickedX, clickedY))736def iClickBox((left, top, right, bottom), clickPos=(0.5, 0.5),737              mouseButton=1, mouseEvent=1, dryRun=None,738              capture=None, _captureText=None):739    """740    DEPRECATED - use fmbtx11.Screen.tapItem instead.741    Click coordinates relative to the given bounding box, default is742    in the middle of the box.743    Parameters:744        (left, top, right, bottom)745                     coordinates of the box inside the window.746                     (0, 0) is the top-left corner of the window.747        clickPos     (offsetX, offsetY) position to be clicked,748                     relative to the given box. (0, 0) is the749                     top-left, and (1.0, 1.0) is the lower-right750                     corner of the box.  The default is (0.5, 0.5),751                     that is, the middle point of the box. Values752                     smaller than 0 and bigger than 1 are allowed,753                     too.754        mouseButton  mouse button to be synthesized on the event, default is 1.755        mouseEvent   event to be synthesized, the default is MOUSEEVENT_CLICK,756                     others: MOUSEEVENT_MOVE, MOUSEEVENT_DOWN, MOUSEEVENT_UP.757        dryRun       if True, does not synthesize events. Still returns758                     coordinates of the clicked position and illustrates759                     the clicked position on the capture image if760                     given.761        capture      name of file where the last screenshot with762                     clicked point highlighted is saved. The default763                     is None (nothing is saved).764    Returns pair (clickedX, clickedY)765                     X and Y coordinates of clicked position on the766                     screen.767    """768    clickWinX = int(left + clickPos[0]*(right-left))769    clickWinY = int(top + clickPos[1]*(bottom-top))770    (clickedX, clickedY) = iClickWindow((clickWinX, clickWinY),771                                        mouseButton, mouseEvent,772                                        dryRun, capture=False)773    if capture:774        if _captureText == None:775            _captureText = "Box: %s, %s, %s, %s" % (left, top, right, bottom)776        drawIcon(_g_origImage, capture, _captureText, (left, top, right, bottom))777        drawClickedPoint(capture, capture, (clickedX, clickedY))778    return (clickedX, clickedY)779def iClickWindow((clickX, clickY), mouseButton=1, mouseEvent=1, dryRun=None, capture=None):780    """781    DEPRECATED - use fmbtx11.Screen.tap instead.782    Click given coordinates in the window.783    Parameters:784        (clickX, clickY)785                     coordinates to be clicked inside the window.786                     (0, 0) is the top-left corner of the window.787                     Integer values are window coordinates. Floating788                     point values from 0.0 to 1.0 are scaled to window789                     coordinates: (0.5, 0.5) is the middle of the790                     window, and (1.0, 1.0) the bottom-right corner of791                     the window.792        mouseButton  mouse button to be synthesized on the event, default is 1.793        mouseEvent   event to be synthesized, the default is MOUSEEVENT_CLICK,794                     others: MOUSEEVENT_MOVE, MOUSEEVENT_DOWN, MOUSEEVENT_UP.795        dryRun       if True, does not synthesize events. Still796                     illustrates the clicked position on the capture797                     image if given.798        capture      name of file where the last screenshot with799                     clicked point highlighted is saved. The default800                     is None (nothing is saved).801    Returns pair (clickedX, clickedY)802                     X and Y coordinates of clicked position on the803                     screen.804    """805    # Get the size of the window806    wndSize = windowSize()807    (clickX, clickY) = _coordsToInt((clickX, clickY), wndSize)808    # Get the position of the window809    wndPos = windowXY()810    # If coordinates are given as percentages, convert to window coordinates811    clickScrX = clickX + wndPos[0]812    clickScrY = clickY + wndPos[1]813    iClickScreen((clickScrX, clickScrY), mouseButton, mouseEvent, dryRun, capture)814    return (clickScrX, clickScrY)815def iClickScreen((clickX, clickY), mouseButton=1, mouseEvent=1, dryRun=None, capture=None):816    """817    DEPRECATED - use fmbtx11.Screen.tap instead.818    Click given absolute coordinates on the screen.819    Parameters:820        (clickX, clickY)821                     coordinates to be clicked on the screen. (0, 0)822                     is the top-left corner of the screen. Integer823                     values are screen coordinates. Floating point824                     values from 0.0 to 1.0 are scaled to screen825                     coordinates: (0.5, 0.5) is the middle of the826                     screen, and (1.0, 1.0) the bottom-right corner of827                     the screen.828        mouseButton  mouse button to be synthesized on the event, default is 1.829        mouseEvent   event to be synthesized, the default is MOUSEEVENT_CLICK,830                     others: MOUSEEVENT_MOVE, MOUSEEVENT_DOWN, MOUSEEVENT_UP.831        dryRun       if True, does not synthesize events. Still832                     illustrates the clicked position on the capture833                     image if given.834        capture      name of file where the last screenshot with835                     clicked point highlighted is saved. The default836                     is None (nothing is saved).837    """838    _DEPRECATED()839    if mouseEvent == MOUSEEVENT_CLICK:840        params = "'mouseclick %s'" % (mouseButton,)841    elif mouseEvent == MOUSEEVENT_DOWN:842        params = "'mousedown %s'" % (mouseButton,)843    elif mouseEvent == MOUSEEVENT_UP:844        params = "'mouseup %s'" % (mouseButton,)845    else:846        params = ""847    clickX, clickY = _coordsToInt((clickX, clickY))848    if capture:849        drawClickedPoint(_g_origImage, capture, (clickX, clickY))850    if dryRun == None:851        dryRun = _g_defaultClickDryRun852    if not dryRun:853        # use xte from the xautomation package854        _runcmd("xte 'mousemove %s %s' %s" % (clickX, clickY, params))855def iGestureScreen(listOfCoordinates, duration=0.5, holdBeforeGesture=0.0, holdAfterGesture=0.0, intermediatePoints=0, capture=None, dryRun=None):856    """857    DEPRECATED - use fmbtx11.Screen.drag instead.858    Synthesizes a gesture on the screen.859    Parameters:860        listOfCoordinates861                     The coordinates through which the cursor moves.862                     Integer values are screen coordinates. Floating863                     point values from 0.0 to 1.0 are scaled to screen864                     coordinates: (0.5, 0.5) is the middle of the865                     screen, and (1.0, 1.0) the bottom-right corner of866                     the screen.867        duration     gesture time in seconds, excluding868                     holdBeforeGesture and holdAfterGesture times.869        holdBeforeGesture870                     time in seconds to keep mouse down before the871                     gesture.872        holdAfterGesture873                     time in seconds to keep mouse down after the874                     gesture.875        intermediatePoints876                     the number of intermediate points to be added877                     between each of the coordinates. Intermediate878                     points are added to straight lines between start879                     and end points.880        capture      name of file where the last screenshot with881                     the points through which the cursors passes is882                     saved. The default is None (nothing is saved).883        dryRun       if True, does not synthesize events. Still884                     illustrates the coordinates through which the cursor885                     goes.886    """887    _DEPRECATED()888    # The params list to be fed to xte889    params = []890    # The list of coordinates through which the cursor has to go891    goThroughCoordinates = []892    for pos in xrange(len(listOfCoordinates)):893        x, y = _coordsToInt(listOfCoordinates[pos])894        goThroughCoordinates.append((x,y))895        if pos == len(listOfCoordinates) - 1:896            break # last coordinate added897        nextX, nextY = _coordsToInt(listOfCoordinates[pos+1])898        (x,y), (nextX, nextY) = (x, y), (nextX, nextY)899        for ip in range(intermediatePoints):900            goThroughCoordinates.append(901                (int(round(x + (nextX-x)*(ip+1)/float(intermediatePoints+1))),902                 int(round(y + (nextY-y)*(ip+1)/float(intermediatePoints+1)))))903    # Calculate the time (in micro seconds) to sleep between moves.904    if len(goThroughCoordinates) > 1:905        moveDelay = 1000000 * float(duration) / (len(goThroughCoordinates)-1)906    else:907        moveDelay = 0908    if not dryRun:909        # Build the params list.910        params.append("'mousemove %d %d'" % goThroughCoordinates[0])911        params.append("'mousedown 1 '")912        if holdBeforeGesture > 0:913            params.append("'usleep %d'" % (holdBeforeGesture * 1000000,))914        for i in xrange(1, len(goThroughCoordinates)):915            params.append("'usleep %d'" % (moveDelay,))916            params.append("'mousemove %d %d'" % goThroughCoordinates[i])917        if holdAfterGesture > 0:918            params.append("'usleep %d'" % (holdAfterGesture * 1000000,))919        params.append("'mouseup 1'")920        # Perform the gesture921        _runcmd("xte %s" % (" ".join(params),))922    if capture:923        intCoordinates = [ _coordsToInt(point) for point in listOfCoordinates ]924        drawLines(_g_origImage, capture, intCoordinates, goThroughCoordinates)925    return goThroughCoordinates926def iGestureWindow(listOfCoordinates, duration=0.5, holdBeforeGesture=0.0, holdAfterGesture=0.0, intermediatePoints=0, capture=None, dryRun=None):927    """928    DEPRECATED - use fmbtx11.Screen.drag instead.929    Synthesizes a gesture on the window.930    Parameters:931        listOfCoordinates932                     The coordinates through which the cursor moves.933                     Integer values are window coordinates. Floating934                     point values from 0.0 to 1.0 are scaled to window935                     coordinates: (0.5, 0.5) is the middle of the936                     window, and (1.0, 1.0) the bottom-right corner of937                     the window.938        duration     gesture time in seconds, excluding939                     holdBeforeGesture and holdAfterGesture times.940        holdBeforeGesture941                     time in seconds to keep mouse down before the942                     gesture.943        holdAfterGesture944                     time in seconds to keep mouse down after the945                     gesture.946        intermediatePoints947                     the number of intermediate points to be added948                     between each of the coordinates. Intermediate949                     points are added to straight lines between start950                     and end points.951        capture      name of file where the last screenshot with952                     the points through which the cursors passes is953                     saved. The default is None (nothing is saved).954        dryRun       if True, does not synthesize events. Still955                     illustrates the coordinates through which the cursor956                     goes.957    """958    screenCoordinates = [ _windowToScreen(*_coordsToInt((x,y),windowSize())) for (x,y) in listOfCoordinates ]959    return iGestureScreen(screenCoordinates, duration, holdBeforeGesture, holdAfterGesture, intermediatePoints, capture, dryRun)960def iType(word, delay=0.0):961    """962    DEPRECATED - use fmbtx11.Screen.type instead.963    Send keypress events.964    Parameters:965        word is either966            - a string containing letters and numbers.967              Each letter/number is using press and release events.968            - a list that contains969              - keys: each key is sent using press and release events.970              - (key, event)-pairs: the event (either "press" or "release")971                is sent.972              - (key1, key2, ..., keyn)-tuples. 2n events is sent:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
